LiveLoveApp logo

Multicasting Operators

Goals

  • Learn to use multicasted Observables.
  • Learn to use the connectable() function.
  • Learn to use connect() and share() operators.

Deprecations

As of version 7.0 of RxJS, the following have been deprecated:

  • ConnectableObservable
  • multicast
  • publish
  • publishBehavior
  • publishLast
  • publishReplay
  • refCount

The goal of the deprecations is to reduce the surface of the API.

Previously, the multicast() operator was used to create a ConnectableObservable instance. Similar to the connectable() function above, the resulting ConnectableObservable had to be connected to the provided Subject through the use of a connect() method.

Further, the publish() operator was a shorthand operator to the multicast() operator where providing the connecting Subject instance was not necessary.

Next up, the refCount() operator is also no longer necessary with these deprecations. The refCount() operator previously enabled automatic internal reference counting of the number of Observers. Internally, when the number of Observers was incremented from 0 to 1, the operator would internally invoke the connect() method on the ConnectableObservable. Likewise, when the number of Observers was decremented from 1 to 0, the operator would internally invoke the unsubscribe() method on the Subscribtion within the closure.

Finally, it should be noted that with these deprecations the share() operator has been refactored. Previously, the share() operator was a shorthand operator for using the multicast() with the refCount() operator. We'll learn more about the share()operator shortly.

Deprecated content

If your RxJS dependency is < 7.0, you can learn about the multicast(), publish(), and refCount() operators.