Skip to content
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: add method to remove all listeners #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

andiwils
Copy link
Collaborator

This PR adds a removeAllListeners method to the AddEvents mixin, allowing for the removal of all event listeners from instances of classes using this mixin. The implementation iterates through all TypedEvent members and calls removeAllListeners on each, ensuring a clean state. Unit tests have been included to verify that the method correctly removes all listeners for both parent and child classes.

@andiwils andiwils requested a review from bbaldino June 10, 2024 16:09
* Remove all event listeners from all events.
*/
removeAllListeners() {
Object.keys(this).forEach((eventName) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

So this works correctly with inheritance I guess?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. The removeAllListeners method has been updated to ensure it works with inherited events by traversing the prototype chain using a helper function. Unit tests updated as well.

@andiwils andiwils requested a review from bbaldino June 10, 2024 19:40
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.

2 participants