What you’ll learn
- Rxjs Basics
- Rxjs Subjects
- Rxjs Operators
- Rxjs Subscription
- Understanding Rxjs in more depth
- Creational, Join, Transformational Operators
- Error Handling in Rxjs
Description
RxJS is a library for composing asynchronous and event-based programs by using observable sequences. It provides one core type, the Observable, satellite types (Observer, Schedulers, Subjects) and operators inspired by Array#extras (map, filter, reduce, every, etc) to allow handling asynchronous events as collections.
Think of RxJS as Lodash for events.
ReactiveX combines the Observer pattern with the Iterator pattern and functional programming with collections to fill the need for an ideal way of managing sequences of events.
The essential concepts in RxJS which solve async event management are:
- Observable: represents the idea of an invokable collection of future values or events.
- Observer: is a collection of callbacks that knows how to listen to values delivered by the Observable.
- Subscription: represents the execution of an Observable, is primarily useful for cancelling the execution.
- Operators: are pure functions that enable a functional programming style of dealing with collections with operations like map, filter, concat, reduce, etc.
- Subject: is the equivalent to an EventEmitter, and the only way of multicasting a value or event to multiple Observers.
- Schedulers: are centralized dispatchers to control concurrency, allowing us to coordinate when computation happens on e.g. setTimeout or requestAnimationFrame or others.
Conceptually promises are a subset of observables. Promise is a value that will resolve asynchronously. Most typical example is http requests. Observables deal with sequence of asynchronous events. These events could be mouse positions, clicks, user input etc. So one could say observables are richer and more complex abstraction for handling asynchronicity.
So, calling observables as promises + helper methods is an oversimplification. The answer to your question depends on whether you need to deal with sequence of events or if you can live with “simple” synchronicity.