• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript underscore.indexBy函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript underscore.indexOf函数代码示例发布时间:2022-05-25
下一篇:
TypeScript underscore.has函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap