-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
on
should be idempotent
#4597
Comments
@jfirebaugh Using your example, if I don't call I'm seeing this behavior while trying to implement a style switcher. I'm calling |
Yeah, I believe double firing is what will currently happen if you bind the same function instance to the same event multiple times. But what you're seeing isn't necessarily this issue. A common mistake is to accidentally bind multiple different functions instances (which happen to do the same thing), e.g. with an inline function ( |
In my case, it is a binded (bound?) function, but that's happening in the constructor of my class: this.update = this.update.bind(this); Then I create the event listener using: map.on('click', this.update); So I would expect the same function instance to be passed each time, correct? Without a fix for this issue in place, I can look at internally tracking whether the event listener has been created already. |
Yes, provided there's only one instance of the class. |
Like
addEventListener
,Evented#on
(andMap#on
with delegation) should be idempotent, and only do something if there wasn't already a listener for the given event type and callback.For example, the sequence
on('a', cb)
,on('a', cb)
,off('a', cb)
should leave nocb
's listening fora
.The text was updated successfully, but these errors were encountered: