Exploring RxJS subjects
Subjects are special types of Observables. While plain Observables are unicast, subjects are multicast, allowing values to be broadcast to all subscribers.
You can consider subjects as observers and Observables at the same time:
- You can subscribe to subjects to get values emitted by the producer (that’s why they act as Observables):
Figure 9.3 – An RxJS subject
- You can send values, errors, and completes by using the
next,error, andcompletemethods that are available in theObserverinterface (that’s why they act as observers):const observer = { next: x => console.log('Observer got a next value: ' + x), error: err => console.error('Observer got an error: ...