Operator Combinelatest is isn't the only And-style combinator. In this lesson we'll explore Withlatestfrom, another and-style combination operator, and how it works essentially as map () operator, with some combination properties.
varFoo = Rx.Observable.interval (400). zip (Rx.Observable.of (' h ', ' e ', ' l ', ' l ', ' O '), (__, x) = =x);varBar = Rx.Observable.interval (300). zip (Rx.Observable.of (0,1,1,0,0,1,0,0,1), (__, x) = =x);/*----h----e----l----l----o| (foo)--0--1--1--0--0--1--0--0--1| (bar) Withlatestfrom ((c,n) = n = = 1? C.touppercase (): C.tolowercase ())----h----E----l----l----o|*/varCombined = Foo.withlatestfrom (bar, (c,n) and n = = = 1?c.touppercase (): C.tolowercase ()); Combined.subscribe (function(x) {Console.log (' next ' +x); }, function(ERR) {console.log (' error ' +err); }, function() {console.log (' done ')); },); /*"Next H" "Next E" "Next L" "Next L" "Next O" "Done"*/
The Foo is the main stream, when Foo emit each time, it'll take the latest value from bar, if the value from bar is 1, t Hen convert foo to upcase string, otherwise lower case string.
[RxJS] Combination Operator:withlatestfrom