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


TypeScript fromPromise.fromPromise函數代碼示例

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


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

示例1: toObservable

export function toObservable(r: any): Observable<any> {
  const obs = isPromise(r) ? fromPromise(r) : r;
  if (!(isObservable(obs))) {
    throw new Error(`Expected validator to return Promise or Observable.`);
  }
  return obs;
}
開發者ID:AnthonyPAlicea,項目名稱:angular,代碼行數:7,代碼來源:validators.ts

示例2: load

 load(parentInjector: Injector, path: string): Observable<LoadedRouterConfig> {
   return fromPromise(this.loader.load(path).then(r => {
     const ref = r.create(parentInjector);
     return new LoadedRouterConfig(
         ref.injector.get(ROUTES), ref.injector, ref.componentFactoryResolver);
   }));
 }
開發者ID:AngularLovers,項目名稱:angular,代碼行數:7,代碼來源:router_config_loader.ts

示例3: of

 return mergeMap.call(wrapIntoObservable(loadChildren()), (t: any) => {
   if (t instanceof NgModuleFactory) {
     return of (t);
   } else {
     return fromPromise(this.compiler.compileModuleAsync(t));
   }
 });
開發者ID:acramatte,項目名稱:angular,代碼行數:7,代碼來源:router_config_loader.ts

示例4: getArticle

 getArticle(): Observable<Article> {
   const article = new Article();
   article.title = '破狼簡介';
   article.categories = ['破狼', '簡介'];
   article.layout = 'post';
   article.html = require('./polang.html');
   return fromPromise(Promise.resolve(article));
 }
開發者ID:VINOlive,項目名稱:rebirth,代碼行數:8,代碼來源:about.service.ts

示例5: return

const transformPromiseToCancellableObservable = (
  promiseFn: () => Promise<any>
) => {
  return (
    fromPromise(promiseFn())
      /** cancel previous subscribed request in favor of the new one */
      .switchMap(() => promiseFn())
  );
};
開發者ID:linode,項目名稱:manager,代碼行數:9,代碼來源:promiseToObservable.ts

示例6: if

export function wrapIntoObservable<T>(value: T | Promise<T>| Observable<T>): Observable<T> {
  if (value instanceof Observable) {
    return value;
  } else if (value instanceof Promise) {
    return fromPromise(value);
  } else {
    return of (value);
  }
}
開發者ID:JanStureNielsen,項目名稱:angular,代碼行數:9,代碼來源:collection.ts

示例7: fromPromise

export function wrapIntoObservable<T>(value: T | NgModuleFactory<T>| Promise<T>| Observable<T>):
    Observable<T> {
  if (value instanceof Observable) {
    return value;
  }

  if (value instanceof Promise) {
    return fromPromise(value);
  }

  return of (value);
}
開發者ID:JSMike,項目名稱:angular,代碼行數:12,代碼來源:collection.ts

示例8: loadModuleFactory

 private loadModuleFactory(loadChildren: LoadChildren): Observable<NgModuleFactory<any>> {
   if (typeof loadChildren === 'string') {
     return fromPromise(this.loader.load(loadChildren));
   } else {
     return mergeMap.call(wrapIntoObservable(loadChildren()), (t: any) => {
       if (t instanceof NgModuleFactory) {
         return of (t);
       } else {
         return fromPromise(this.compiler.compileModuleAsync(t));
       }
     });
   }
 }
開發者ID:acramatte,項目名稱:angular,代碼行數:13,代碼來源:router_config_loader.ts

示例9: fromPromise

export function wrapIntoObservable<T>(value: T | NgModuleFactory<T>| Promise<T>| Observable<T>):
    Observable<T> {
  if (isObservable(value)) {
    return value;
  }

  if (isPromise(value)) {
    // Use `Promise.resolve()` to wrap promise-like instances.
    // Required ie when a Resolver returns a AngularJS `$q` promise to correctly trigger the
    // change detection.
    return fromPromise(Promise.resolve(value));
  }

  return of (value);
}
開發者ID:cooperka,項目名稱:angular,代碼行數:15,代碼來源:collection.ts

示例10: handle

    handle(req: HttpRequest<any>): Observable<HttpEvent<any>> {
        return fromPromise(this.platform.ready()).pipe(
            switchMap(() => {
                /**
                 * Native HTTP Cordova plugin doesn't like local requests
                 */
                const isExternalRequest = checkExternalRequest(req);

                if (
                    isExternalRequest &&
                    checkAvailability('cordova.plugin.http') === true
                ) {
                    return this.cordovaHttpBackend.handle(req);
                } else {
                    return this.fallbackBackend.handle(req);
                }
            }),
        );
    }
開發者ID:achubutkin,項目名稱:ionic-native-http-connection-backend,代碼行數:19,代碼來源:native-http-fallback.ts


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