Skip to content

Readd internal ChatClient onPrivmsg handler on removeListener #178

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

Merged
merged 4 commits into from
Sep 30, 2020
Merged

Readd internal ChatClient onPrivmsg handler on removeListener #178

merged 4 commits into from
Sep 30, 2020

Conversation

hlxid
Copy link
Contributor

@hlxid hlxid commented Sep 21, 2020

Type: Bugfix

Fixes: #177

Re-registers the internal onPrivmsg handler that emits the onMessage events on removeListener.
I hope the way I did it is fine, otherwise just let me know.


removeListener() {
// Doing this with rest params would require a any[] type annotation which is bad and also
// would add a new function signature which is also not wanted thus using `arguments` makes more sense here.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the implementation doesn't contribute to the actual signatures. But you don't have to use any[] either.

Please update the event emitter package (as a hard dependency in package.json! it's a necessary bugfix) and use its new signatures as a base for this. Also drop the .call from the super call - it's completely unnecessary.

To be honest, a complete fix for this would probably have to completely separate internal and external events. There are many Promises that could leak because of calling this function while being connected. With separated events, event handlers wouldn't have to be recreated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the package and fixed the above code by using typescript type guards similar to the new implementation of removeHandlers.
I assume you meant removeListener(idOrEvent?: Listener | Function, listener?: Function) by "new signature" and that I should use that one but that signature isn't included with the newly generated type definitons: https://unpkg.com/@d-fischer/typed-event-emitter@3.0.2/lib/EventEmitter.d.ts so I can't use it to just forward the two parameters.

I'm sorry to say this but I currently don't have enough time to dig into the lib and understand how exactly events are passed so I'm not able to refactor this to use internal and external events.

@hlxid hlxid requested a review from d-fischer September 26, 2020 15:47
@d-fischer d-fischer changed the base branch from master to support/4.2 September 30, 2020 22:00
@d-fischer d-fischer changed the base branch from support/4.2 to master September 30, 2020 22:01
hlxid and others added 4 commits October 1, 2020 00:10

Partially verified

This commit is signed with the committer’s verified signature.
d-fischer’s contribution has been verified via GPG key.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.

Partially verified

This commit is signed with the committer’s verified signature.
d-fischer’s contribution has been verified via GPG key.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.

Partially verified

This commit is signed with the committer’s verified signature.
d-fischer’s contribution has been verified via GPG key.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.

Verified

This commit was signed with the committer’s verified signature.
d-fischer Daniel Fischer
This is currently unsupported by TS; I'm considering contributing it as a feature. Until then, @ts-expect-error is necessary
@d-fischer d-fischer changed the base branch from master to support/4.2 September 30, 2020 22:11
Copy link
Member

@d-fischer d-fischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed up the way arguments are passed to the superclass. Anyway, thanks for your effort!

@d-fischer
Copy link
Member

Don't worry, I have to close and reopen so that Travis picks the weird rebases up properly.

@d-fischer d-fischer closed this Sep 30, 2020
@d-fischer d-fischer reopened this Sep 30, 2020
@d-fischer d-fischer merged commit ed6738a into twurple:support/4.2 Sep 30, 2020
@d-fischer
Copy link
Member

@all-contributors please add @daniel0611 for code

@allcontributors
Copy link
Contributor

@d-fischer

I've put up a pull request to add @daniel0611! 🎉

@d-fischer
Copy link
Member

Released as 4.2.5.

@hlxid hlxid deleted the fix/177-removeListener-breaks-onMessage branch October 1, 2020 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calling ChatClient.removeListener breaks onMessage
2 participants