elm / browser

Create Elm programs that run in browsers!
https://package.elm-lang.org/packages/elm/browser/latest/
BSD 3-Clause "New" or "Revised" License
312 stars 64 forks source link

Expose "on" -function #114

Open swelet opened 4 years ago

swelet commented 4 years ago

Thanks for all the work that you guys do.

I think the Browser.Events.on -function should be exposed.

With the Html.Events.on function we can listen for custom js-events on elements in the Dom. I miss a way of doing the same for Document through subscriptions. Say I want to use a custom drag and drop library in js, I could listen for this event:

someElement.dispatchEvent(new CustomEvent('customDragStart'));

but not make a subscription of this

document.dispatchEvent(new CustomEvent('customDrop'));

I think exposing Browser.Events.on would be both useful and consistent with the api in Html.Events.

rupertlssmith commented 2 years ago

Would also need to expose Node.

Or expose 'on' functions specalized to window or document:

onWindow : String -> Decode.Decoder msg -> Sub msg
onDocument : String -> Decode.Decoder msg -> Sub msg
Janiczek commented 2 years ago

This would be useful for "online" and "offline" events that only happen on <body>.

https://developer.mozilla.org/en-US/docs/Web/API/Document/ononline https://developer.mozilla.org/en-US/docs/Web/API/Document/onoffline