Using a Subject as an Event Bus

Share this video with your friends

Send Tweet

Every Subject is an Observer, meaning we can freely use the Observer methods next(), error(), complete() to manually send events to the Subject. This lesson will teach you how to use a Subject as an Event Bus through the Observer methods.

Viktor Soroka
Viktor Soroka
~ 7 years ago

What do you think Andre about the pattern Angular 2 recommend to use? I mean creating subject as private member of the service and then share the readonly observable from it. In this case we ensure that the service is the only place to emit new data.

fredrik
fredrik
~ 6 years ago

I use that pattern alot when needed. One benefit is when trying to listen to changes in network connections. i need some other services and components to be aware or be notified of that changings without implement some "new" instance of network components everytime, that mean using a central service for network and letting the rxjs subject to notified the subscriber when it has been changed.