本文整理汇总了TypeScript中underscore.pluck函数的典型用法代码示例。如果您正苦于以下问题:TypeScript pluck函数的具体用法?TypeScript pluck怎么用?TypeScript pluck使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pluck函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: expect
unsubscribe = store.subscribe(() => {
expect(store.getState().status).toBe(GameStatus.VOTE_MAFIA);
expect(store.getState().active_roles).toEqual([Roles.MAFIA]);
expect(store.getState().vote_variants).toEqual(_.pluck(store.getState().players.filter(player => player.role !== Roles.MAFIA), 'token'));
expect(store.getState().votes).toEqual(_.pluck(store.getState().players.filter(player => player.role === Roles.MAFIA), 'token').map(token => ({who_token: token})));
// Отписываемся т. к. store общий для всех тестов
unsubscribe();
done();
});
开发者ID:andreevWork,项目名称:mafia,代码行数:10,代码来源:FirstScenario.ts
示例2: it
it('when calling getAvailableValues returns children of the last parent', () => {
Simulate.query(test.env, simulateQueryData);
const values: string[] = pluck(test.cmp.getAvailableValues(), 'value');
for (let i = 0; i < simulateQueryData.results.categoryFacets[0].values.length - 1; i++) {
expect(values[i]).toEqual(`value${i}`);
}
});
开发者ID:francoislg,项目名称:search-ui,代码行数:7,代码来源:CategoryFacetTest.ts
示例3: GameReducer
export default function GameReducer (state: GameState = InitialGameState, action: IGameAction): GameState {
switch(action.type) {
case GameAction.CREATE_GAME:
return getNewState(InitialGameState, ['time_create', 'time_last_update', 'time_last_update_players'], {
status: GameStatus.START_THE_GAME,
players: action.payload.players
});
case GameAction.NEXT_GAME_STEP:
return GameStatusReducer(state, action);
case GameAction.VOTE:
// Если токен который голосует отсутствует в коллекции голосующих ничего не делаем
if(state.votes.length && !~_.pluck(state.votes, 'who_token').indexOf(action.payload.who_token)) {
return state;
}
return getNewState(state, [], {
votes: state.votes.map((vote: VoteObject) => {
return action.payload.who_token === vote.who_token ? _.extend({for_whom_token: action.payload.for_whom_token}, vote) : vote;
})
});
default:
return state;
}
}
开发者ID:andreevWork,项目名称:mafia,代码行数:27,代码来源:GameReducer.ts
示例4: it
it(`тест с числом игроков равным ${count_players}`, () => {
// Создаем массив с игроками
players = Array.apply(null, {length: count_players}).map(() => getPlayer());
// Отправляем в тестируемую функцию
game_players = Player.RolesForPlayers(players);
// По приходу из коллекции игроков, забираем у каждого его роль и суем в массив
roles_array = _.pluck(game_players, 'role');
// Затем считаем, сколько пришлось игроков на каждую роль
count_roles = _.countBy(roles_array, _.identity);
// Поскольку данные персонажи есть не всегда, надо явно проставить ноль для сравнения
count_roles[Roles.COMMISSAR] = count_roles[Roles.COMMISSAR] || 0;
count_roles[Roles.WHORE] = count_roles[Roles.WHORE] || 0;
mafia_count = Math.floor((count_players - MIN_PLAYERS) / STEP_CHANGE_ROLES) + 1;
doctor_count = 1;
whore_count = 1;
commissar_count = count_players >= MIN_PLAYERS + STEP_CHANGE_ROLES ? 1 : 0;
expect(count_roles[Roles.MAFIA]).toBe(mafia_count);
expect(count_roles[Roles.DOCTOR]).toBe(doctor_count);
expect(count_roles[Roles.COMMISSAR]).toBe(commissar_count);
expect(count_roles[Roles.WHORE]).toBe(whore_count);
expect(count_roles[Roles.INHABITANT]).toBe(count_players - mafia_count - doctor_count - commissar_count - whore_count);
});
开发者ID:andreevWork,项目名称:mafia,代码行数:28,代码来源:PlayerTest.ts
示例5: async
client.on(messages.FetchProfileCollectionsYield, async ({ items }) => {
this.push({
collections: {
set: indexBy(items, "id"),
ids: pluck(items, "id"),
},
});
});
开发者ID:HorrerGames,项目名称:itch,代码行数:8,代码来源:collections-fetcher.ts
示例6: mergeUsers
export function mergeUsers(current: ISearchResults, users: User[]) {
return mergeSearchResults(current, {
users: {
ids: pluck(users, "id"),
set: indexBy(users, "id"),
},
});
}
开发者ID:HorrerGames,项目名称:itch,代码行数:8,代码来源:search-helpers.ts
示例7: mergeGames
export function mergeGames(current: ISearchResults, games: Game[]) {
return mergeSearchResults(current, {
games: {
ids: pluck(games, "id"),
set: indexBy(games, "id"),
},
});
}
开发者ID:HorrerGames,项目名称:itch,代码行数:8,代码来源:search-helpers.ts
示例8: getMaxTransactionDepth
function getMaxTransactionDepth(sindex:SindexShortEntry[]) {
const ids = _.uniq(_.pluck(sindex, 'tx'))
let maxTxChainingDepth = 0
for (let id of ids) {
maxTxChainingDepth = Math.max(maxTxChainingDepth, getTransactionDepth(id, sindex, 0))
}
return maxTxChainingDepth
}
开发者ID:duniter,项目名称:duniter,代码行数:8,代码来源:local_rules.ts
示例9: sortFacetValues
public sortFacetValues(hierarchyFacetValues = this.hierarchyFacetValues): FacetValue[] {
if (!this.facet.shouldReshuffleFacetValuesClientSide) {
let sortArray = _.map(hierarchyFacetValues, (hierarchy: FacetValue, idx: number) => {
return {
hierarchy: hierarchy,
idx: idx
};
});
// If we exclude the top level, the alpha order is not respected (since it is done by the index, and the first level is omitted by client side code).
// Do the ordering client side, in the precise case where its alpha ordering and the starting level is not 0;
if (
this.facet.options.levelStart != 0 &&
this.facet.options.sortCriteria &&
this.facet.options.sortCriteria.toLowerCase().indexOf('alpha') != -1
) {
let reversed = this.facet.options.sortCriteria.toLowerCase().indexOf('descending') != -1;
sortArray = sortArray.sort((first, second) => {
let firstInTopLevel =
_.find(this.facet.topLevelHierarchy, (hierarchy: IValueHierarchy) => {
return hierarchy.facetValue.value.toLowerCase() == first.hierarchy.value.toLowerCase();
}) != null;
let secondInTopLevel =
_.find(this.facet.topLevelHierarchy, (hierarchy: IValueHierarchy) => {
return hierarchy.facetValue.value.toLowerCase() == first.hierarchy.value.toLowerCase();
}) != null;
if (firstInTopLevel && secondInTopLevel) {
let firstValue = this.facet.getValueCaption(first.hierarchy);
let secondValue = this.facet.getValueCaption(second.hierarchy);
let compared = firstValue.localeCompare(secondValue);
return reversed ? -1 * compared : compared;
}
return first.idx - second.idx;
});
}
// Normally facet values are sorted by selected first, then inactive, then excluded values.
// For hierarchical, we want selected first, then those that have childs selected, then normal sorting.
sortArray = sortArray.sort((first, second) => {
if (first.hierarchy.selected === second.hierarchy.selected) {
let firstFromHierarchy = this.facet.getValueFromHierarchy(first.hierarchy);
let secondFromHierarchy = this.facet.getValueFromHierarchy(second.hierarchy);
if (firstFromHierarchy.hasChildSelected === secondFromHierarchy.hasChildSelected) {
return first.idx - second.idx;
} else {
return firstFromHierarchy.hasChildSelected ? -1 : 1;
}
} else {
return first.hierarchy.selected ? -1 : 1;
}
});
return _.pluck(sortArray, 'hierarchy');
}
return hierarchyFacetValues;
}
开发者ID:coveo,项目名称:search-ui,代码行数:58,代码来源:HierarchicalFacetValuesList.ts
注:本文中的underscore.pluck函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论