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


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

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


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

示例1: loadVendor

  function loadVendor(
    account: DestinyAccount,
    store: D1Store,
    vendorDef,
    defs: D1ManifestDefinitions
  ) {
    const vendorHash = vendorDef.hash;

    const key = vendorKey(store, vendorHash);
    return get<Vendor>(key)
      .then((vendor) => {
        if (cachedVendorUpToDate(vendor, store, vendorDef)) {
          // console.log("loaded local", vendorDef.summary.vendorName, key, vendor);
          if (vendor.failed) {
            throw new Error(`Cached failed vendor ${vendorDef.summary.vendorName}`);
          }
          return vendor;
        } else {
          // console.log("load remote", vendorDef.summary.vendorName, key, vendorHash, vendor, vendor && vendor.nextRefreshDate);
          return getVendorForCharacter(account, store, vendorHash)
            .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);
            })
            .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 set(key, vendor)
                  .catch(handleLocalStorageFullError)
                  .then(() => {
                    throw new Error(`Cached failed vendor ${vendorDef.summary.vendorName}`);
                  });
              }
              throw new Error(`Failed to load vendor ${vendorDef.summary.vendorName}`);
            });
        }
      })
      .then((vendor) => {
        if (vendor && vendor.enabled) {
          const processed = processVendor(vendor, vendorDef, defs, store);
          return processed;
        }
        // console.log("Couldn't load", vendorDef.summary.vendorName, 'for', store.name);
        return Promise.resolve(null);
      });
  }
开发者ID:w1cked,项目名称:DIM,代码行数:59,代码来源: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: getClassifiedData

export function getClassifiedData(): Promise<ClassifiedData> {
  if (classifiedDataPromise) {
    return classifiedDataPromise;
  }

  classifiedDataPromise = get('classified-data').then((data: ClassifiedData) => {
    // Use cached data for up to 4 hours
    if ($DIM_FLAVOR !== 'dev' && data && data.time && data.time > Date.now() - 4 * 60 * 60 * 1000) {
      return data;
    }

    // In dev, use a local copy of the JSON for testing
    const url =
      $DIM_FLAVOR === 'dev'
        ? '/data/classified.json'
        : 'https://beta.destinyitemmanager.com/data/classified.json';

    return Promise.resolve(fetch(url))
      .then((response) => (response.ok ? response.json() : Promise.reject(response)))
      .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;
      })
      .catch((e) => {
        console.error(`Couldn't load classified info from ${url}`, e);

        return {
          itemHash: {}
        };
      });
  });

  return classifiedDataPromise;
}
开发者ID:w1cked,项目名称:DIM,代码行数:36,代码来源:classified-data.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: Set

      stores.forEach((store) => {
        store.items.forEach((item) => {
          if (item.isNew) {
            _removedNewItems.add(item.id);
            item.isNew = false;
          }
        });
      });
      this.saveNewItems(new Set(), account);
    });
  },

  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) => {
开发者ID:bhollis,项目名称:DIM,代码行数:31,代码来源:new-items.service.ts

示例6: clearNewItems

      this.saveNewItems(newItems, account, item.destinyVersion);
    });
  },

  clearNewItems(stores: DimStore[], account: DestinyAccount) {
    if (!stores || !account) {
      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);
      });
    });
开发者ID:w1cked,项目名称:DIM,代码行数:31,代码来源:new-items.service.ts

示例7: Set

    stores.forEach((store) => {
      store.items.forEach((item) => {
        if (item.isNew) {
          _removedNewItems.add(item.id);
          item.isNew = false;
        }
      });
    });
    this.hasNewItems = false;
    this.saveNewItems(new Set(), account);
  },

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

  saveNewItems(newItems: Set<string>, account: DestinyAccount) {
    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);
      });
    });
开发者ID:delphiactual,项目名称:DIM,代码行数:31,代码来源:new-items.service.ts


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