Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: A stronger typed 'on' function #197

Open
dtaskoff opened this issue Jul 26, 2019 · 2 comments
Open

Suggestion: A stronger typed 'on' function #197

dtaskoff opened this issue Jul 26, 2019 · 2 comments

Comments

@dtaskoff
Copy link

dtaskoff commented Jul 26, 2019

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
Copy link
Member

avh4 commented Jul 26, 2019

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
Copy link
Author

dtaskoff commented Jul 26, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants