RxJS allows us to manage and manipulate streams of data.
RxJS is the JS implementation of Reactive X, an API for asynchronous programming with observable streams.
It implements ideas from the Observer pattern, the Iterator pattern and functional programming.
In summary, a tool to:
- Create event streams
- Combine streams
- Subscribe to the events of the streams
Key aspects:
- Functional. Avoid stateful programs, using functions.
- Operators. Set of operators that reduce lines of code.
- Better async error handling.
- Concurrency.
It's used in Angular extensively inside the core API and third-party libraries, but it's not mandatory. There are many implementations of it in different languages and frameworks.
- Observable. The object that listen to changes in the stream of data. Something that can be observed.
- Observer. Represents the collection of listeners that are subscribed to the stream.
- Subscription. The execution of an observable and observer.
- Operators. Pure functions that manipulate the stream.
- Subject. The stream emitter.
Images that help us understand how a stream of data is manipulated. It has an input timeline with the original stream, middle operators that perform operations on it, and the output stream.
The catch operator: