html icon indicating copy to clipboard operation
html copied to clipboard

Suggestion: A stronger typed 'on' function

Open dtaskoff opened this issue 6 years ago • 2 comments

Currently, Html.Events.on has the following type signature:

on : String -> Decoder msg -> Attribute msg

Several times, I've been struggling to find what I'm doing wrong, only to discover, that I've mistyped the event's name (stringly-typed ftw).

Wouldn't it be better, to replace that String argument with an enum, which has all current javascript events, plus a Custom String one, for custom events? If you're up for such a change, I'm willing to implement it.

dtaskoff avatar Jul 26 '19 13:07 dtaskoff

Just to reiterate the note leohaskell made about custom events: if something like that were implemented, there would still need to be some way to listen to events with arbitrary string names:

DOM events are not limited to a specific set -- "synthetic" events can be created and used that have any string name: https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events

Specifically, I believe it's not uncommon to make use of synthetic events when building custom elements: https://developers.google.com/web/fundamentals/web-components/customelements

avh4 avatar Jul 26 '19 15:07 avh4

Another solution to this problem would be to provide more functions like ‘onClick’, ‘onInput’, and the like, which is a viable option, as well, although it’s not as flexible as the above mentioned solution, because the user will have to stick with the provided specific implementations.

dtaskoff avatar Jul 26 '19 15:07 dtaskoff