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: Adding the ability to deregister event listeners #241

Merged
merged 3 commits into from
Dec 11, 2024

Conversation

AndresMonk
Copy link
Collaborator

Adds the ability to remove listeners that have been registered.

@CLAassistant
Copy link

CLAassistant commented Dec 10, 2024

CLA assistant check
All committers have signed the CLA.

@michielvandergeest
Copy link
Collaborator

Great work @AndresMonk! Love contributions with tests and documentation!

About the implementation:he $removeListener method seems removes events by event type, rather than a single listener by id. Also, if I understood correctly this method will remove all listeners that exists for a specific event. I imagine that beign useful in certain cases, but I can also see how more granular control of which listeners are being removed may come in handy. What do you think?

@AndresMonk
Copy link
Collaborator Author

Thanks @michielvandergeest !

Also, if I understood correctly this method will remove all listeners that exists for a specific event.
That wasn’t what I was gunning for, so it could be my understanding of the maps is a bit wonky.

As a breakdown of how I thought this was working:

//! Get all the components that are listening to this specific event.
let componentsMap = eventsMap.get(event)

...

//! Check if the component exists within the map the event.
if (componentsMap.contains(component)) {

  //! If it does exist, remove this component from the listeners for this event.
  componentsMap.delete(component);

  //! Set the updated list of components for the map.
  eventsMap.set(event, componentsMap)
  callbackCache.delete(event)
}

@michielvandergeest
Copy link
Collaborator

No, I think you are actually right! I looked at the implementation to fast :)

@michielvandergeest michielvandergeest changed the base branch from master to dev December 11, 2024 14:08
Copy link
Collaborator

@michielvandergeest michielvandergeest left a comment

Choose a reason for hiding this comment

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

Thanks for making these last changes. This looks good to me!

@michielvandergeest michielvandergeest merged commit de0a8ec into lightning-js:dev Dec 11, 2024
1 check passed
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.

3 participants