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

Bug in DomEvent: removeListener does not remove listener is some cases #281

Closed
Scalar4eg opened this issue Sep 7, 2011 · 4 comments
Closed
Assignees
Labels
blocker Critical issue or PR that must be resolved before the next release
Milestone

Comments

@Scalar4eg
Copy link

removeListener does not remove SAME listeners
Here is simple test:

function OnClick() {console.log("i'm OnClick listener");}

for(var i=0;i<10;i++) L.DomEvent.addListener(document, "click", OnClick);
for(var i=0;i<10;i++) L.DomEvent.removeListener(document, "click", OnClick);

Now we can click on the page and we'll see message "i'm OnClick listener" 9 times instead of 0.

@mourner
Copy link
Member

mourner commented Sep 8, 2011

Hmm, I guess it shouldn't add the same listeners in the first place, right?

@ghost ghost assigned mourner Sep 8, 2011
@anru
Copy link
Contributor

anru commented Sep 8, 2011

From http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-Registration-interfaces-h3 :

If multiple identical EventListeners are registered on the same EventTarget with the same parameters the duplicate instances are discarded. They do not cause the EventListener to be called twice and since they are discarded they do not need to be removed with the removeEventListener method.

@mourner
Copy link
Member

mourner commented Sep 8, 2011

In this case Leaflet addListener creates a closure to bind it to the given context, so the listeners are not identical. We need to track this manually.

@mourner mourner closed this as completed in fde7c79 Sep 8, 2011
mourner added a commit that referenced this issue Sep 8, 2011
@mikila85
Copy link

so how am i spose to do this?
i get duplicate events fired because it initialized the controller few times :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker Critical issue or PR that must be resolved before the next release
Projects
None yet
Development

No branches or pull requests

4 participants