本文整理汇总了TypeScript中underscore.indexBy函数的典型用法代码示例。如果您正苦于以下问题:TypeScript indexBy函数的具体用法?TypeScript indexBy怎么用?TypeScript indexBy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了indexBy函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: updateCommonsNowThrows
async function updateCommonsNowThrows(store: IStore) {
if (!store.getState().setup.done) {
return;
}
const { caves, downloadKeys, installLocations } = await call(
messages.FetchCommons,
{}
);
let locationSizes = {};
if (!isEmpty(installLocations)) {
for (const x of installLocations) {
locationSizes[x.id] = x.sizeInfo.installedSize;
}
}
push(store, {
caves: indexBy(caves, "id"),
caveIdsByGameId: groupIdBy(caves, "gameId"),
downloadKeys: indexBy(downloadKeys, "id"),
downloadKeyIdsByGameId: groupIdBy(downloadKeys, "gameId"),
locationSizes,
});
}
示例2: on
on(actions.downloadsListed, (state, action) => {
const { downloads } = action.payload;
return {
...state,
items: indexBy(downloads, "id"),
};
});
示例3: mergeUsers
export function mergeUsers(current: ISearchResults, users: User[]) {
return mergeSearchResults(current, {
users: {
ids: pluck(users, "id"),
set: indexBy(users, "id"),
},
});
}
示例4: mergeGames
export function mergeGames(current: ISearchResults, games: Game[]) {
return mergeSearchResults(current, {
games: {
ids: pluck(games, "id"),
set: indexBy(games, "id"),
},
});
}
示例5: async
client.on(messages.FetchProfileCollectionsYield, async ({ items }) => {
this.push({
collections: {
set: indexBy(items, "id"),
ids: pluck(items, "id"),
},
});
});
示例6: saveLoadouts
async function saveLoadouts(loadouts: Loadout[]): Promise<Loadout[]> {
const loadoutPrimitives = loadouts.map(dehydrate);
const data = {
'loadouts-v3.0': loadoutPrimitives.map((l) => l.id),
..._.indexBy(loadoutPrimitives, (l) => l.id)
};
await SyncService.set(data);
return loadouts;
}
示例7: it
it("groupIdBy", () => {
assert.deepEqual(groupIdBy(null, "gameId"), {});
assert.deepEqual(groupIdBy(undefined, "gameId"), {});
assert.deepEqual(groupIdBy([], "gameId"), {});
assert.deepEqual(groupIdBy({}, "gameId"), {});
const items = [
{ id: 1, gameId: 11 },
{ id: 4, gameId: 44 },
{ id: 7, gameId: 77 },
{ id: 77, gameId: 77 },
];
assert.deepEqual(groupIdBy(items, "gameId"), {
11: [1],
44: [4],
77: [7, 77],
} as any);
assert.deepEqual(
groupIdBy<typeof items[0]>(items, o => String(o.gameId * 10)),
{
110: [1],
440: [4],
770: [7, 77],
} as any
);
assert.deepEqual(groupIdBy(items, "id"), {
1: [1],
4: [4],
7: [7],
77: [77],
} as any);
const itemMap = indexBy(items, "id");
assert.deepEqual(groupIdBy(itemMap, "gameId"), {
11: [1],
44: [4],
77: [7, 77],
} as any);
assert.deepEqual(groupIdBy(itemMap, "id"), {
1: [1],
4: [4],
7: [7],
77: [77],
} as any);
});
示例8: syncInstallLocations
async function syncInstallLocations(store: Store) {
const { installLocations } = await mcall(messages.InstallLocationsList, {});
const newLocationsById = indexBy(installLocations, "id");
const { preferences } = store.getState();
if (!preferences.importedOldInstallLocations) {
await mkdirp(appdataLocationPath());
let oldLocations = {
...preferences.installLocations,
appdata: {
id: "appdata",
path: appdataLocationPath(),
},
} as { [key: string]: { id: string; path: string } };
let numAdded = 0;
if (!isEmpty(oldLocations)) {
for (const id of Object.keys(oldLocations)) {
logger.debug(`Checking install location ${id}...`);
const oldLoc = oldLocations[id];
const newLoc = newLocationsById[id];
if (newLoc) {
logger.debug(`Has on butler side too!`);
} else {
logger.debug(`Synchronizing ${id}...`);
numAdded++;
try {
await mcall(messages.InstallLocationsAdd, {
id,
path: oldLoc.path,
});
} catch (e) {
logger.warn(`Could not add ${oldLoc.path}: ${e.stack}`);
}
}
}
}
if (numAdded > 0) {
logger.info(`Registered ${numAdded} install locations with butler`);
} else {
logger.info(`All install locations synchronized with butler`);
}
store.dispatch(
actions.updatePreferences({ importedOldInstallLocations: true })
);
}
}
示例9: syncInstallLocations
async function syncInstallLocations(store: IStore) {
const { installLocations } = await call(messages.InstallLocationsList, {});
const newLocationsById = indexBy(installLocations, "id");
const rs = store.getState();
let oldLocations = {
...rs.preferences.installLocations,
appdata: {
id: "appdata",
path: appdataLocationPath(),
},
};
let numAdded = 0;
if (!isEmpty(oldLocations)) {
for (const id of Object.keys(oldLocations)) {
logger.debug(`Checking install location ${id}...`);
const oldLoc = oldLocations[id];
const newLoc = newLocationsById[id];
if (newLoc) {
logger.debug(`Has on butler side too!`);
} else {
logger.debug(`Synchronizing ${id}...`);
numAdded++;
await call(messages.InstallLocationsAdd, {
id,
path: oldLoc.path,
});
}
}
}
if (numAdded > 0) {
logger.info(`Registered ${numAdded} install locations with butler`);
} else {
logger.info(`All install locations synchronized with butler`);
}
}
示例10: processItems
return processItems({ id: null } as any, saleItems.map((i) => i.item)).then((items) => {
const itemsById = _.indexBy(items, 'id');
const categories = _.compact(
_.map(vendor.saleItemCategories, (category: any) => {
const categoryInfo = vendorDef.categories[category.categoryIndex];
if (_.contains(categoryBlacklist, categoryInfo.categoryHash)) {
return null;
}
const categoryItems = category.saleItems.map((saleItem) => {
const unlocked = isSaleItemUnlocked(saleItem);
return {
index: saleItem.vendorItemIndex,
costs: saleItem.costs
.map((cost) => {
return {
value: cost.value,
currency: _.pick(
defs.InventoryItem.get(cost.itemHash),
'itemName',
'icon',
'itemHash'
)
};
})
.filter((c) => c.value > 0),
item: itemsById[`vendor-${vendorDef.hash}-${saleItem.vendorItemIndex}`],
// TODO: caveat, this won't update very often!
unlocked,
unlockedByCharacter: unlocked ? [store.id] : [],
failureStrings: saleItem.failureIndexes
.map((i) => vendorDef.failureStrings[i])
.join('. ')
};
});
let hasArmorWeaps = false;
let hasVehicles = false;
let hasShadersEmbs = false;
let hasEmotes = false;
let hasConsumables = false;
let hasBounties = false;
categoryItems.forEach((saleItem) => {
const item = saleItem.item;
if (
item.bucket.sort === 'Weapons' ||
item.bucket.sort === 'Armor' ||
item.type === 'Artifact' ||
item.type === 'Ghost'
) {
if (item.talentGrid) {
item.dtrRoll = _.compact(item.talentGrid.nodes.map((i) => i.dtrRoll)).join(';');
}
hasArmorWeaps = true;
}
if (item.type === 'Ship' || item.type === 'Vehicle') {
hasVehicles = true;
}
if (item.type === 'Emblem' || item.type === 'Shader') {
hasShadersEmbs = true;
}
if (item.type === 'Emote') {
hasEmotes = true;
}
if (item.type === 'Material' || item.type === 'Consumable') {
hasConsumables = true;
}
if (item.type === 'Bounties') {
hasBounties = true;
}
});
return {
index: category.categoryIndex,
title: categoryInfo.displayTitle,
saleItems: categoryItems,
hasArmorWeaps,
hasVehicles,
hasShadersEmbs,
hasEmotes,
hasConsumables,
hasBounties
};
})
);
items.forEach((item: any) => {
item.vendorIcon = createdVendor.icon;
});
createdVendor.categories = categories;
createdVendor.hasArmorWeaps = _.any(categories, (c) => c.hasArmorWeaps);
createdVendor.hasVehicles = _.any(categories, (c) => c.hasVehicles);
createdVendor.hasShadersEmbs = _.any(categories, (c) => c.hasShadersEmbs);
createdVendor.hasEmotes = _.any(categories, (c) => c.hasEmotes);
createdVendor.hasConsumables = _.any(categories, (c) => c.hasConsumables);
createdVendor.hasBounties = _.any(categories, (c) => c.hasBounties);
return createdVendor;
//.........这里部分代码省略.........