本文整理汇总了TypeScript中@orbit/core.Promise类的典型用法代码示例。如果您正苦于以下问题:TypeScript Promise类的具体用法?TypeScript Promise怎么用?TypeScript Promise使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Promise类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: jsonapiResponse
export function jsonapiResponse(_options, body?, timeout?) {
let options;
let response;
if (typeof _options === 'number') {
options = { status: _options };
} else {
options = _options || {};
}
options.statusText = options.statusText || statusText(options.status);
options.headers = options.headers || {};
if (body) {
options.headers['Content-Type'] = 'application/vnd.api+json';
response = new Orbit.globals.Response(JSON.stringify(body), options);
} else {
response = new Orbit.globals.Response(options);
}
// console.log('jsonapiResponse', body, options, response.headers.get('Content-Type'));
if (timeout) {
return new Orbit.Promise((resolve, reject) => {
let timer = Orbit.globals.setTimeout(() => {
Orbit.globals.clearTimeout(timer);
resolve(response);
}, timeout);
});
} else {
return Orbit.Promise.resolve(response);
}
}
示例2: removeItem
removeItem(key: string): Promise<void> {
const fullKey: string = this.getFullKeyForItem(key);
Orbit.globals.localStorage.removeItem(fullKey);
return Orbit.Promise.resolve();
}
示例3: setItem
setItem(key: string, value: any): Promise<void> {
const fullKey: string = this.getFullKeyForItem(key);
Orbit.globals.localStorage.setItem(fullKey, JSON.stringify(value));
return Orbit.Promise.resolve();
}
示例4: getItem
getItem(key: string): Promise<any> {
const fullKey: string = this.getFullKeyForItem(key);
return Orbit.Promise.resolve(JSON.parse(Orbit.globals.localStorage.getItem(fullKey)));
}
示例5: upgrade
upgrade() {
assert.ok(false, 'upgrade should not be called');
return Orbit.Promise.resolve();
}