TBD
There is also a shareReplay
operator, which keeps track of the number of
observers, and disconnects from the source Observable when that number drops to zero.
shareReplay
takes three optional parameters and returns an ordinary Observable:
bufferSize
window
scheduler
var interval = Rx.Observable.interval(1000); var source = interval .take(4) .doAction(function (x) { console.log('Side effect'); }); var published = source .shareReplay(3); published.subscribe(createObserver('SourceA')); published.subscribe(createObserver('SourceB')); // Creating a third subscription after the previous two subscriptions have // completed. Notice that no side effects result from this subscription, // because the notifications are cached and replayed. Rx.Observable .return(true) .delay(6000) .flatMap(published) .subscribe(createObserver('SourceC')); function createObserver(tag) { return Rx.Observer.create( function (x) { console.log('Next: ' + tag + x); }, function (err) { console.log('Error: ' + err); }, function () { console.log('Completed'); }); }
Side effect Next: SourceA0 Next: SourceB0 Side effect Next: SourceA1 Next: SourceB1 Side effect Next: SourceA2 Next: SourceB2 Side effect Next: SourceA3 Next: SourceB3 Completed Completed Next: SourceC1 Next: SourceC2 Next: SourceC3 Completed
replay
and shareReplay
are found in the following distributions:
rx.all.js
rx.all.compat.js
rx.binding.js
(requires rx.js
or rx.compat.js
)rx.lite.js
rx.lite.compat.js
TBD
TBD
TBD