当前位置: 首页>>代码示例>>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;未经允许,请勿转载。