分享在RxJS 5中的重播 [英] shareReplay in RxJS 5

查看:96
本文介绍了分享在RxJS 5中的重播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据RxJS 5 MIGRATION.md 它看起来像 shareReplay()已被删除。

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


  1. 为什么?

  2. .publishReplay(1).refCount( )忠实地复制行为?基本上我需要将最新的单个数据集重播给任何新订阅者。

  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.


推荐答案

简短回答:
引用Blesh爵士:

The short answer : Quoting Sir Blesh :


RxJS 5试图解决的问题是ConnectableObservables
应该是reconnectable和 refCount 应该返回一个可观察的
,直到订阅为止,然后才热,直到所有订阅
结束,然后再冷。

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.

问题在于完成后主题的行为会阻止可完成时重新连接可连接的observable。

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

答案很长:
https://github.com/ReactiveX/RxJS/issues/453

当前的API似乎是两个愿景之间妥协的结果。重新连接问题。如果有关人员可以对手头的问题进行总结,那将是很好的。我的理解是 .publishReplay(1).refCount()应保留旧的行为,即当您的订阅者数量达到0时,源被断开,并且您不能重播它。但是不要相信我的话,测试它,我在讨论后迷路了。

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.

这篇关于分享在RxJS 5中的重播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆