-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(shareReplay): adds shareReplay
variant of publishReplay
#2443
Conversation
`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. related #2013, #453, #2043
I suspect the 0.009% change in coverage isn't worth blocking this over, as it's pretty much a rounding error. |
can you expand on the behavior differences? Perhaps with an example? |
@robwormald The tests show the behavior, but in case they aren't clear enough...
assume that
... hopefully, that illustrates the behavior? |
The only reservation I have is that the ReplaySubject isn't deallocated when the refCount Observable is disposed. By referencing the RS in the Observable definition, it'll only be GC'd when the |
This seems promising. How do I use if for the following scenario. I want to cache a list of customers from the server but periodically refresh that list, say, if it is more than an hour old.
In the absence of the Be gentle ... I'm a comparative noob. |
const subscriber2 = hot(' b| ').mergeMapTo(shared); | ||
const expected2 = ' (12)-3-# '; | ||
const subscriber3 = hot(' (c|) ').mergeMapTo(shared); | ||
const expected3 = ' -1-2-----3-#'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't expected3
be (23)#
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore me. It's correct. (because the source errored, it didn't complete, so we create a new ReplaySubject for the next multicast)
Apart from what has already been said (e.g. by Paul), this looks good to merge IMO. |
Shall the MIGRATION.md be updated aswell? It might be confusing otherwise |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
shareReplay
returns an observable that is the source multicasted over aReplaySubject
. That replay subject is recycled on error from thesource
, but not on completion of the source. This makesshareReplay
ideal for handling things like caching AJAX results, as it's retryable. It's repeat behavior, however, differs fromshare
in that it will not repeat thesource
observable, rather it will repeat thesource
observable's values.related #2013, #453, #2043