Skip to content

Conversation

@robinmolen
Copy link
Contributor

Closes #192

To correctly unmount a event handler the map.on() and map.off() have to use the exact same props, otherwise the map.off() cannot correctly identify which handler to unmount, resulting in multiple (read duplicate) event handlers for the same event. See https://leafletjs.com/reference.html#evented-off for more information

By using a custom function on the map.on() (which in turn might call the correct props[handler]), the props[handler] is actually never used as event handler. Meaning that the map.off(), in the current setup, will never work.

By making sure that the map.on() and map.off() use the same function, the unmounting works as expected and old event handlers are removed.

I couldn't find a reason why this "function checking its own type, and then maybe calling the correct props[handler]" behaviour was implemented. If someone can tell me why (and preferably a bug report that shows an actual bug), i can look into a solution that uses the old setup.

When unmounting a specific map event handler (`map.off(eventType, func)`), the exact same mounting function (`map.on(eventType, func)`) has to be used. Otherwise the map unmounting doesn't know how which function should be removed, and nothing happens (resulting in more and more duplicate handlers for the same event). See https://leafletjs.com/reference.html#evented-off

By using a custom function on the `map.on()` (which in turn *might* call the correct `props[handler]`), the `props[handler]` is actually never used as event handler. Meaning that the `map.off()`, in the current setup, will never work.

By making sure that the `map.on()` and `map.off()` use the same function, the unmounting works as expected and old event handlers are removed.
@brennanwilkes
Copy link
Collaborator

if someone with more time than me can approve this I will merge it and deploy a version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The handleChange function is fired multiple times during edit or delete operations.

2 participants