The RxJS library
As mentioned previously, Angular comes with a peer dependency on RxJS, the JavaScript flavor of the ReactiveX library that allows us to create observables out of a large variety of scenarios, including the following:
- Interaction events
- Promises
- Callback functions
- Events
In this sense, reactive programming does not aim to replace asynchronous patterns, such as promises or callbacks. All the way around, it can leverage them as well to create observable sequences.
RxJS has built-in support for a wide range of composable operators to transform, filter, and combine the resulting event streams. Its API provides convenient methods for observers to subscribe to these streams so that our components can respond accordingly to state changes or input interaction. Let's see some of these operators in action in the following sections.
Creating observables
We have already learned how to create an observable from a DOM event using the fromEvent
operator....