Implement RxJS `mergeMap` through inner Observables to Subscribe and Pass Values Through

InstructorJohn Lindquist

Share this video with your friends

Send Tweet

Understanding sources and subscribers makes it much easier to understand what's going on with mergeMap under the hood. Where a typical operator invokes destination.next directly, mergeMap wraps destination.next inside of a new source/subscriber combo so there's an "outer" next and an "inner" next.

J. Matthew
~ 5 years ago

mergeMap makes sense now!

I see how, whereas map directly transforms a given value in the stream, mergeMap creates a new stream (Observable) from that value, and then merges the output from the new stream into the old stream (or replaces the old stream with the new, depending on how you want to look at it).

delay is obviously a contrived example (albeit an effective one), but it's easy to see how critical this would be for practical asynchronous actions, like HTTP requests.