Skip to content

LocalStateStorage

Defined in: src/client/state/local-state-storage.ts:38

State in localStorage, so every tab of an origin agrees on it and it survives a reload.

Workers cannot read localStorage, so a tab mirrors each record it writes or subscribes to into IndexedDB and announces it, and a worker loads the mirror into memory. A worker changes nothing: signing in and out happens in a page.

The two fields are written as <principal>|<expiration> rather than JSON, because an expiration is a bigint and JSON has no way to carry one.

implements StateStorage

new LocalStateStorage(): LocalStateStorage

LocalStateStorage

readonly isReadOnly: boolean

Defined in: src/client/state/local-state-storage.ts:45

True in a worker, which reads what its tabs mirror and changes nothing.

StateStorage.isReadOnly

discard(key): void

Defined in: src/client/state/local-state-storage.ts:95

The same as remove: this store publishes nothing beyond the origin.

string

void

StateStorage.discard


get(key): SessionState | null

Defined in: src/client/state/local-state-storage.ts:61

The state, or null where nothing is signed in within this store’s reach.

string

SessionState | null

StateStorage.get


ready(): Promise<void>

Defined in: src/client/state/local-state-storage.ts:53

Resolves once a worker has loaded the keys subscribed to so far, and every load queued meanwhile.

Promise<void>

StateStorage.ready


remove(key): void

Defined in: src/client/state/local-state-storage.ts:87

Removes the state, and anything this store publishes beyond this origin.

What signing out does: the user ended the sign-in, so a sibling reading a shared record must stop seeing one.

string

void

StateStorage.remove


set(key, state): void

Defined in: src/client/state/local-state-storage.ts:80

string

Omit<SessionState, "held">

void

StateStorage.set


subscribe(key, listener): () => void

Defined in: src/client/state/local-state-storage.ts:107

Fires when the state changes, here or in another tab of this origin.

localStorage raises storage in every tab except the one that wrote, so that event carries a change between tabs and a same-tab write is announced directly. Either way the record is readable before it is announced, so a listener asking who is signed in sees what it was told about.

string

() => void

() => void

StateStorage.subscribe