4 Laws of RxJS Observables — figure 1

Grasping this concept is essential! Many resources online may be inaccurate.

Compact yet dense explanation.

🏆 Here are 4 Laws of Observables 🏆

Law 1

• Every Observable is lazy—this holds universally, with no exceptions.

Law 2

• Observables fall into two categories: cold ones, which provide a distinct execution context per subscription, operating unicast.

• Or hot ones, which share a single execution context across multiple subscribers, operating multicast.

Law 3

• A Subject acts as both an Observable and an Observer.

• The Observable side is multicast, yet it remains lazy, executing only upon the arrival of the first subscriber.

• The Observer side is eagerly instantiated, enabling the use of .next() to push data through the Subject;

• The Observer side does not signal that the Observable's execution context is active prior to the initial subscription.

Law 4

• Some Subjects maintain state, such as BehaviorSubject or ReplySubject, by expanding the Observer role.

• They incorporate capabilities to store 1..n previous states, which the Observable part then multicasts to prospective subscribers.


Does this make you consider RxJS a challenging topic (pun intended :D)?

The Angular Team has hinted at potentially making RxJS non-mandatory in the future.

Should RxJS remain a requirement?
Or is making it optional the right call?