RxJS share() Multicasting OperatorRxJS share() operator is a multicasting operator which returns a new observable that shares or multicasts the original observable. As long as there is at least one subscriber, this observable will be subscribed and emitting data. When all subscribers have unsubscribed, it will unsubscribe from the source observable. Because the observable is multicasting, it makes the stream hot. This is an alias for multicast(() => new Subject()), refCount(). Syntax:Following is the syntax of the RxJS share() multicasting operator: Or Parameter ExplanationThere is no such parameter that we have to explain. Return valueThe RxJS share() operator returns observable causes the source observable to emit items to its observers when the connection is established. Let us see some examples of the RxJS share() operator to understand it clearly. Example 1Output: After executing the above example, you will see the following result: Example 2 (Multiple subscribers sharing source)Output: After executing the above example, you will see the following result:
Next TopicRxJS Operators
|