RxJS 5 中的共享重放 [英] shareReplay in RxJS 5

查看:23
本文介绍了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.

推荐答案

简短的回答:引用布莱什爵士的话:

The short answer : Quoting Sir Blesh :

RxJS 5 试图解决的问题是 ConnectableObservables应该是可重新连接的",并且 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天全站免登陆