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

Description

Overview

Miso.Subscription is the re-export hub for all of miso's built-in Sub subscriptions. A subscription is a long-running IO action of type Sink action -> IO () that delivers external events — mouse moves, key presses, URL changes, animation frames — into the update loop by calling its Sink.

Register subscriptions in the subs field of a Component:

import Miso
import Miso.Subscription

myComponent = (component model update view)
  { subs =
      [ mouseSub    MouseMoved
      , keyboardSub KeyPressed
      , uriSub      UrlChanged
      , rAFSub      Tick
      ]
  }

Subscription catalogue

mouseSub
global pointermoveMiso.Subscription.Mouse
keyboardSub
global keydown / keyupMiso.Subscription.Keyboard
arrowsSub, wasdSub, directionSub
arrow or WASD keys held — Miso.Subscription.Keyboard
uriSub
browser popstate (back/forward/pushState) — Miso.Subscription.History
routerSub
same, decoded via RouterMiso.Subscription.History
windowCoordsSub
global window pointermoveMiso.Subscription.Window
windowPointerMoveSub
global window pointermoveMiso.Subscription.Window
windowSubWithOptions
any window event — Miso.Subscription.Window
onLineSub
online / offline change — Miso.Subscription.OnLine
rAFSub
every requestAnimationFrame tick — Miso.Subscription.RAF

History helpers

The Miso.Subscription.History module also exports imperative navigation functions usable from within Effect:

update GoHome = io_ (pushURI (toURI Home))
update GoBack = io_ back

See also

Synopsis

Mouse

Keyboard

History

Window

OnLine

requestForAnimationFrame