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