BrowserKeyValueStore
Browser-backed KeyValueStore layers for client-side Effect programs.
This module provides browser implementations of the unstable persistence KeyValueStore service. Use layerLocalStorage for small origin-scoped values that should survive reloads and browser restarts, use layerSessionStorage for tab / page-session state, and use layerIndexedDb when the store should be asynchronous and backed by IndexedDB. The IndexedDB layer requires the browser IndexedDb service and accepts an optional database name.
Layers
layerIndexedDb
Added in v4.0.0
Source
Signature
declare function layerIndexedDb(options?: {
readonly database?: string;
}): Layer<KeyValueStore, never, IndexedDb>;layerLocalStorage
Added in v4.0.0
Source
Creates a KeyValueStore layer that uses the browser's localStorage API and stores values between browser sessions.
Signature
declare const layerLocalStorage: Layer.Layer<KeyValueStore.KeyValueStore>;layerSessionStorage
Added in v4.0.0
Source
Creates a KeyValueStore layer that uses the browser's sessionStorage API and stores values only for the current session.
Signature
declare const layerSessionStorage: Layer.Layer<KeyValueStore.KeyValueStore>;
Creates a
KeyValueStorelayer backed by IndexedDB.When to use
Use when you need persistent asynchronous IndexedDB storage for a browser
KeyValueStoreinstead of the synchronous Web Storage APIs.Details
The database name defaults to
"effect_key_value_store". The layer requires theIndexedDbservice and stores string andUint8Arrayvalues in the same backing object store.Gotchas
IndexedDB may be unavailable or blocked by browser settings, private browsing, quota limits, or restricted contexts. The string and
Uint8Arrayaccessors do not coerce values stored with the other representation.See
layerLocalStoragefor synchronous persistent Web StoragelayerSessionStoragefor synchronous tab-session Web Storage