Member-only story
RxJS: Understanding Expand
RxJS has a lot of operators. Lots and lots of them.
It takes time to learn what they all do and how they can be used. Some operators are straightforward; others, less so. One operator that developers often find confusing is expand
.
It doesn’t have to be confusing, though. It’s just like a delay pedal.
So what’s a delay pedal?
A delay pedal is an electronic effect that simulates echoes. You plug an instrument into it, plug it into the amp, stomp on it to switch it on and then cool things happen when you make some noise.
The input signal received by the pedal is passed straight through, as the point of the effect is to add echoes — not to modify the input signal itself. The pedal then records the signal and replays it after a delay — simulating an echo.
A typical delay pedal will have a feedback control and turning it up will see the delayed signal fed back into the effect, as if it came from the source. So a delay will be applied to the delayed signal, effecting a series of ever-quieter echoes.
So how’s expand like a pedal?
The key to understanding how expand
works is realising that — just like a pedal — the signal that’s received from the source passes straight through. That is, the…