convert an ordinary Observable into a connectable Observable
publish
publish
let letBind multicast publish publishLast publishValue
The above operators are available in the following packages:
rx.all.js
rx.all.compat.js
rx.binding.js
(requires either rx.js
or rx.compat.js
)rx.lite.js
rx.lite.compat.js
RxJS also has a multicast
operator which operates on an ordinary Observable, multicasts that Observable by means of a particular Subject that you specify, applies a transformative function to each emission, and then emits those transformed values as its own ordinary Observable sequence. Each subscription to this new Observable will trigger a new subscription to the underlying multicast Observable.
var subject = new Rx.Subject(); var source = Rx.Observable.range(0, 3) .multicast(subject); var observer = Rx.Observer.create( function (x) { console.log('Next: ' + x); }, function (err) { console.log('Error: ' + err); }, function () { console.log('Completed'); } ); var subscription = source.subscribe(observer); subject.subscribe(observer); var connected = source.connect(); subscription.dispose();
Next: 0 Next: 0 Next: 1 Next: 1 Next: 2 Next: 2 Completed
The multicast
operator is available in the following packages:
rx.all.js
rx.all.compat.js
rx.binding.js
(requires either rx.lite.js
or rx.compat.js
)rx.lite.js
rx.lite.compat.js
There is also a let
operator (the alias letBind
is available for browsers such as Internet Explorer before IE9 where “let
” is forbidden). It is similar to multicast
but does not multicast the underlying Observable through a Subject:
var obs = Rx.Observable.range(1, 3); var source = obs.let(function (o) { return o.concat(o); }); var subscription = source.subscribe( function (x) { console.log('Next: ' + x); }, function (err) { console.log('Error: ' + err); }, function () { console.log('Completed'); }); var subscription = source.subscribe( function (x) { console.log('Next: ' + x); }, function (err) { console.log('Error: ' + err); }, function () { console.log('Completed'); });
Next: 1 Next: 2 Next: 3 Next: 1 Next: 2 Next: 3 Completed
The let
(or letBind
) operator is available in the following packages:
rx.all.js
rx.all.compat.js
rx.experimental.js
It requires one of the following packages:
rx.js
rx.compat.js
rx.lite.js
rx.lite.compat.js
multicast multicastWithSelector publish publishLast publishValue
© ReactiveX contributors
Licensed under the Apache License 2.0.
http://reactivex.io/documentation/operators/publish.html