What is the correct way to share the result of an Angular Http network call in RxJs 5?

前端 未结 21 1781
广开言路
广开言路 2020-11-21 06:11

By using Http, we call a method that does a network call and returns an http observable:

getCustomer() {
    return          


        
21条回答
  •  不要未来只要你来
    2020-11-21 06:20

    rxjs 5.4.0 has a new shareReplay method.

    • rx-book shareReplay()
    • No docs at reactivex.io/rxjs

    The author explicitly says "ideal for handling things like caching AJAX results"

    rxjs PR #2443 feat(shareReplay): adds shareReplay variant of publishReplay

    shareReplay returns an observable that is the source multicasted over a ReplaySubject. That replay subject is recycled on error from the source, but not on completion of the source. This makes shareReplay ideal for handling things like caching AJAX results, as it's retryable. It's repeat behavior, however, differs from share in that it will not repeat the source observable, rather it will repeat the source observable's values.

提交回复
热议问题