Replies: 2 comments 16 replies
-
I think your example is a bit hard to follow because you have changed the signature of Wouldn't something like this work? export const publishRef = <T>(bufferSize = 1, windowTime?: number) =>
share<T>({
connector: () => new ReplaySubject(bufferSize, windowTime),
resetOnComplete: false,
}); What this does is multicast the subscription by using a replay subject, which will get reset when everyone unsubscribes, but not when the source completes. The only problem this code has, if I'm not wrong, is that Again, I think it will be easier to reason about if you keep the signature of publishRef the same as before. |
Beta Was this translation helpful? Give feedback.
-
It's been a year, but I'm finding that what I really want is not possible in a simple way and probably never has been. It's like a simple version of what TanStack Query does. I used to think However, what I really want is to abstract away the fact that there are multiple subscribers, and not have multiple network requests triggered. And the behavior of a single self-completing observable is that if you subscribe again, it runs again. Obviously this is desirable, because why wouldn't you want fresh data when subscribing to an observable that everybody stopped caring about a long time ago? So I've been playing around with the new API, which I was reluctant to try for a long time, because it's so verbose. But it seems like I am forced to choose between 2 suboptimal behaviors: After source completes, either I have So this is my problem: When the source completes, I don't want the destination observers to complete. I want the But there are no options for this in complete: () => {
hasCompleted = true;
cancelReset();
resetConnection = handleReset(reset, resetOnComplete);
dest.complete();
}, I'm writing an article about this right now, and this isn't a very satisfying conclusion :/ I want there to be an option like |
Beta Was this translation helpful? Give feedback.
-
We've written a custom operator which wraps
publishReplay
+refCount
, and it was just working perfectly.But after v7, it is recommended to migrate to share: https://rxjs.dev/deprecations/multicasting#publishreplay
So we changed the implementation following the recommendation:
But in our Angular application, it seems working differently:
When we are consuming a watching stream only on Angular template via
async
pipe, and after navigating to other rules, the stream should be completed automatically, but the current implementation does not work as before. I don't know is our new implementation correct? Or it's just incorrect documentation.Sorry I can't reproduce it easily because it's in our own business codes, I'll try to reproduce further, but I still want to let you know it firstly.
Beta Was this translation helpful? Give feedback.
All reactions