Skip to content

Commit

Permalink
Switch ElementOn back to addEventListener instead of dom.on
Browse files Browse the repository at this point in the history
This undoes 7c6d9b9, since  using dom.on was causing some undocumented breakages in code relying on on-* listeners firing as a component is being destroyed
  • Loading branch information
ericyhwang committed Dec 22, 2022
1 parent 3f84fdc commit c9eaeb8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,13 @@ ElementOn.prototype.emit = function(context, element) {
var listener = function elementOnListener(event) {
return elementOn.apply(context, element, event);
};
context.controller.dom.on(this.name, element, listener, false);
// Using `context.controller.dom.on` would be better for garbage collection,
// but since it synchronously removes listeners on component destroy, it would
// break existing code relying on `on-*` listeners firing as a component is
// being destroyed. Even with `addEventListener`, browsers should still GC
// the listeners once there are no references to the element.
element.addEventListener(this.name, listener, false);
// context.controller.dom.on(this.name, element, listener, false);
};
ElementOn.prototype.apply = function(context, element, event) {
var modelData = context.controller.model.data;
Expand Down

0 comments on commit c9eaeb8

Please sign in to comment.