Expose complex reactive code as simple function based APIs

Rares Matei
InstructorRares Matei

Share this video with your friends

Send Tweet

Before we can test what we built, we need to go back to the empty Subjects that we used as placeholders to define when tasks start and end and actually connect them to our app. In addition, we will learn how to keep our external APIs simple, and avoid making our users understand RxJS.

dqunbp
dqunbp
~ a year ago

Why do we use switchMap? What is the difference if we used mergeMap, concatMap or exhaustMap? It seems to me that in this lesson was a key point, but its explanation was given very short and not detailed.

Cree
Cree
~ a year ago

Hey @dqunbp. I found a pretty good answer for you here! https://www.learnrxjs.io/learn-rxjs/operators/transformation/switchmap

The main difference between switchMap and other flattening operators is the canceling effect. On each emission, the previous inner observable (the result of the function you supplied) is canceled and the new observable is subscribed. You can remember this by the phrase switch to a new observable.

Rares Matei
Rares Mateiinstructor
~ a year ago

Why do we use switchMap? What is the difference if we used mergeMap, concatMap or exhaustMap? It seems to me that in this lesson was a key point, but its explanation was given very short and not detailed.

Thanks for the question, it's a very important one when learning RxJS!! I cannot recommend this Egghead course highly enough if you want to know more about the nuances of merging higher order observables: https://egghead.io/courses/use-higher-order-observables-in-rxjs-effectively

The key point in this lesson was to explore how you can use Subjects to link an internal, observable-based implementation to the outside codebase, which might not be using observables.