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

Description

Overview

Miso.Subscription.Cookie provides cookieChangeSub, an optional subscription that delivers cookieStore change events into the update loop. Each event carries the list of cookies that were added/updated and the list that were deleted since the last event.

The subscription is optional — applications that only need one-shot reads and writes can use cookieGet, cookieSet, and cookieDelete directly without registering a subscription.

Quick start

import Miso
import Miso.Subscription.Cookie
import Miso.Cookie (CookieChangeEvent (..))

data Action = CookiesChanged CookieChangeEvent

subs :: [Sub Action]
subs = [ cookieChangeSub CookiesChanged ]

update :: Action -> Effect p props Model Action
update (CookiesChanged ev) =
  io_ (consoleLog (ms (show (cookiesChanged ev))))

Availability

The CookieStore API requires a secure context (HTTPS or localhost) and is not yet supported in all browsers. The subscription silently does nothing when cookieStore is unavailable.

See also

Synopsis

Subscriptions

cookieChangeSub Source #

Arguments

:: (CookieChangeEvent -> action)

Callback: receives the change event on every cookie modification

-> Sub action 

Returns a Sub that fires an action on every cookieStore change event, carrying the decoded CookieChangeEvent (changed and deleted cookie lists).

The subscription is self-contained: it registers the listener on mount and removes it on unmount via createSub.

https://developer.mozilla.org/en-US/docs/Web/API/CookieStore/change_event