Skip to content

Comments

feat: add method to remove all listeners#6

Open
andiwils wants to merge 2 commits intomainfrom
feat/remove-all-listeners
Open

feat: add method to remove all listeners#6
andiwils wants to merge 2 commits intomainfrom
feat/remove-all-listeners

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