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


TypeScript Observable.defer方法代碼示例

本文整理匯總了TypeScript中rxjs.Observable.defer方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.defer方法的具體用法?TypeScript Observable.defer怎麽用?TypeScript Observable.defer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rxjs.Observable的用法示例。


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

示例1: loadWithFetch

export function loadWithFetch(url) {
        return Observable.defer(() => {
            return Observable.fromPromise(fetch(url).then(r => {
                if (r.status === 200) {
                    return r.json();
                } else {
                    return Promise.reject(r);
                }
            }))
        }).retryWhen(retryStrategy());
}
開發者ID:wormster,項目名稱:rxjs-gettingstarted,代碼行數:11,代碼來源:loader.ts

示例2: loadWithFetch

export function loadWithFetch(url: string) {
           
    return Observable.defer(() => 
    {
        return Observable
            .fromPromise(fetch(url).then(r => {
                if(r.status === 200) {
                    return r.json();
                } else {
                    return Promise.reject(r);
                }
            }));               
    }).retryWhen(retryStrategy({attempts: 4, delay:1000}));
}
開發者ID:OdeToCode,項目名稱:AtTheMovies,代碼行數:14,代碼來源:loader.ts

示例3: initialize

  public static initialize(): void {
    this.accounts$ = Observable.defer(() => {
      const promise = API.one('credentials')
        .useCache()
        .withParams({ expand: true })
        .get();
      return Observable.fromPromise<IAccountDetails[]>(promise);
    })
      .publishReplay(1)
      .refCount();

    this.providers$ = AccountService.accounts$.map((accounts: IAccountDetails[]) => {
      const providersFromAccounts: string[] = uniq(accounts.map(account => account.type));
      return intersection(providersFromAccounts, CloudProviderRegistry.listRegisteredProviders());
    });
  }
開發者ID:emjburns,項目名稱:deck,代碼行數:16,代碼來源:AccountService.ts

示例4: waterfall

  /**
   * Make Async to Sync (like a waterfall)
   * 
   * !!! NOT RECOMMENDED !!!. Do if necessary.
   * 
   * @author mattpodwysocki
   * @see https://github.com/Reactive-Extensions/RxJS/issues/73#issuecomment-30093431
   */
  public static waterfall(series: ((fn?: any) => Observable<any>)[]): Observable<any> {
    // tslint:disable-next-line:only-arrow-functions
    return Observable.defer(function () {
      let acc = series[0]();
      for (let i = 1, len = series.length; i < len; i++) {
        // tslint:disable-next-line:only-arrow-functions
        (function (func) {
          // tslint:disable-next-line:only-arrow-functions
          acc = acc.flatMap(function (x) {
            return func(x);
          });
        }(series[i]));
      }

      return acc;
    });
  }
開發者ID:PoompisekK,項目名稱:myWork,代碼行數:25,代碼來源:rxjs.util.ts

示例5: execAndWaitForOutputToMatch

export function execAndWaitForOutputToMatch(cmd: string, args: string[], match: RegExp) {
  if (cmd === 'ng' && args[0] === 'serve') {
    // Accept matches up to 20 times after the initial match.
    // Useful because the Webpack watcher can rebuild a few times due to files changes that
    // happened just before the build (e.g. `git clean`).
    // This seems to be due to host file system differences, see
    // https://nodejs.org/docs/latest/api/fs.html#fs_caveats
    return Observable.fromPromise(_exec({ waitForMatch: match }, cmd, args))
      .concat(
        Observable.defer(() =>
          Observable.fromPromise(waitForAnyProcessOutputToMatch(match, 2500))
            .repeat(20)
            .catch(_x => Observable.empty())
        )
      )
      .takeLast(1)
      .toPromise();
  } else {
    return _exec({ waitForMatch: match }, cmd, args);
  }
}
開發者ID:deebloo,項目名稱:angular-cli,代碼行數:21,代碼來源:process.ts


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