Chapter 5
Multiplexing Observables

So far you’ve learned that a new subscriber creates an entirely new observable stream, including rerunning the constructor. The term for this kind of observable is a cold observable, and it’s the default in RxJS. However, sometimes you may want to create only a single source for an observable stream (such as the websocket example in Chapter 4, Advanced Async). You don’t want to create a pile of new websocket connections if all of a page’s components want to listen in on the stream. In this case, you need a hot observable.

A hot observable contains a single stream that every subscriber listens in on (this is called multicasting). These hot observables can be created by piping through publish on a regular observable or by creating a subject, which are hot by default. This sounds complicated, but if you take it step-by-step, you’ll do just fine. You’ll learn these concepts by building this chapter’s big project: a chat system. Time to dive in!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.60.249