fn
createCookieStoreAdapter
v0.0.14testeddemoCookieStorageLike adapter over the
Cookie Store API:
async reads/writes plus a change-event subscription that observes other
tabs, server Set-Cookie responses, and expiry. The API can only write
Secure cookies, so secure: false is rejected — use
createDocumentCookieAdapter for that.
Example
ts
const store = createCookieStoreAdapter(window.cookieStore);Demo
Loading demo…
Signature
ts
export function createCookieStoreAdapter(cookieStore: CookieStore): CookieStorageLike{ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
cookieStore | CookieStore | The window.cookieStore instance to wrap |
Returns
CookieStorageLikeThe adapter| Property | Type | Description |
|---|---|---|
getItem | (name: string) => string | null | Promise<string | null> | Read the raw (encoded) cookie value, null when absent. |
setItem | (name: string, value: string, attributes: CookieAttributes) => void | Promise<void> | Write the raw value. Attributes carry the cookie's scope and lifetime. |
removeItem | (name: string, attributes: CookieAttributes) => void | Promise<void> | Delete the cookie. Attributes carry the identity (path/domain) the
deletion must repeat to match. |
onChange? | (name: string, callback: (newValue: string | null) => void) => () => void | Optional: observe changes of the given cookie (other tabs, server
Set-Cookie responses, other instances). The callback receives the new
raw value (null = deleted). Returns an unsubscribe function. |
echoesOwnWrites? | boolean | Whether onChange also reports this context's own writes (e.g. the
Cookie Store API change event does, a BroadcastChannel does not). The
composable uses this to know when an own write will come back as a
notification that must be swallowed instead of re-applied. |