Function: webStorageAdapter
webStorageAdapter(
area):StorageAdapter
A StorageAdapter over a Web Storage area (localStorage, sessionStorage), the shape
a web app stores pending swaps in: the value lands under the key as JSON text. A missing key
resolves undefined. CORRUPT JSON resolves as the raw string, never a rejection (the store
reads a value that is not an array as "no entries" and the next write repairs it, whereas a
get that rejects forever would make every remember a no-op). A throwing area (storage blocked
by the browser, quota exceeded on setItem) rejects, which the store treats as "storage
unavailable".
Pass a FUNCTION that returns the area to look it up at each call instead of when the adapter is
built: where localStorage does not exist (server rendering, a test, a blocked context)
the access throws inside the function, which is the same "storage unavailable" rejection, and
the module that builds the adapter still loads.
storage adapter local session set item
Parameters
| Parameter | Type |
|---|---|
area | WebStorageLike | (() => WebStorageLike) |
web storage like
Returns
storage adapter
Example
const store = new PendingSwapStore(webStorageAdapter(() => localStorage));