-
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): add config parameter #4059
Conversation
Pull Request Test Coverage Report for Build 7850
💛 - Coveralls |
Supporting additional overload signatures is possible. More could be added to allow for shareReplay({ refCount: true }) or shareReplay(1, { refCount: true }) But I'll wait to see what people think of the PR before adding any. And I'll add some |
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.
I like the spirit of this one... I think I'd rather force users into a "use the config object, or don't" sort of api:
For example:
source.pipe(
shareReplay({
bufferSize: 3,
windowSize: 2000,
scheduler: animationFrameScheduler,
refCount: true,
}),
)
We can, of course, support the current signature, so it's not a breaking change, but anytime we're over two arguments, I think a configuration object just makes it more readable.
@benlesh I've updated the PR:
However, there is one thing about which I'm unsure: I don't know the syntax that should be used to express the |
@cartant does this answer help with your question about how to document the |
@pertrai1 Yeah, that helps. Thanks. |
Hmm: microsoft/tsdoc#19 |
From the core team meeting Sticking with this PR, we might default to refCount: true in an upcoming major release. |
@cartant regarding the documentation. So a basic description of the parameter itself would be totally fine. As far as I know we automatically we link to an api page if it exists, which isn't the case in the current implementation and to be honest I don't know how we want to export the interface. So basically we just render docs for eported stuff from following files:
|
@benlesh Regarding this PR being merged/released, I think the docs are pretty important. I agree with OJ that it is or, at least, has the potential to be confusing. There are some issues - hinted at above - regarding the TSDoc. TypeScript does not like the JSDoc dot-separated style and annotating a separate type is recommended. However, here, TL;DR I don't think this can be released without good docs. And I'm going to be working on those, later today. |
@cartant ... looking in Google3, there are a LOT... a LOT LOT of uses of shareReplay where it's just Also I think that we should use the TestScheduler marble diagrams for this test. |
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.
- Update the tests to use marble diagrams
- undeprecate the old signature. We'll need to keep it, there are too many uses of shareReplay(1). We can discuss deprecating the "larger" signatures, though.
Also, once this is done, we'll need to implement the changes in the experimental branch. |
Regarding the deprecation, yeah, I can see that doing so might be too harsh - even though it's not technically a breaking change. One of the reasons for this PR is that I was about to write a TSLint rule to highlight |
Ping @cartant ... not sure where this one is at right now. |
@benlesh It's on my TODO list. I've not yet addressed your change requests. |
@benlesh This is done, except for the docs.
With those points in mind, I've made no attempt at updating the TSDoc. |
since ShareReplay doesn't work as expected after upgrade of Rx.js. it should be fixed soon (ReactiveX/rxjs#4059) Change-Id: I8c7f4983daf9334095cb9da2f4261060ddf3da89 Reviewed-on: http://review.couchbase.org/100894 Well-Formed: Build Bot <[email protected]> Reviewed-by: Pavel Blagodov <[email protected]> Tested-by: Pavel Blagodov <[email protected]>
If set |
@@ -1,11 +1,17 @@ | |||
import { Observable, SchedulerLike } from 'rxjs'; | |||
import { shareReplay as higherOrder } from 'rxjs/operators'; | |||
import { ShareReplayConfig } from 'rxjs/internal-compatibility'; | |||
|
|||
/** | |||
* @method shareReplay | |||
* @owner Observable |
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.
We can remove @owner Observable
here. It's not necessary.
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.
Done.
What exactly is the argument for making shareReplay configurably leak subscriptions? |
@pauldraper For background, you could read the issues linked in this PR's description. The discussion therein is close to exhaustive.
See this comment in particular. |
YEAY!!! 🎉 |
Description:
This PR adds a
config
parameter to theshareReplay
operator so that it's possible to specify the ref counting behaviour for the use cases outlined in this comment.If the
config
parameter is not specified, it defaults to the current behaviour: the subscription to the source is not reference counted and the unsubscriptions from the shared observable do not effect an unsubscription from the source. That is, unsubscription from the source only occurs if the source completes or errors.I've named the
config
propertyrefCount
, as that seems appropriate, given that the current implementation of theshareReplay
operator is not ref counted.Inline with the comment linked above, if
{ refCount: true }
is specified and the ref count drops to zero, a newReplaySubject
will be created if another subscription to the shared observable is made.I've added tests for the default behaviour and for
{ refCount: true }
and{ refCount: false }
.Also, there was another problem with the previous implementation: the returned teardown function was never called. Instead of being returned, it needs to be added to the
Subscriber
via thethis
context.Related issue (if exists): #3336 #3127
Here's some more detail about the history behind this feature/fix:
5.4.3
theshareReplay
implementation usedmulticast
, but did not recycle the subject if it had completed. That meant that if the reference count dropped to zero, the subject was discarded and the subscription to the source would be unsubscribed.5.5.0.beta.4
- in response to this issue - the implementation was changed. And the new implementation essentially no longer reference counted the subscription to the source and that subscription was only unsubscribed upon the source completing or erroring. That is, an explicit unsubscription from the shared observable would never effect an unsubscription from the source.