| 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.OnLine
Contents
Description
Overview
Miso.Subscription.OnLine provides onLineSub, a subscription that
tracks the browser's
navigator.onLine
connectivity status. It registers online and offline event listeners
on window and fires an action with True when the connection is
restored and False when it is lost.
Quick start
import Miso import Miso.Subscription.OnLine data Action = OnLineChanged Bool subs :: [SubAction] subs = [onLineSubOnLineChanged ] update :: Action ->Effectp props Model Action update (OnLineChanged isOnLine) | isOnLine =io_(consoleLog "Back online") | otherwise =io_(consoleLog "Offline")
To read the current status imperatively without subscribing, use
isOnLine from Miso.Navigator.
See also
- Miso.Navigator —
isOnLinefor one-shot reads - Miso.Subscription — re-export hub
- Miso.Subscription.Util —
createSubused internally
Subscriptions
Returns Sub for the navigator.onLine API.
Fires action with True when the browser goes online, and False when it goes offline.
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/onLine