本文整理匯總了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();
});
示例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}`);
}
});
示例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;
}
}
示例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);
});
示例5: async
client.on(messages.FetchProfileCollectionsYield, async ({ items }) => {
this.push({
collections: {
set: indexBy(items, "id"),
ids: pluck(items, "id"),
},
});
});
示例6: mergeUsers
export function mergeUsers(current: ISearchResults, users: User[]) {
return mergeSearchResults(current, {
users: {
ids: pluck(users, "id"),
set: indexBy(users, "id"),
},
});
}
示例7: mergeGames
export function mergeGames(current: ISearchResults, games: Game[]) {
return mergeSearchResults(current, {
games: {
ids: pluck(games, "id"),
set: indexBy(games, "id"),
},
});
}
示例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
}
示例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;
}