Member-only story

RxJS: Avoiding switchMap-Related Bugs

Nicholas Jamieson
6 min readMar 12, 2018

--

A while ago, Victor Savkin tweeted about a subtle bug that occurs through the misuse of switchMap in NgRx effects in Angular applications:

So what’s the bug?

Let’s use a shopping cart as an example and have a look at an effect — and an epic — that misuses switchMap and then consider some alternative operators.

Here’s an NgRx effect that misuses switchMap:

And here’s its equivalent redux-observable epic:

Our shopping cart lists the items the user intends to purchase and against each…

--

--

Nicholas Jamieson
Nicholas Jamieson

Written by Nicholas Jamieson

RxJS core team member; front-end developer; mentor; speaker; open-source contributor

Responses (9)