RxJS: Calling publish with a Selector

Nicholas Jamieson
4 min readApr 2, 2019
Photo by Beatriz Pérez Moya on Unsplash

The publish and publishReplay operators can be called in two ways: either with or without a selector function. Let’s look at the differences and at why you should almost always pass a selector.

Without a selector

When publish is called without a selector, it returns a particular type of observable: a ConnectableObservable.

--

--

Nicholas Jamieson

RxJS core team member; front-end developer; mentor; speaker; open-source contributor