-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Call subscription.complete on interpreter stop #3453
Conversation
🦋 Changeset detectedLatest commit: 60572d9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 60572d9:
|
👇 Click on the image for a new way to code review
Legend |
@@ -388,8 +388,8 @@ export class Interpreter< | |||
return this; | |||
} | |||
public subscribe( | |||
observer: Observer< | |||
State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta> | |||
observer: Partial< |
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've rechecked with RxJS and listener types are actually all optional (well, not exactly, but I'm not sure if we want to do this).
It was really annoying in tests for me to implement this:
service.subscribe({
next: noop,
error: noop,
complete: completeCb
})
and I think that it makes sense to make it easier to just provide a single callback type, so I've followed that instinct and wrapped Observer
at the parameter position Partial
this.doneListeners.delete(resolvedCompleteListener); | ||
this.listeners.delete(observer.next); | ||
this.doneListeners.delete(completeOnce); | ||
this.stopListeners.delete(completeOnce); |
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.
this is an additional bug fix, we were missing a call to remove a stop listener
this.onDone(completeOnce); | ||
this.onStop(completeOnce); |
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.
this was a little bit annoying, but I think it's the cleanest solution possible right now. This probably will be completely refactored in v5 anyway.
next: ((isObserver ? nextHandler.next : nextHandler) || noop).bind(self), | ||
error: ((isObserver ? nextHandler.error : errorHandler) || noop).bind(self), | ||
complete: ( | ||
(isObserver ? nextHandler.complete : completionHandler) || noop | ||
).bind(self) |
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 don't think that we really need those bind
s here but we were already binding next
listener in the Interpreter#subscribe
. So I didn't want to regress this accidentally and I've just used the same code pattern for all the callbacks here.
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.
The code looks top quality 👍🏻
When an interpreter is stoped, all listeners get removed, therefore a potential subscription should complete.
Closes: #3452