Understand RxJS Subjects

Click for: original source

If you are an Angular developer there is no way you missed RxJS Observables but you might be less familiar with Subjects. Even though they are less frequent than simple Observables, they are extremely useful. Understanding them will help you write better, cleaner reactive code. By Dornhoth.

Observables are lazy Push collections of multiple values. A Subject is like an Observable, but can multicast to many Observers.

The article describes:

  • Observables
  • Subjects
  • BehaviorSubjects
  • ReplaySubjects
  • AsyncSubjects

Intuitively, you can think of Observables as objects that emit streams of values. You need to subscribe to the Observable for it to start counting, the same way you need to call a function for it to be computed. Subjects are Observables. Nice intro into reactive programming!

[Read More]

Tags web-development react javascript