| 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.Cookie
Contents
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 = CookiesChangedCookieChangeEventsubs :: [SubAction] subs = [cookieChangeSubCookiesChanged ] update :: Action ->Effectp props Model Action update (CookiesChanged ev) =io_(consoleLog (ms (show (cookiesChangedev))))
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
- Miso.Cookie —
cookieGet,cookieSet,cookieDelete,cookieGetAll - Miso.Subscription.Util —
createSubused internally - Miso.Subscription — re-export hub
Synopsis
- cookieChangeSub :: (CookieChangeEvent -> action) -> Sub action
Subscriptions
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