switchMap
is an operator in the rxjs
library for reactive programming in JavaScript. It is used to flatten higher order observables into a single observable.
Here's an example usage of switchMap
:
473 chars15 lines
In this example, switchMap
is used to switch to a new observable of intervals every time the button is clicked, and the resulting values are logged to the console.
Note that switchMap
cancels any previous inner observables when a new outer observable emits, which can be useful for scenarios where you only want to handle the most recent events.
gistlibby LogSnag