doom icon indicating copy to clipboard operation
doom copied to clipboard

EventListener doesn't get removed

Open frabbit opened this issue 8 years ago • 7 comments

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");
    );
}

frabbit avatar Jul 05 '17 21:07 frabbit

the click listener is executed everytime i click on the button (the label is correctly updated)

frabbit avatar Jul 05 '17 21:07 frabbit

it works correctly if i set it to a different listener, maybe that's the reason why this error wasn't revealed.

frabbit avatar Jul 05 '17 21:07 frabbit

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.

fponticelli avatar Jul 05 '17 23:07 fponticelli

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.

frabbit avatar Jul 06 '17 00:07 frabbit

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.

fponticelli avatar Jul 06 '17 03:07 fponticelli

what kind of issues did you run in when comparing VDOM with VDOM?

frabbit avatar Jul 06 '17 08:07 frabbit

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.

fponticelli avatar Jul 06 '17 13:07 fponticelli