doom
doom copied to clipboard
EventListener doesn't get removed
I found out that an event listener is not removed in my case, i use bind to add a click listener, do you know if this is a known issue?
public static function render (state:State, api:Api) {
return div(
state.active ? button( "Enable") : button(["click" => api.removeState.bind()], "Disable");
);
}
the click listener is executed everytime i click on the button (the label is correctly updated)
it works correctly if i set it to a different listener, maybe that's the reason why this error wasn't revealed.
That's right, the patching mechanism will not remove attributes or events that are not explicitly indicated. You can pass to the left case "click" => null (or an empty handler) and it should work.
hmm, is there any reason why you don't remove them? Don't you compare the vdom and generate remove patches? I'm not sure, but i can imagine that this behaviour leads to nasty bugs.
The reason is that the real doms has quite literally hundreds of attributes and properties and the VDOM knows about the things that exist but not the things that were existing in the last update. So to be clear I do not compare the old VDOM with the new one. I compare the VDOM with the actual DOM. I tried VDOM to VDOM before and the surprises were even worse. The hidden requirement is that if you have symmetrical elements with the same name they should also bring the same collection of attributes. I wish there was a more formal way to enforce that.
what kind of issues did you run in when comparing VDOM with VDOM?
The main problem was with components that changed their own attributes and HTML internally (bootstrap components and so on). In that case the old VDOM didn't look at all like the current DOM. There might be a sweet spot where patches to VDOM and patches to DOM can live in harmony.