简体   繁体   English

分享在RxJS 5中的重播

[英]shareReplay in RxJS 5

According to the RxJS 5 MIGRATION.md it looks like shareReplay() been removed. 根据RxJS 5 MIGRATION.md ,看起来像shareReplay()已被删除。

  1. Why? 为什么?
  2. Does .publishReplay(1).refCount() faithfully replicate the behaviour? .publishReplay(1).refCount()忠实地复制了这种行为? Basically I need to replay the single most recent data set to any new subscribers. 基本上我需要将最新的单个数据集重播给任何新订阅者。

The short answer : Quoting Sir Blesh : 简短的回答:引用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. RxJS 5试图解决的问题是ConnectableObservables应该是“可重新连接的”,并且refCount应该返回一个冷却直到订阅的observable,然后热,直到所有订阅都结束,然后再冷。

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 答案很长: 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. 当前的API似乎是重新连接问题的两个愿景之间妥协的结果。 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. 我的理解是.publishReplay(1).refCount()应保留旧的行为,即当您的订阅者数量达到0时,源被断开,您无法重放它。 But don't take my word for it, test it, I got lost following the discussion. 但是不要相信我的话,测试它,我在讨论后迷路了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM