When should I use `publishReplay` vs `shareReplay`?

前端 未结 3 1342
青春惊慌失措
青春惊慌失措 2020-12-25 12:17

I already know that

  • publish shares a single subscription and also returns a ConnectableObservable ( so we have to Connect(

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-25 12:39

    publishReplay allows you to controls when the subscription starts. shareReplay will start automatically upon the first subscription.

    Generally, if the observable is to be used in a template (html file) use shareReplay. The advantage being you won't have to worry about unsubscribing etc.

提交回复
热议问题