本文整理汇总了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;
}
示例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);
}));
}
示例3: of
return mergeMap.call(wrapIntoObservable(loadChildren()), (t: any) => {
if (t instanceof NgModuleFactory) {
return of (t);
} else {
return fromPromise(this.compiler.compileModuleAsync(t));
}
});
示例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));
}
示例5: return
const transformPromiseToCancellableObservable = (
promiseFn: () => Promise<any>
) => {
return (
fromPromise(promiseFn())
/** cancel previous subscribed request in favor of the new one */
.switchMap(() => promiseFn())
);
};
示例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);
}
}
示例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);
}
示例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));
}
});
}
}
示例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);
}
示例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);
}
}),
);
}