mercredi 9 octobre 2019

Event delegation and the global `event` object in Ember action

Today I've learned a bit about the event delegation in Ember. The whole thing is exactly what I'd like to use in my code. There is a small problem though. When I migrate from

<div ondragend=></div>

to

<div ></div>

then I can't get the event parameter in my action method anymore and the thing is that I need it to get access to event.clientX/Y. This answer mentiones that it's possible to simply remove the parameter event and use it "globally" like this

...
actions: {
  dragEnd() {
    event.blahblah...
  }
}

So, I've got some questions regarding this technique:

  1. Can anyone tell me how legal is it? It's not documented anywhere.
  2. Do I understand correctly that in the case I use the closured action (<div ondragend=></div>) it won't use the event delegation, i.e. it will attach the event handler to that div and not the body like it does according to the doc if I use this pattern (<div ></div>) ?



Aucun commentaire:

Enregistrer un commentaire