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


TypeScript underscore.indexBy函数代码示例

本文整理汇总了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,
  });
}
开发者ID:HorrerGames,项目名称:itch,代码行数:25,代码来源:commons.ts

示例2: on

 on(actions.downloadsListed, (state, action) => {
   const { downloads } = action.payload;
   return {
     ...state,
     items: indexBy(downloads, "id"),
   };
 });
开发者ID:HorrerGames,项目名称:itch,代码行数:7,代码来源:downloads.ts

示例3: 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

示例4: 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

示例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: 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;
  }
开发者ID:bhollis,项目名称:DIM,代码行数:11,代码来源:loadout.service.ts

示例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);
  });
开发者ID:itchio,项目名称:itch,代码行数:50,代码来源:group-id-by.spec.ts

示例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 })
    );
  }
}
开发者ID:itchio,项目名称:itch,代码行数:48,代码来源:setup.ts

示例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`);
  }
}
开发者ID:HorrerGames,项目名称:itch,代码行数:38,代码来源:setup.ts

示例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;
//.........这里部分代码省略.........
开发者ID:bhollis,项目名称:DIM,代码行数:101,代码来源:vendor.service.ts


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