gnat / surreal

🗿 Mini jQuery alternative. Dependency-free animations. Locality of Behavior. Use one element or arrays transparently. Pairs with htmx. Vanilla querySelector() but better!
https://gnat.github.io/surreal/example.html
MIT License
1.3k stars 26 forks source link

Payload for custom event #16

Closed ilkiri23 closed 8 months ago

ilkiri23 commented 9 months ago

It would be great if we could pass payload to the trigger function (something like trigger('click', { value: 42 })) and get it in the handler

me().on('click', (event) => { 
  console.log(event.detail.value) // 42
})

If you agree with that, I can create a PR

gnat commented 8 months ago

This is a good idea and I'll add it soon unless you want to make a PR.

ilkiri23 commented 8 months ago

What do you also think about adding cancelable: true option by default?

gnat commented 8 months ago

What do you also think about adding cancelable: true option by default?

They already are as far as I know. Check out Surreal's halt() for a convenient way to stop propagation / prevent default.

gnat commented 8 months ago

Latest 1.1.6 adds optional event details, and send() now aliases trigger().