最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - shareReplay in RxJS 5 - Stack Overflow

programmeradmin2浏览0评论

According to the RxJS 5 MIGRATION.md it looks like shareReplay() been removed.

  1. Why?
  2. Does .publishReplay(1).refCount() faithfully replicate the behaviour? Basically I need to replay the single most recent data set to any new subscribers.

According to the RxJS 5 MIGRATION.md it looks like shareReplay() been removed.

  1. Why?
  2. Does .publishReplay(1).refCount() faithfully replicate the behaviour? Basically I need to replay the single most recent data set to any new subscribers.
Share Improve this question edited Nov 18, 2016 at 5:11 user3743222 18.7k5 gold badges73 silver badges75 bronze badges asked Feb 6, 2016 at 21:48 Philip BulleyPhilip Bulley 9,4143 gold badges35 silver badges46 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 14

Happy news, shareReplay() is back in RxJS 5.4.0: https://github.com/ReactiveX/rxjs/blob/892700dd4f5d5e5f9ae9276ede32208f4390c5e9/CHANGELOG.md#540-2017-05-09

The short answer : Quoting Sir Blesh :

The problem RxJS 5 is trying to solve is that ConnectableObservables should be "reconnectable", and refCount should return an observable that is cold until subscribed to, then hot until all subscriptions have ended, then cold again.

The issue is that of the behaviour of subjects after completion which prevents a connectable observable to be reconnected when completed.

The long answer : https://github.com/ReactiveX/RxJS/issues/453

The current API appears to be the result of a compromise between two visions of the reconnection issue. It would be great if those involved could do a summary of the issues at hand. My understanding is that .publishReplay(1).refCount() should keep the old behaviour, that is that when your number of subscribers reaches 0, the source is disconnected, and you can't replay it. But don't take my word for it, test it, I got lost following the discussion.

发布评论

评论列表(0)

  1. 暂无评论