Exploring Subjects
Subjects are special types of Observables. While plain observables are Unicast, Subjects are Multicast. They allow Multicasting values to all the subscribers. You can regard Subjects as Observers and Observables at the same time:
- You can subscribe to Subjects to get emitted values by the Producer (that's why they act as Observables).
- You can send values, errors, and complete the stream using the
next
,error
, andcomplete
methods (that's why they act as an observer):
Remember that the Observer interface has the next
, error
and complete
methods to, respectively, send values, error out, and complete an execution:
const observer = { next: x => console.log('Observer got a next value: ' + x), error...