miso
Copyright(C) 2016-2026 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso.Subscription.Window

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
  = MouseMoved Coord         -- (clientX, clientY)
  | PointerMoved PointerEvent -- full pointer data

subs :: [Sub Action]
subs =
  [ windowCoordsSub      MouseMoved    -- simple (x, y) pair
  , windowPointerMoveSub PointerMoved  -- full PointerEvent
  ]

Subscription variants

  • windowCoordsSub — fires (clientX, clientY) as a Coord on every pointermove. Simplest option when only screen position is needed.
resizeSub :: (Coord -> action) -> Sub action
resizeSub f = windowSub "resize" emptyDecoder (const (f (0,0)))

See also

Synopsis

Subscription

windowSub Source #

Arguments

:: MisoString

DOM event name to listen for on window (e.g. "resize", "pointermove")

-> Decoder r

Decoder for extracting a value from the raw event object

-> (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.

windowCoordsSub Source #

Arguments

:: (Coord -> action)

Callback fired with (clientX, clientY) on every pointermove event

-> Sub action 

Captures window coordinates changes as they occur and writes them to an event sink.

windowPointerMoveSub Source #

Arguments

:: (PointerEvent -> action)

Callback fired with the full PointerEvent on every pointermove

-> Sub action 

window.addEventListener ("pointermove", (event) => handle(event)) A Sub to handle PointerEvents on window.

windowSubWithOptions Source #

Arguments

:: Options

Propagation options (preventDefault, stopPropagation)

-> MisoString

DOM event name to listen for on window

-> Decoder result

Decoder for extracting a value from the raw event object

-> (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.

Types

type Coord = (Double, Double) Source #

An (x,y) coordinate.