| Copyright | (C) 2016-2026 David M. Johnson |
|---|---|
| License | BSD3-style (see the file LICENSE) |
| Maintainer | David M. Johnson <code@dmj.io> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Miso.Subscription.Window
Contents
Description
Overview
Miso.Subscription.Window provides subscriptions that listen to
window-level events.
It also exposes windowSub and windowSubWithOptions as the generic
primitives on which mouseSub and other
per-event wrappers are built.
Quick start
import Miso import Miso.Subscription.Window data Action = MouseMovedCoord-- (clientX, clientY) | PointerMovedPointerEvent-- full pointer data subs :: [SubAction] subs = [windowCoordsSubMouseMoved -- simple (x, y) pair ,windowPointerMoveSubPointerMoved -- full PointerEvent ]
Subscription variants
windowCoordsSub— fires(clientX, clientY)as aCoordon everypointermove. Simplest option when only screen position is needed.
windowPointerMoveSub— fires the fullPointerEvent(pressure, tilt, pointer type, …) on everypointermove.windowSub— listen to any named window event by providing an event name and aDecoder:
resizeSub :: (Coord-> action) ->Subaction resizeSub f =windowSub"resize"emptyDecoder(const (f (0,0)))
windowSubWithOptions— same aswindowSubbut acceptsOptionsto callpreventDefaultorstopPropagationon the raw event before forwarding it.
See also
- Miso.Subscription.Mouse —
mouseSub(thin alias overwindowPointerMoveSub) - Miso.Event.Decoder —
Decoder,pointerDecoder - Miso.Event.Types —
PointerEvent,Options - Miso.Subscription.Util —
createSubused internally
Synopsis
- windowSub :: MisoString -> Decoder r -> (r -> action) -> Sub action
- windowCoordsSub :: (Coord -> action) -> Sub action
- windowPointerMoveSub :: (PointerEvent -> action) -> Sub action
- windowSubWithOptions :: Options -> MisoString -> Decoder result -> (result -> action) -> Sub action
- type Coord = (Double, Double)
Subscription
Arguments
| :: MisoString | DOM event name to listen for on |
| -> Decoder r |
|
| -> (r -> action) | Callback fired with the decoded value on each event |
| -> Sub action |
windowSub eventName decoder toAction provides a subscription
to listen to window level events.
Arguments
| :: (Coord -> action) | Callback fired with |
| -> Sub action |
Captures window coordinates changes as they occur and writes them to an event sink.
Arguments
| :: (PointerEvent -> action) | Callback fired with the full |
| -> Sub action |
window.addEventListener ("pointermove", (event) => handle(event))
A Sub to handle PointerEvents on window.
Arguments
| :: Options | Propagation options ( |
| -> MisoString | DOM event name to listen for on |
| -> Decoder result |
|
| -> (result -> action) | Callback fired with the decoded value on each event |
| -> Sub action |
windowSubWithOptions options eventName decoder toAction provides a
subscription to listen to window level events.