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
Fix adding/removing events on an unstamped context #1514
Conversation
…always apply if there is a context.
Usually, the layer is already stamp by the map.addLayer function. But I think it's a good idea to make sure the context is always stamp like you did 👍 |
@jfgirard right, issue was around adding a feature to a FeatureGroup before it was added to a map. Guarding with L.stamp() was essentially how I was working around it as well. |
I'll just tack this on here instead of opening another issue. Ran into one more edge case today - calling the current implementation of Events#removeEventListener with a stamped context will decrement the objLenKey index for that particular event for all contexts, even if the current context isn't registered. this can lead to a sticky situation where the objLenKey index is at zero before other event listeners have been fully cleared out, leading to zombies.
fix is simply to change the conditional here |
Awesome thanks, have added that one too. |
@@ -67,8 +67,9 @@ L.Mixin.Events = { | |||
|
|||
removeEventListener: function (types, fn, context) { // (String[, Function, Object]) or (Object[, Object]) | |||
var events = this[key], | |||
type, i, len, listeners, j, | |||
contextId, objKey, objLenKey; | |||
contextId = context && context._leaflet_id, // if the context has an id, use it to find the listeners |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We always stamp context in addEventListener
so we can use L.stamp
here too.
Also, please use spaces for alignment here.
Cool, changed to L.stamp there too. We are using spaces for alignment there, the old code must have been tabs. |
Fix adding/removing events on an unstamped context
Awesome, thanks Dave! |
If you add an event listener with a context with no stamp, then stamp the context and try remove the event listener we fail to do so as we assume that we need to use the stamped array, which hasn't been set yet.
I've changed this to always stamp the context (if there is one), so we either go the stamped way, or the no context way.
Not sure why we weren't always just stamping the context before, so please have a check over @mourner @jfgirard thanks :-)
Fixes #1495, Fixes #1512
Refs #1141