Created
February 28, 2020 06:57
-
-
Save b2977053/5d91fcc26e80b14629b7775bc2c52ffd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Operators - withLatestFrom | |
var main = Rx.Observable.from([1,2,3,4,5]).zip(Rx.Observable.interval(500), (x, y) => x); | |
var some = Rx.Observable.from([0,1,0,0,0,1]).zip(Rx.Observable.interval(300), (x, y) => x); | |
var example = main.withLatestFrom(some, (x, y) => { | |
return y === 1 ? x*10 : x; | |
}); | |
example.subscribe({ | |
next: (value) => { console.log(value); }, | |
error: (err) => { console.log('Error: ' + err); }, | |
complete: () => { console.log('complete'); } | |
}); | |
//1 | |
//2 | |
//3 | |
//40 | |
//50 | |
//complete | |
/*解釋: | |
在 withLatestFrom observable 有主從關係 | |
從<--至少執行一次,主<--才會開始執行 | |
之後互不等待,直到主 observable 丟出 complete。 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment