shareReplay in RxJS 5

前端 未结 2 859
无人及你
无人及你 2020-12-19 02:52

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

  1. Why?
  2. Does .publishReplay(1).refCount() faith
2条回答
  •  独厮守ぢ
    2020-12-19 03:20

    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.

提交回复
热议问题