Events: listener without context can be added twice
See original GitHub issuevar m = new L.Marker();
var x = function() {console.log("event fired")};
/* register without context */
m.on("test", x);
m.on("test", x);
/* fires twice */
m.fire("test");
/* register with context */
context = {}
m.on("test2", x, context);
m.on("test2", x, context);
/* fires once*/
m.fire("test2");
https://playground-leaflet.rhcloud.com/wum/1/edit?html,js,output
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Rebind JavaScript events and addEventListener fires twice
The .addEventListener method ensures that the same function reference won't be bound more than once to the same element/event/captures ...
Read more >How to ensure an event listener is only fired once in JavaScript
We can pass an object as an argument to the addEventListener method and specify that the event is only handled once. This is...
Read more >event listener pattern in api - what should adding the same ...
If you allow the same listener to be added twice, it should be clear which of the two listener entries is going to...
Read more >Event Listeners being called twice. - Google Groups
I'm having an issue where my eventListeners are all called twice for one give event emission - I believe the listeners are registered...
Read more >Introduction to browser events - The Modern JavaScript Tutorial
All DOM nodes generate such signals (but events are not limited to ... To react on events we can assign a handler –...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We had a small chat about this, and it seems it’s a feature, not a bug 😉 Basically, this is what you are doing when you do something like:
So what needs to be unique is the combination of listener + context.
This is fixed now, is it?