待定
还存在一个 share
操作符,它等同于将 publish
和 refCount
操作符按顺序应用于 Observable。
share()
还存在一个 share
操作符,它等同于将 publish
和 refCount
操作符按顺序应用于 Observable。
share()
还存在一个 share
操作符,它等同于将 publish
和 refCount
操作符按顺序应用于 Observable。一个名为 shareValue
的变体将一个项目作为参数,它将在开始从源 Observable 发射项目之前将其发射给任何订阅者。
var interval = Rx.Observable.interval(1000); var source = interval .take(2) .do( function (x) { console.log('Side effect'); }); var published = source.share(); // When the number of observers subscribed to published observable goes from // 0 to 1, we connect to the underlying observable sequence. published.subscribe(createObserver('SourceA')); // When the second subscriber is added, no additional subscriptions are added to the // underlying observable sequence. As a result the operations that result in side // effects are not repeated per subscriber. published.subscribe(createObserver('SourceB')); 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 Completed
share
和 shareValue
存在于以下发行版中
rx.all.js
rx.all.compat.js
rx.binding.js
(需要 rx.js
或 rx.compat.js
)rx.lite.js
rx.lite.compat.js
待定