canjs / can-component

Custom elements and widgets
https://canjs.com/doc/can-component.html
MIT License
8 stars 8 forks source link

DOM Event Delegation #335

Open JaneOri opened 5 years ago

JaneOri commented 5 years ago

Since can-component events deprecated: https://canjs.com/doc/can-component.prototype.events.html There isn't a happy path solution for the DOM event delegation that it provided

JaneOri commented 5 years ago

stache syntax could be interesting. like:

<ul on:delegated:click=".clickme; doSomething()">
  <li>asdf</li>
  <li class="clickme">Hi</li>
  <li class="clickme">Hello</li>
</ul>

downside: any existing event delegation to direct children of the component element can't use this since the component element isn't part of the view.

rjgotten commented 4 years ago

@James0x57 Could set this up with the connectedCallback - e.g.

connectedCallback( element ) {
  this.listenTo( element, ".delegated", "click", event => {
    // ...
  });
});

Except registering delegated listeners currently does not work correctly at all with the underlying event bindings mixin. See also my findings in https://github.com/canjs/can-event-queue/issues/35