elm / html

Use HTML in Elm!
https://package.elm-lang.org/packages/elm/html/latest/
BSD 3-Clause "New" or "Revised" License
394 stars 99 forks source link

Suggestion: A stronger typed 'on' function #197

Open dtaskoff opened 5 years ago

dtaskoff commented 5 years ago

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.

avh4 commented 5 years ago

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

dtaskoff commented 5 years ago

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.