rxjs icon indicating copy to clipboard operation
rxjs copied to clipboard

feat(shareReplay): use another observable to control resets

Open Evertt opened this issue 3 years ago • 3 comments

This feature, first introduced for the share operator, is equally as desirable for the shareReplay operator. It allows one to, for example, set up a delayed reset. For Observables that are a little expensive to set up, but not so expensive that it makes sense to keep them around forever.

Evertt avatar Mar 01 '22 04:03 Evertt

I think I'd rather guide users to just use share. IMHO, we should probably deprecate shareReplay at some point in the future.

benlesh avatar Mar 10 '22 21:03 benlesh

we should probably deprecate shareReplay at some point in the future

Really? Why? It's such a pleasant operator to have.

Evertt avatar Mar 11 '22 06:03 Evertt

I was just pumping to this and wondered how to solve it. I found refCount observable to be very handy when playing with suspense with react. If anyone else pumps in to this, here is how I used share-operator instead of shareReplay to manage this:

      observable.pipe(
      share({
        connector: () => new ReplaySubject(1),
        resetOnRefCountZero: () => timer(1000),
      }))

diginikkari avatar May 06 '22 11:05 diginikkari