当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript mapValues.default函数代码示例

本文整理汇总了TypeScript中lodash-es/mapValues.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: computeData

export function computeData(entry: NonNullable<GameState>): IScoreboardData {
  const totalScores = mapValues(entry.scores, sum)
  return {
    names: entry.names,
    scores: entry.scores,
    prevScores: mapValues(entry.scores, score => score[score.length - 1] || 0),
    totalScores,
    ranks: getRank(totalScores),
    endedRounds: getEndedRounds(entry)
  }
}
开发者ID:Holi0317,项目名称:bridge-calc,代码行数:11,代码来源:compute-data.ts

示例2: computeScores

export function computeScores(bids: IPlayerMap<number>, wins: IPlayerMap<number>, scores: IPlayerMap<number[]>) {
  return mapValues(scores, (score, playerID) => {
    const bid = bids[playerID]
    const win = wins[playerID]
    return [...score, calculateScore(bid, win)]
  })
}
开发者ID:Holi0317,项目名称:bridge-calc,代码行数:7,代码来源:compute-scores.ts

示例3: getRank

function getRank(scores: IPlayerMap<number>): IPlayerMap<string> {
  const sortedScores: number[] = Object.values(scores).sort((a, b) => b - a)
  const lastScore = sortedScores[sortedScores.length - 1]
  return mapValues(scores, score => {
    const rank = sortedScores.indexOf(score) + 1
    return toOrdinal(rank) + getEmoji(rank, score === lastScore)
  })
}
开发者ID:Holi0317,项目名称:bridge-calc,代码行数:8,代码来源:compute-data.ts

示例4: changePlayersHandler

export function changePlayersHandler(rawState: IWaitingBidState | IWaitingWinState, {newNames, rounds, maker, time}: IChangePlayersAction): IWaitingBidState | IEndedState {
  // Short circuit. When action.rounds is less than current round
  if (rounds < rawState.currentRound) {
    // Tslint false positive on shallowed variable -- Shallowed variable on the else branch
    // tslint:disable-next-line: no-shadowed-variable
    const state = toEndedState(rawState, time)
    state.names = newNames
    state.rounds = rounds
    state.scores = mapValues(state.scores, (score: number[]) => score.slice(0, rounds))
    return state
  }

  const state = toWaitingBidState(rawState)
  state.rounds = rounds

  // Set currentPlayerOrder
  const newPlayerIDList = Object.keys(newNames)
  state.currentPlayerOrder = toFront(newPlayerIDList, newPlayerIDList.indexOf(maker))

  // Change scores
  const oldScores = state.scores
  const freshScores = range(state.currentRound - 1).fill(0) // Score for new players. I am terrible at naming.
  state.scores = mapValues(newNames, (_: string, ID: string): number[] => (
    (ID in oldScores)
      ? oldScores[ID]
      : freshScores
  ))

  // Change bid
  const oldBid = state.bid
  state.bid = mapValues(newNames, (_: string, ID: string): number => (
    (ID in oldBid)
      ? oldBid[ID]
      : 0
  ))

  // Change names field lastly
  state.names = newNames

  return state
}
开发者ID:Holi0317,项目名称:bridge-calc,代码行数:41,代码来源:change-players-handler.ts

示例5: retrieveOldData

export function retrieveOldData(): IOldGameData | null {
  const dataMap = mapValues(KEYS, key => {
    const value = localStorage.getItem(key)
    return value != null ? JSON.parse(value) : null
  })

  if (Object.values(dataMap).includes(null)) {
    return null
  } else {
    return dataMap as any
  }
}
开发者ID:Holi0317,项目名称:bridge-calc,代码行数:12,代码来源:old-state-manager.ts

示例6: validateWin

function validateWin(opts: IStackInput, t: TranslationFunction): IPlayerMap<string> | null {
  if (!opts.win || /* Is empty? */isOk(opts.win)) {
    return null
  }
  const sum: number = sumBy(Object.entries(opts.win), ([, value]) => value)
  if (sum === opts.currentRound) {
    return null
  }
  const msg = sum > opts.currentRound
    ? t('Too many stacks')
    : t('Too less stacks')
  return mapValues(opts.win, () => msg)
}
开发者ID:Holi0317,项目名称:bridge-calc,代码行数:13,代码来源:stack-input-validator.ts

示例7: validateNames

function validateNames(names: IPlayerMap<string>, t: TranslationFunction): IPlayerMap<string> {
  const duplicates = dupe(Object.values(names))
  const res: IPlayerMap<string | null> = mapValues(names, (name: string) => {
    if (name === '') {
      return t('Name cannot be empty')
    }
    if (duplicates.includes(name)) {
      return t('Name cannot be repeated')
    }
    return null
  })
  return removeUndef(res)
}
开发者ID:Holi0317,项目名称:bridge-calc,代码行数:13,代码来源:settings-validator.ts

示例8: createForm

export function createForm(dialog: DialogViewModel, formBuilder: FormBuilder): { form: FormGroup, dialog: DialogViewModel, parms: Dictionary<ParameterViewModel>, sub: ISubscription } {
    const pps = dialog.parameters;
    const parms = zipObject(map(pps, p => p.id), map(pps, p => p)) as Dictionary<ParameterViewModel>;
    const controls = mapValues(parms, p => [p.getValueForControl(), (a: AbstractControl) => p.validator(a)]);
    const form = formBuilder.group(controls);

    const sub = form.valueChanges.subscribe((data: any) => {
        // cache parm values
        forEach(data, (v, k) => parms[k!].setValueFromControl(v));
        dialog.setParms();
    });

    return { form: form, dialog: dialog, parms: parms, sub: sub };
}
开发者ID:NakedObjectsGroup,项目名称:NakedObjectsFramework,代码行数:14,代码来源:helpers-components.ts

示例9: skip

export function skip(state: IWaitingBidState | IWaitingWinState, n: number, time: number): IWaitingBidState | IEndedState {
  if (state.currentRound > state.rounds) {
    // Last round. Return regardless of content of n.
    return toEndedState(state, time)
  }
  if (n <= 0) {
    // Last skip action and not last round
    return toWaitingBidState(state)
  }

  const newState = toWaitingBidState(state)
  newState.bid = bidWinGenerator(Object.keys(state.names))
  newState.scores = mapValues(state.scores, score => [...score, 0])
  newState.currentPlayerOrder = toFront(state.currentPlayerOrder, 1)
  newState.currentRound = state.currentRound + 1

  return skip(newState, n - 1, time)
}
开发者ID:Holi0317,项目名称:bridge-calc,代码行数:18,代码来源:skip.ts

示例10: migratePlayers

/**
 * Create names, scores, bid and win maps
 */
function migratePlayers(players: IOldPlayers[]): IPlayerMaps {
  const ids = players.map(cuid)
  const map = {
    names: 'name',
    scores: 'score',
    bid: 'bid',
    win: 'win'
  }
  const res = mapValues(map, (prop: keyof IOldPlayers) => (
    zipObject(ids, players.map(player => player[prop]))
  )) as any

  // Type convertion
  res.bid = numberize(res.bid)
  res.win = numberize(res.win)

  return res
}
开发者ID:Holi0317,项目名称:bridge-calc,代码行数:21,代码来源:converter.ts


注:本文中的lodash-es/mapValues.default函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。