Reducing
Explore how to manipulate observable streams using RxJS operators like mergeMap and reduce. Understand creating inner observables to manage smaller event streams and efficiently combine them into single output values for responsive UI updates.
We'll cover the following...
Reducing streams
Now that the array of words is being flattened into separate events, we need some way of handling each of these smaller, “inner” events.
Effectively, two different streams of data are going on.
-
One is the same stream from before: every keystroke triggers an event containing the current content of the textbox.
-
The new stream is smaller (and finite), containing an event for every word in the textbox.
Mixing these two would be problematic: the view rendering function wouldn’t know whether a new word is a continuation of the inner stream, or represents the beginning of a new event from the original stream. There’s no way to know when to clear the page without adding obtuse hacks to your ...