當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ramda.pick函數代碼示例

本文整理匯總了TypeScript中ramda.pick函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript pick函數的具體用法?TypeScript pick怎麽用?TypeScript pick使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了pick函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

    describe('ramda', function () {

        function filterUserData(username) {
            return R.filter(R.propEq('username', username));
        }

        const isUnComplete = (task) => !task.complete;
        const filterOutstandingTasks = R.pipe(
            R.filter(isUnComplete),
            R.map(R.pick(['id', 'title', 'dueDate', 'priority'])));

        function descSort(property) {
            return (a, b) => a[property].localeCompare(b[property]);
        }

        function getIncompleteTaskSummaries(username) {
            return R.pipeP(fetchTaskData, R.prop('tasks'), filterUserData(username), filterOutstandingTasks, R.sort(descSort('dueDate')));
        }

        it('returns unfinished tasks sorted by due dates in ascending order', function (done) {
            getIncompleteTaskSummaries('Scott')()
                .then((answer) => done(assert.deepEqual(answer, expectedAnswer)))
                .catch((error) => done(error));
        });
    });
開發者ID:dhassaine-scottlogic,項目名稱:fp_experiments,代碼行數:25,代碼來源:ts_ramda.test.ts

示例2: checkOneBrowser

function checkOneBrowser(browser: Browser) {
  const platform = os.platform()
  const pickBrowserProps = pick([
    'name',
    'displayName',
    'type',
    'version',
    'path'
  ])

  const logBrowser = (props: any) => {
    log('setting major version for %j', props)
  }

  const failed = (err: NotInstalledError) => {
    if (err.notInstalled) {
      log('browser %s not installed', browser.name)
      return false
    }
    throw err
  }

  log('checking one browser %s', browser.name)
  return lookup(platform, browser)
    .then(merge(browser))
    .then(pickBrowserProps)
    .then(tap(logBrowser))
    .then(setMajorVersion)
    .catch(failed)
}
開發者ID:lgandecki,項目名稱:cypress,代碼行數:30,代碼來源:detect.ts

示例3: merge

 const set = data => {
   for (let x = 0; x < data.width; x++) {
     for (let y = 0; y < data.height; y++) {
       // cant read from MST array above bounds, so check length first
       // @ts-ignore
       self.field[x] = x === self.field.length ? [] : self.field[x]
       self.field[x][y] = y === self.field[x].length ? {} : self.field[x][y]
       // merge to preserve flags on UI
       self.field[x][y] = merge(self.field[x][y], data.field[x][y])
     }
   }
   Object.assign(
     self,
     pick(
       [
         'width',
         'height',
         'bombCount',
         'cellsLeft',
         'isFinished',
         'isWon',
         'isLost'
       ],
       data
     )
   )
 }
開發者ID:NotBadDevs,項目名稱:minesweepers,代碼行數:27,代碼來源:game.ts

示例4: buildJoiSpec

 .map(handler => [
     {
         method,
         path,
         handler,
         validate: buildJoiSpec(Joi, spec),
         meta: pick(['summary', 'description'], spec)
     }
 ])
開發者ID:benjambles,項目名稱:my-own-world,代碼行數:9,代碼來源:get-route-mapping.ts

示例5: switch

const panesReducer = (previousState = initialState, action) => {
  if (isPanesModule(action)) {
    switch (action.type) {
      case panesActionTypes.OPEN: {
        const {
          payload: { pane },
        } = action;
        return { activeKey: pane.key, panes: { ...previousState.panes, [pane.key]: pane } };
      }
      case panesActionTypes.ACTIVE: {
        const {
          payload: { key },
        } = action;
        return { ...previousState, activeKey: key };
      }
      case panesActionTypes.CLOSE: {
        const { activeKey, panes } = previousState;
        const {
          payload: { key },
        } = action;

        // prettier-ignore
        const index = R.compose(R.indexOf(activeKey), R.keys)(panes);
        const nextPanes = _.omit(panes, key);

        const nextKeys = _.keys(nextPanes);
        const nextKey =
          activeKey && _.has(nextPanes, activeKey)
            ? activeKey
            : // 關閉當前 tab 時定位到後麵一個 tab
              nextKeys[_.min([index, nextKeys.length - 1]) as number];
        return { activeKey: nextKey, panes: nextPanes };
      }
      case panesActionTypes.CLOSE_ALL: {
        return {};
      }
      case panesActionTypes.CLOSE_WITHOUT: {
        const {
          payload: { activeKey },
        } = action;
        if (activeKey) {
          const panes = R.pick([activeKey])(previousState.panes);
          return R.merge(previousState, { panes });
        }
        return {};
      }
      default:
        return { ...previousState, ...action.payload };
    }
  }
  return previousState;
};
開發者ID:danielwii,項目名稱:asuna-admin,代碼行數:52,代碼來源:panes.redux.ts

示例6: async

TaskCardRouter.post('/v2/task-card', authJwt, async (req, res, next) => {
  try {
    const data = R.pick(['title', 'boardId', 'trackId', 'type'], req.body);

    const { jw } = req;

    const card: ITaskCard = await createTaskCard({
      title: data.title,
      type: data.type,
      creatorId: jw.user.id,
      boardId: data.boardId,
      trackId: data.trackId
    });
    res.status(201).send(card);
  } catch (error) {
    next(error);
  }
});
開發者ID:A-Horse,項目名稱:bblist-backend,代碼行數:18,代碼來源:task-card.router.ts

示例7: pick

const createFormatError = (details: any) => (error: any) => {
  const formattedError = pick(ERROR_FIELD_WHITELIST, error)

  if (formattedError.extensions && formattedError.extensions.exception) {
    formattedError.extensions.exception = cleanError(formattedError.extensions.exception)
    if (formattedError.stack === formattedError.extensions.exception.stack) {
      delete formattedError.extensions.exception.stack
    }
  }

  if (formattedError.originalError) {
    formattedError.originalError = cleanError(formattedError.originalError)
    if (formattedError.stack === formattedError.originalError.stack) {
      delete formattedError.originalError.stack
    }
  }

  Object.assign(formattedError, details)

  return formattedError as any
}
開發者ID:vtex,項目名稱:apps-client-node,代碼行數:21,代碼來源:formatters.ts

示例8: async

export const response = async (ctx: GraphQLServiceContext, next: () => Promise<void>) => {
  const {responseInit, graphqlResponse} = ctx.graphql

  const {
    maxAge = '',
    scope = '',
    segment = null,
  } = graphqlResponse ? cacheControl(graphqlResponse, ctx) : {}

  ctx.set({
    ...responseInit && responseInit.headers,
    'Cache-Control': `${maxAge}, ${scope}`,
  })

  if (segment) {
    ctx.vary(SEGMENT_HEADER)
  }

  ctx.body = pick(['data', 'errors'], graphqlResponse!)

  await next()
}
開發者ID:vtex,項目名稱:apps-client-node,代碼行數:22,代碼來源:response.ts

示例9: propOr

  },
  // propOr :: a → String → Object → a
  propOr(defaultVal, fieldsArr, obj) {
    return R.propOr(defaultVal, fieldsArr, obj)
  },
  // [Idx] → {a} → a | Undefined
  // Idx = String | Int
  path(fieldsLevelArr, obj) {
    return R.path(fieldsLevelArr, obj)
  },
  pathOr(defaultVal, fieldsLevelArr, obj) {
    return R.path(defaultVal, fieldsLevelArr, obj)
  },
  // pick :: [k] → {k: v} → {k: v}
  pick(fieldsArr, obj) {
    return R.pick(fieldsArr, obj)
  },

  // assoc/assocPath
  // assoc :: String → a → {k: v} → {k: v}
  assoc(field, val, obj) {
    return R.assoc(field, val, obj)
  },
  // [Idx] → a → {a} → {a}
  // Idx = String | Int
  assocPath(fieldsLevelArr, val, obj) {
    return R.assocPath(fieldsLevelArr, val, obj)
  },

  // dissoc/dissocPath
  // String → {k: v} → {k: v}
開發者ID:stefaniepei,項目名稱:react-redux-scaffold,代碼行數:31,代碼來源:ramda.ts

示例10: canAttack

import * as R from 'ramda';
import { canAttack } from '../../../Character';
import { CardType } from '../../../enums';
import { MinionProps } from './Minion';
import TargetableMinion from './TargetableMinion';
import { performAttack } from '../characterReducer';

const collect: DnD.DragSourceCollector = (connector, monitor) => ({
  connectDragSource: connector.dragSource(),
  canDrag: monitor.canDrag(),
});

const spec: DnD.DragSourceSpec<MinionProps> = {
  beginDrag: (props, monitor, component) => props,
  canDrag: (props, monitor: DnD.DragSourceMonitor) =>
    props.character.owner === props.state.activePlayer &&
    canAttack(props.character),
};

const DraggableMinion = DnD.DragSource<MinionProps>(
  CardType.Minion,
  spec,
  collect
)(TargetableMinion);

const mapStateToProps = R.pick(['state', 'entities']);

export default connect(mapStateToProps, { performAttack })(
  DraggableMinion
) as React.ComponentClass<Partial<MinionProps>>;
開發者ID:zernie,項目名稱:typescript-redux-card-game,代碼行數:30,代碼來源:DraggableMinion.ts


注:本文中的ramda.pick函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。