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
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new LocalStateStorage():
LocalStateStorage
Returns
Section titled “Returns”LocalStateStorage
Properties
Section titled “Properties”isReadOnly
Section titled “isReadOnly”
readonlyisReadOnly:boolean
Defined in: src/client/state/local-state-storage.ts:45
True in a worker, which reads what its tabs mirror and changes nothing.
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”discard()
Section titled “discard()”discard(
key):void
Defined in: src/client/state/local-state-storage.ts:95
The same as remove: this store publishes nothing beyond the origin.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”SessionState | null
Implementation of
Section titled “Implementation of”ready()
Section titled “ready()”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.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”remove()
Section titled “remove()”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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”set(
key,state):void
Defined in: src/client/state/local-state-storage.ts:80
Parameters
Section titled “Parameters”string
Omit<SessionState, "held">
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”subscribe()
Section titled “subscribe()”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.
Parameters
Section titled “Parameters”string
listener
Section titled “listener”() => void
Returns
Section titled “Returns”() => void