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


TypeScript angular.IPromise類代碼示例

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


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

示例1: reportException

  (item: DimItem, store: DimStore, equip: boolean, amount: number) => {
    const reload = item.equipped || equip;
    let promise: IPromise<any> = dimItemService.moveTo(item, store, equip, amount);

    if (reload) {
      // Refresh light levels and such
      promise = promise.then((item: DimItem) => {
        return item
          .getStoresService()
          .updateCharacters()
          .then(() => item);
      });
    }

    promise = promise.then((item: DimItem) => item.updateManualMoveTimestamp()).catch((e) => {
      toaster.pop('error', item.name, e.message);
      console.error('error moving item', item.name, 'to', store.name, e);
      // Some errors aren't worth reporting
      if (
        e.code !== 'wrong-level' &&
        e.code !== 'no-space' &&
        e.code !== 1671 /* PlatformErrorCodes.DestinyCannotPerformActionAtThisLocation */
      ) {
        reportException('moveItem', e);
      }
    });

    loadingTracker.addPromise(promise);

    return promise;
  }
開發者ID:bhollis,項目名稱:DIM,代碼行數:31,代碼來源:dimItemMoveService.factory.ts

示例2: queuedAction

export const consolidate = queuedAction((actionableItem: DimItem, store: DimStore) => {
  const stores = _.filter(actionableItem.getStoresService().getStores(), (s) => {
    return !s.isVault;
  });
  const vault = actionableItem.getStoresService().getVault()!;

  let promise: IPromise<any> = $q.all(
    stores.map((s) => {
      // First move everything into the vault
      const item = _.find(s.items, (i) => {
        return store.id !== i.owner && i.hash === actionableItem.hash && !i.location.inPostmaster;
      });
      if (item) {
        const amount = s.amountOfItem(actionableItem);
        return dimItemService.moveTo(item, vault, false, amount);
      }
      return $q.when();
    })
  );

  // Then move from the vault to the character
  if (!store.isVault) {
    promise = promise.then(
      (): IPromise<any> | undefined => {
        const item = vault.items.find(
          (i) => i.hash === actionableItem.hash && !i.location.inPostmaster
        );
        if (item) {
          const amount = vault.amountOfItem(actionableItem);
          return dimItemService.moveTo(item, store, false, amount);
        }
        return undefined;
      }
    );
  }

  promise = promise
    .then(() => {
      let message;
      if (store.isVault) {
        message = t('ItemMove.ToVault', {
          name: actionableItem.name
        });
      } else {
        message = t('ItemMove.ToStore', {
          name: actionableItem.name,
          store: store.name
        });
      }
      toaster.pop('success', t('ItemMove.Consolidate', { name: actionableItem.name }), message);
    })
    .catch((a) => {
      toaster.pop('error', actionableItem.name, a.message);
      console.log('error consolidating', actionableItem, a);
    });

  loadingTracker.addPromise(promise);

  return promise;
});
開發者ID:bhollis,項目名稱:DIM,代碼行數:60,代碼來源:dimItemMoveService.factory.ts

示例3: listMasters

 public listMasters(type: BuildServiceType = null): IPromise<string[]> {
   const allMasters: IPromise<string[]> = this.API.one('v2').one('builds').get();
   if (!allMasters) {
     return this.$q.reject('An error occurred when retrieving build masters');
   }
   switch (type) {
     case BuildServiceType.Jenkins:
       return allMasters.then(masters => masters.filter(master => !(/^travis-/.test(master))));
     case BuildServiceType.Travis:
       return allMasters.then(masters => masters.filter(master => /^travis-/.test(master)));
     default:
       return allMasters;
   }
 }
開發者ID:robfletcher,項目名稱:deck,代碼行數:14,代碼來源:igor.service.ts

示例4: dequipItem

  function dequipItem(item: DimItem, excludeExotic = false): IPromise<DimItem> {
    const storeService = getStoreService(item);
    const similarItem = getSimilarItem(item, [], excludeExotic);
    if (!similarItem) {
      return $q.reject(new Error($i18next.t('ItemService.Deequip', { itemname: item.name })));
    }
    const source = storeService.getStore(item.owner)!;
    const target = storeService.getStore(similarItem.owner)!;

    let p: IPromise<DimItem> = $q.when();
    if (source.id !== target.id) {
      p = moveTo(similarItem, source, true);
    }

    return p
      .then(() => equipItem(similarItem))
      .then(() => item);
  }
開發者ID:delphiactual,項目名稱:DIM,代碼行數:18,代碼來源:dimItemService.factory.ts

示例5: listMasters

 public static listMasters(buildType: BuildServiceType = null): IPromise<string[]> {
   const allMasters: IPromise<string[]> = API.one('v2')
     .one('builds')
     .withParams({ type: buildType })
     .get();
   if (!allMasters) {
     return $q.reject('An error occurred when retrieving build masters');
   }
   switch (buildType) {
     case BuildServiceType.Jenkins:
       return allMasters.then(masters => masters.filter(master => !/^travis-/.test(master)));
     case BuildServiceType.Travis:
       return allMasters.then(masters => masters.filter(master => /^travis-/.test(master)));
     case BuildServiceType.Concourse:
       return allMasters.then(masters => masters.filter(master => /^concourse-/.test(master)));
     default:
       return allMasters;
   }
 }
開發者ID:emjburns,項目名稱:deck,代碼行數:19,代碼來源:igor.service.ts

示例6: isValidTransfer

  /**
   * Check whether this transfer can happen. If necessary, make secondary inventory moves
   * in order to make the primary transfer possible, such as making room or dequipping exotics.
   */
  function isValidTransfer(
    equip: boolean,
    store: DimStore,
    item: DimItem,
    amount: number,
    excludes?: DimItem[],
    reservations?: MoveReservations
  ): IPromise<any> {
    let promise: IPromise<any> = $q.when();

    if (equip) {
      promise = promise.then(() => canEquip(item, store));
      if (item.equippingLabel) {
        promise = promise.then(() => canEquipExotic(item, store));
      }
    }

    return promise.then(() => canMoveToStore(item, store, amount, { excludes, reservations }));
  }
開發者ID:bhollis,項目名稱:DIM,代碼行數:23,代碼來源:dimItemService.factory.ts

示例7: func

 // interval is in milliseconds
 public static buildRetrySequence<T>(
   func: () => T | IPromise<T>,
   stopCondition: (results: T) => boolean,
   limit: number,
   interval: number,
 ): IPromise<T> {
   const call: T | IPromise<T> = func();
   const promise: IPromise<T> = call.hasOwnProperty('then') ? (call as IPromise<T>) : $q.resolve(call);
   if (limit === 0) {
     return promise;
   } else {
     return promise
       .then((result: T) => {
         if (stopCondition(result)) {
           return result;
         } else {
           return $timeout(interval).then(() => this.buildRetrySequence(func, stopCondition, limit - 1, interval));
         }
       })
       .catch(() => $timeout(interval).then(() => this.buildRetrySequence(func, stopCondition, limit - 1, interval)));
   }
 }
開發者ID:emjburns,項目名稱:deck,代碼行數:23,代碼來源:retry.service.ts

示例8: applyConfig

        function applyConfig () {
          optionsAlreadyRead.then(function () {
            checkSelection();
            updateNgModel();
            checkConfig(scope.config, setViewValue);
            controller.$validate();
          });

          if (!configRead) {
            updateStaticTexts();
            configRead = true;
          }
        }
開發者ID:w11k,項目名稱:w11k-select,代碼行數:13,代碼來源:w11k-select.directive.ts

示例9: render

        function render () {
          optionsAlreadyRead.then(function () {
            ngModelAlreadyRead = true;

            let viewValue = controller.$viewValue;

            setSelected(internalOptions, false);

            let i = viewValue.length;
            while (i--) {
              let trackingId = value2trackingId(viewValue[i], w11kSelectHelper, optionsExpParsed);
              let option = internalOptionsMap[trackingId];

              if (option) {
                option.state = OptionState.selected;
              }
            }

            updateHeader();
          });
        }
開發者ID:w11k,項目名稱:w11k-select,代碼行數:21,代碼來源:w11k-select.directive.ts


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