RxJS River — Angular

Pick the RxJS operator that routes ojek orders down Mbak Galuh's river: map, switchMap, retry. 16 levels, played right in the browser with nothing to install.

What you learn in this game

An Observable is a stream of values over time: here, the river carrying orders. pipe(...) puts rules on the post, and each rule is an RxJS operator that takes one stream and returns a new one. This world is a marble diagram: the upper river is the stream going in, the lower river the stream coming out, and the distance from the left is time. The river's clock runs on real RxJS 7.8.2's TestScheduler, in virtual milliseconds: a whole day on the river takes an instant.

Time operators use a clock. On this river the clock is virtual: debounceTime, throttleTime, delay and timer run on the TestScheduler, so 300 ms pass without waiting, and the result is always the same. For a search box what matters is the pause: when someone stops typing.

When each value calls something that is also an Observable (an HTTP request, a motorbike taxi trip), four operators flatten it, and they differ in one thing only: what happens when a new value comes while the old one is still running. mergeMap runs them all at once. concatMap queues. switchMap cancels the old one. exhaustMap ignores the new one.

Cold or hot? A cold Observable starts its work for each subscriber: two subscribers, two calls. A hot one is already running, and a subscriber only hears it from the moment they arrive. The river has been hot all along: orders float down whether anyone watches or not. The kitchen is cold.