-
Notifications
You must be signed in to change notification settings - Fork 437
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
Preventing duplicate event listener registrations #554
Preventing duplicate event listener registrations #554
Conversation
Thanks for your PR! Why do we need to enforce a named function?
Using this will break functionality for current users, we should probably just |
This is because we prevent duplicate event listener registration by using the name of the named function as a key.
This code isn't necessary, but was added as a defensive measure. It doesn't seem to cause any issues in operation. If you are concerned, replacing it with the I will add a commit 😀 |
Maybe we should also fallback on eventName if listener.name is empty? |
Using the What do you think about this approach?
Since By doing this, the same behavior as before is assured even if this PR is merged. |
Do we really need to append more events with Couldn't we just replace the old event with the new, given same name? Also |
I've written it as defensively as possible. If it's sufficient to replace an existing event with a new one, it's fine to just use |
Looks good to me! |
@seungdeng17 hello 👋 Sorry to bother - this is also my first time digging into the source code for this package But ever since upgrading to this commit, every time
Do you have any pointers to stop these console warns? I'll start digging into the call stack but I figured I'd ask here in this change if you know the correct way around this |
I encountered an issue where event listeners were being registered multiple times.
I discovered that when calling scrollTo-related functions in the
animate-scroll
module, event listeners were being registered through thesubscribe
method.There was no logic to remove registered events or check for duplicates, resulting in event listeners being registered multiple times.
I have thought of the simplest solution: preventing duplicate registrations by using the name of the listener function passed as a parameter to the
addPassiveEventListener
function as a key.It is important to note that you should pass a named function with a unique name as the listener parameter, rather than an anonymous function.
Fix for #451