【发布时间】:2016-09-17 18:44:08
【问题描述】:
import {Observable} from '@reactivex/rxjs'
// This is a fake API polling, this data is in reality coming from
// the server
const fakePoll$ = Observable.from([
{
status: 'initialized',
data: {...},
},
{
status: 'progress',
data: {...},
},
{
status: 'progress',
data: {...},
},
{
status: 'progress',
data: {...},
},
{
status: 'completed',
data: {...},
},
...
{
status: 'completed',
data: {...},
},
])
fakePoll$
.takeWhile(x => x.status != 'completed')
.subscribe(x => console.log(x))
这个sn-p返回所有的进度和初始化状态:
initialized
progress
progress
progress
但我需要完成第一个也像 takeWhile 但包容性。
【问题讨论】:
-
我相信你在使用 api 时必须使用重复,假设它是一个承诺返回调用。我在 plnkr.co/edit/6fBPFCus3HhZmCFBXFKq 中这样做了。希望这会有所帮助。
-
另外请参考我的问题,我在其中尝试了 3 种不同的方式。请随意发表评论。 stackoverflow.com/questions/44248530/…
标签: javascript rxjs rxjs5