當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。