RxJS5 - skipWhile 但在跳过时保持值?
RxJS5 - skipWhile but keep values while skipping?
我有一个流需要在 bool 为真时跳过。
但是,当该 bool 设置回 false 时,我需要应用它跳过时错过的最后一个流值。
Rx.Observable
.interval(1000)
.skipWhile(val => true|false)<---when back to false, get last missed value?
.subscribe(val => console.log(val));
使用多播共享起始值和其余值。 pairwise to pairt prev and next value and concat to combine start and the rest.
Rx.Observable.interval(500)
.multicast(new Rx.Subject(), shared => {
let start$ = shared
.pairwise()
.skipWhile((x)=>x[1]<5) // this is the condition to skip
.first()
.switchMap(el=>Rx.Observable.concat(Rx.Observable.of(el[0]),
Rx.Observable.of(el[1])));
return Rx.Observable.concat(start$, shared);
}).subscribe(x=>console.log(x));
我有一个流需要在 bool 为真时跳过。
但是,当该 bool 设置回 false 时,我需要应用它跳过时错过的最后一个流值。
Rx.Observable
.interval(1000)
.skipWhile(val => true|false)<---when back to false, get last missed value?
.subscribe(val => console.log(val));
使用多播共享起始值和其余值。 pairwise to pairt prev and next value and concat to combine start and the rest.
Rx.Observable.interval(500)
.multicast(new Rx.Subject(), shared => {
let start$ = shared
.pairwise()
.skipWhile((x)=>x[1]<5) // this is the condition to skip
.first()
.switchMap(el=>Rx.Observable.concat(Rx.Observable.of(el[0]),
Rx.Observable.of(el[1])));
return Rx.Observable.concat(start$, shared);
}).subscribe(x=>console.log(x));