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


TypeScript core.Promise類代碼示例

本文整理匯總了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);
  }
}
開發者ID:SmuliS,項目名稱:orbit.js,代碼行數:32,代碼來源:jsonapi.ts

示例2: removeItem

 removeItem(key: string): Promise<void> {
   const fullKey: string = this.getFullKeyForItem(key);
   Orbit.globals.localStorage.removeItem(fullKey);
   return Orbit.Promise.resolve();
 }
開發者ID:SmuliS,項目名稱:orbit.js,代碼行數:5,代碼來源:bucket.ts

示例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();
 }
開發者ID:SmuliS,項目名稱:orbit.js,代碼行數:5,代碼來源:bucket.ts

示例4: getItem

 getItem(key: string): Promise<any> {
   const fullKey: string = this.getFullKeyForItem(key);
   return Orbit.Promise.resolve(JSON.parse(Orbit.globals.localStorage.getItem(fullKey)));
 }
開發者ID:SmuliS,項目名稱:orbit.js,代碼行數:4,代碼來源:bucket.ts

示例5: upgrade

 upgrade() {
   assert.ok(false, 'upgrade should not be called');
   return Orbit.Promise.resolve();
 }
開發者ID:SmuliS,項目名稱:orbit.js,代碼行數:4,代碼來源:source-test.ts


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