本文整理汇总了TypeScript中@reactivex/rxjs.Observable.fromPromise方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.fromPromise方法的具体用法?TypeScript Observable.fromPromise怎么用?TypeScript Observable.fromPromise使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@reactivex/rxjs.Observable
的用法示例。
在下文中一共展示了Observable.fromPromise方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: init
function init(state_: string, current_: number) {
console.log('new');
return Observable.fromPromise(new Promise((resolve, reject) => {
setTimeout(() => {
resolve('init success');
}, 2000);
}));
}
示例2: login
/**
* login on Relution
* @link [relution-sdk](https://github.com/relution-io/relution-sdk)
*/
login(serverModel: ServerModelRc, force?: boolean): Observable<{ user: Relution.security.User }> {
Relution.init({
serverUrl: serverModel.serverUrl,
application: 'studio'
});
if (!force) {
let currentUser: Relution.security.User = Relution.security.getCurrentUser();
if (currentUser) {
return Observable.create((observer: any) => {
observer.next({
user: currentUser
});
observer.complete();
});
}
}
return Observable.fromPromise(Relution.web.login({
userName: serverModel.userName,
password: serverModel.password
}, serverModel));
}
示例3: Promise
import { Observable } from '@reactivex/rxjs';
/*
var clicks = Observable.interval(1000);
var interval = Observable.interval(200);
var buffered = interval.buffer(clicks);
buffered.subscribe(x => console.log(x));
*/
/*
var clicks = Observable.interval(200);
var buffered = clicks.bufferWhen(() =>
Observable.interval(1000)
);
buffered.subscribe(x => console.log(x));
*/
let update$ = Observable.interval(200);
let init$ = Observable.fromPromise(new Promise((resolve, reject) => resolve('hi')));
update$.bufferWhen(() => init$)
.subscribe(x => console.log(x));
示例4:
.flatMap(function(requestUrl) {
return Rx.Observable.fromPromise(fetch(requestUrl)
.then(function(response) {
return response.json();
}));
})