The docs for .share()
state: 'Returns a new Observable that multicasts (shares) the original Observable.'.
This sounds like share()
is a lovely simple method that'll make your life easier. However share()
is really a trap, for if you have the hubris to use .share()
the angry complexity bees that live inside RxJS will swarm out and sting you in the eye (in a rate-limited fashion).
Let's see why. Our goal is to take a cold observable, take only the first item from it, do something to it, and share the resulting observable between 2 subscribers. They should both share the values from our new observable. Easy huh?
{
const coldObservable = Rx.Observable.create(function(observer) {
console.log('observable created')