Implement RxJS `switchMap` by Canceling Inner Subscriptions as Values are Passed Through

InstructorJohn Lindquist

Share this video with your friends

Send Tweet

switchMap is mergeMap that checks for an "inner" subscription. If the "inner" subscription exists, switchMap unsubscribes from that "inner" subscription which effectively "cancels" any pending pushes.

J. Matthew
~ 5 years ago

Great explanation of switchMap!

My default Webpack build process breaks when I try to declare innerSubscription above the constructor. Seems like something is missing to handle that; not sure what or why. However, it's not necessary to declare the property. It is sufficient to reference and set this.innerSubscription inside _next. In fact, we're already doing that (working with an undeclared property) with this.fn.