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

TypeScript idb-keyval.set函数代码示例

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

本文整理汇总了TypeScript中idb-keyval.set函数的典型用法代码示例。如果您正苦于以下问题:TypeScript set函数的具体用法?TypeScript set怎么用?TypeScript set使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了set函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: calculateExpiration

 .then((vendor: Vendor) => {
   vendor.expires = calculateExpiration(vendor.nextRefreshDate, vendorHash);
   vendor.factionLevel = factionLevel(store, vendorDef.summary.factionHash);
   vendor.factionAligned = factionAligned(store, vendorDef.summary.factionHash);
   return set(key, vendor)
     .catch(handleLocalStorageFullError)
     .then(() => vendor);
 })
开发者ID:w1cked,项目名称:DIM,代码行数:8,代码来源:vendor.service.ts


示例2: getAwaToken

export async function getAwaToken(
  account: DestinyAccount,
  action: AwaType,
  item?: D2Item
): Promise<string> {
  if (!awaCache) {
    // load from cache first time
    awaCache = ((await idbKeyval.get('awa-tokens')) || {}) as {
      [key: number]: AwaAuthorizationResult & { used: number };
    };
  }

  let info = awaCache[action];
  if (!info || !tokenValid(info)) {
    try {
      // Note: Error messages should be handled by other components. This is just to tell them to check the app.
      toaster.pop('info', t('AWA.ConfirmTitle'), t('AWA.ConfirmDescription'));

      info = awaCache[action] = {
        ...(await requestAdvancedWriteActionToken(account, action, item)),
        used: 0
      };

      // Deletes of "group A" require an item and shouldn't be cached
      // TODO: This got removed from the API
      /*
      if (action === AwaType.DismantleGroupA) {
        delete awaCache[action]; // don't cache
      }
      */
    } catch (e) {
      throw new Error('Unable to get a token: ' + e.message);
    }

    if (!info || !tokenValid(info)) {
      throw new Error('Unable to get a token: ' + info ? info.developerNote : 'no response');
    }
  }

  info.used++;

  // TODO: really should use a separate db for this
  await idbKeyval.set('awa-tokens', awaCache);

  return info.actionToken;
}
开发者ID:bhollis,项目名称:DIM,代码行数:46,代码来源:advanced-write-actions.ts


示例3: factionLevel

            .catch((e) => {
              // console.log("vendor error", vendorDef.summary.vendorName, 'for', store.name, e, e.code, e.status);
              if (e.status === 'DestinyVendorNotFound') {
                const vendor = {
                  failed: true,
                  code: e.code,
                  status: e.status,
                  expires: Date.now() + 60 * 60 * 1000 + (Math.random() - 0.5) * (60 * 60 * 1000),
                  factionLevel: factionLevel(store, vendorDef.summary.factionHash),
                  factionAligned: factionAligned(store, vendorDef.summary.factionHash)
                };

                return idbKeyval.set(key, vendor).then(() => {
                  throw new Error(`Cached failed vendor ${vendorDef.summary.vendorName}`);
                });
              }
              throw new Error(`Failed to load vendor ${vendorDef.summary.vendorName}`);
            });
开发者ID:bhollis,项目名称:DIM,代码行数:18,代码来源:vendor.service.ts


示例4: getAwaToken

export async function getAwaToken(account: DestinyAccount, action: AwaType, item?: DimItem): Promise<string> {
  if (!awaCache) {
    // load from cache first time
    awaCache = (await idbKeyval.get('awa-tokens') || {}) as {
      [key: number]: AwaAuthorizationResult & { used: number };
    };
  }

  let info = awaCache[action];
  if (!info || !tokenValid(info)) {
    try {
      info = awaCache[action] = {
        ...await requestAdvancedWriteActionToken(account, action, item),
        used: 0
      };

      // Deletes of "group A" require an item and shouldn't be cached
      if (action === AwaType.DismantleGroupA) {
        delete awaCache[action]; // don't cache
      }

      // TODO: really should use a separate db for this
      // without blocking, save this
      idbKeyval.set('awa-tokens', awaCache);
    } catch (e) {
      throw new Error("Unable to get a token: " + e.message);
    }

    if (!info || !tokenValid(info)) {
      throw new Error("Unable to get a token: " + info ? info.developerNote : "no response");
    }
  }

  info.used++;
  return info.actionToken;
}
开发者ID:delphiactual,项目名称:DIM,代码行数:36,代码来源:advanced-write-actions.ts


示例5: loadNewItems

    });
  },

  loadNewItems(account: DestinyAccount): Promise<Set<string>> {
    if (account) {
      const key = newItemsKey(account);
      return Promise.resolve(idbKeyval.get(key)).then(
        (v) => (v as Set<string>) || new Set<string>()
      );
    }
    return Promise.resolve(new Set<string>());
  },

  saveNewItems(newItems: Set<string>, account: DestinyAccount) {
    store.dispatch(setNewItems(newItems));
    return Promise.resolve(idbKeyval.set(newItemsKey(account), newItems));
  },

  buildItemSet(stores) {
    const itemSet = new Set();
    stores.forEach((store) => {
      store.items.forEach((item) => {
        itemSet.add(item.id);
      });
    });
    return itemSet;
  },

  applyRemovedNewItems(newItems: Set<string>) {
    _removedNewItems.forEach((id) => newItems.delete(id));
    _removedNewItems.clear();
开发者ID:bhollis,项目名称:DIM,代码行数:31,代码来源:new-items.service.ts


示例6: set

 .then((remoteData: ClassifiedData) => {
   remoteData.time = Date.now();
   // Don't wait for the set - for some reason this was hanging
   set('classified-data', remoteData).catch(handleLocalStorageFullError);
   return remoteData;
 })
开发者ID:w1cked,项目名称:DIM,代码行数:6,代码来源:classified-data.service.ts


示例7:

 .then((remoteData: ClassifiedData) => {
   remoteData.time = Date.now();
   // Don't wait for the set - for some reason this was hanging
   idbKeyval.set('classified-data', remoteData);
   return remoteData;
 })
开发者ID:bhollis,项目名称:DIM,代码行数:6,代码来源:classified-data.service.ts


示例8: Set

      return;
    }
    store.dispatch(setNewItems(new Set()));
    this.saveNewItems(new Set(), account);
  },

  loadNewItems(account: DestinyAccount): Promise<Set<string>> {
    if (account) {
      const key = newItemsKey(account);
      return Promise.resolve(get(key)).then((v) => (v as Set<string>) || new Set<string>());
    }
    return Promise.resolve(new Set<string>());
  },

  saveNewItems(newItems: Set<string>, account: DestinyAccount) {
    return Promise.resolve(set(newItemsKey(account), newItems)).catch(handleLocalStorageFullError);
  },

  buildItemSet(stores) {
    const itemSet = new Set();
    stores.forEach((store) => {
      store.items.forEach((item) => {
        itemSet.add(item.id);
      });
    });
    return itemSet;
  },

  applyRemovedNewItems(newItems: Set<string>) {
    _removedNewItems.forEach((id) => newItems.delete(id));
    _removedNewItems.clear();
开发者ID:w1cked,项目名称:DIM,代码行数:31,代码来源:new-items.service.ts


示例9: calculateExpiration

 .then((vendor: Vendor) => {
   vendor.expires = calculateExpiration(vendor.nextRefreshDate, vendorHash);
   vendor.factionLevel = factionLevel(store, vendorDef.summary.factionHash);
   vendor.factionAligned = factionAligned(store, vendorDef.summary.factionHash);
   return idbKeyval.set(key, vendor).then(() => vendor);
 })
开发者ID:bhollis,项目名称:DIM,代码行数:6,代码来源:vendor.service.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript idx.default函数代码示例发布时间:2022-05-25
下一篇:
TypeScript idb-keyval.get函数代码示例发布时间: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