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

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 :: [Sub Action]
subs = [ onLineSub OnLineChanged ]

update :: Action -> Effect p 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

Synopsis

Subscriptions

onLineSub Source #

Arguments

:: (Bool -> action)

Callback: True when going online, False when going offline

-> Sub action 

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