Control the Output of Values with RxJS Operator withLatestFrom

Share this video with your friends

Send Tweet

Operator combineLatest is not the only AND-style combinator. In this lesson we will explore withLatestFrom, another AND-style combination operator, and how it works essentially as map() operator, with some combination properties.

🚨 Since we are importing interval from RxJS, we don't need to preface our Observables with Rx.Observable. You can no longer .{operator}, you need to .pipe({operator}) instead. To link together multiple Observables and Operators, the method is a bit different. You call zip first, then list your Observables, your functions, then pipe your Operators.

ganqqwerty
ganqqwerty
~ 7 years ago

Can you come up with a more of a real-world example for withLatestFrom operator?

fredrik
fredrik
~ 6 years ago

Can you come up with a more of a real-world example for withLatestFrom operator? Not sure if this is a "full explanation" of a real-world example. But somethings tells me that You can have one stream that tells what "states" you are in for the moment, and another one where you where before that. If we have a transaction from one particular state to another would bring a certain events. Now this is helpful to use when creating a FSM (finite state machine) for instance. Its a little bit more complicated, but still that is how I would interpreted it. There are for certain other example situations when you actually needs it. But for me its helpful to ask this question "when in the code do I need a "mechanism" where I need to remember the latest value/state in order to operate the new operation ?" It could be useful when also we have a stream of values and suddenly the "state" (again state!) changed which change everything how the other values should be handled.