當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript dexie.Promise類代碼示例

本文整理匯總了TypeScript中dexie.Promise的典型用法代碼示例。如果您正苦於以下問題:TypeScript Promise類的具體用法?TypeScript Promise怎麽用?TypeScript Promise使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Promise類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: storeHashtagsInTweets

    storeHashtagsInTweets(jsons: Twitter.Status[]) {
        const entries = [] as HashtagsScheme[];
        const push = Array.prototype.push;

        for (const j of jsons) {
            if (!j.entities || !j.entities.hashtags) {
                continue;
            }

            const hashtags = j.entities.hashtags
                .map(h => ({
                    text: h.text,
                    timestamp: Date.now(),
                }));

            push.apply(entries, hashtags);
        }

        if (entries.length === 0) {
            return Dexie.Promise.resolve<void>();
        }

        return this.table.bulkPut(entries)
            .catch((e: Error) => {
                log.error('Error on storing hashtags in tweets:', e, entries);
                throw e;
            });
    }
開發者ID:DevenLu,項目名稱:YourFukurou,代碼行數:28,代碼來源:hashtags.ts

示例2: relationValueMap

  private async relationValueMap(joinQueryIds: Relation<number[]>): Promise<Relation<Map<number, string>>> {
    let accounts      = [] as DexiePromise<Entity[]>[];
    let categories    = [] as DexiePromise<Entity[]>[];
    let subcategories = [] as DexiePromise<Entity[]>[];
    let payeePayers   = [] as DexiePromise<Entity[]>[];
    let tags          = [] as DexiePromise<Entity[]>[];
    const tables = [
      this.db.accounts,
      this.db.categories,
      this.db.subcategories,
      this.db.payeePayers,
      this.db.tags
    ];
    await this.db.transaction('r', tables, () => {
      joinQueryIds.accounts     .forEach((id) => accounts     .push(this.db.accounts     .where('id').equals(id).toArray()));
      joinQueryIds.categories   .forEach((id) => categories   .push(this.db.categories   .where('id').equals(id).toArray()));
      joinQueryIds.subcategories.forEach((id) => subcategories.push(this.db.subcategories.where('id').equals(id).toArray()));
      joinQueryIds.payeePayers  .forEach((id) => payeePayers  .push(this.db.payeePayers  .where('id').equals(id).toArray()));
      joinQueryIds.tags         .forEach((id) => tags         .push(this.db.tags         .where('id').equals(id).toArray()));
    });

    const allResolved = {
      accounts     : lodash.flattenDeep<Entity>(await Dexie.Promise.all(accounts)),
      categories   : lodash.flattenDeep<Entity>(await Dexie.Promise.all(categories)),
      subcategories: lodash.flattenDeep<Entity>(await Dexie.Promise.all(subcategories)),
      payeePayers  : lodash.flattenDeep<Entity>(await Dexie.Promise.all(payeePayers)),
      tags         : lodash.flattenDeep<Entity>(await Dexie.Promise.all(tags)),
    } as Relation<Entity[]>;

    const _allMap = {
      accounts:      new Map(),
      categories:    new Map(),
      subcategories: new Map(),
      payeePayers:   new Map(),
      tags:          new Map()
    } as Relation<Map<number, string>>;

    allResolved.accounts     .map((item) => _allMap.accounts     .set(item.id, item.name));
    allResolved.categories   .map((item) => _allMap.categories   .set(item.id, item.name));
    allResolved.subcategories.map((item) => _allMap.subcategories.set(item.id, item.name));
    allResolved.payeePayers  .map((item) => _allMap.payeePayers  .set(item.id, item.name));
    allResolved.tags         .map((item) => _allMap.tags         .set(item.id, item.name));

    return _allMap;
  }
開發者ID:armorik83,項目名稱:reveal-wealth,代碼行數:45,代碼來源:money-transaction-repository.service.ts

示例3: getUrlsAndStatuses

// With async/await
async function getUrlsAndStatuses() {
    let urls = await db.syncable.list();
    let statuses = await Dexie.Promise.all(urls.map(url => db.syncable.getStatus(url)));
}
開發者ID:lincolon,項目名稱:Dexie.js,代碼行數:5,代碼來源:test-typings.ts


注:本文中的dexie.Promise類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。