StateClient
App-scoped shared state across the live frames of ONE app — the top-level app frame plus its modal /
embedded-surface frames — brokered by the shell (so it is observable and origin-independent, unlike a
raw same-origin BroadcastChannel). The model is single-writer, many-readers: a namespace has at
most one writer; readers never write, so there is no lost-update. State is keyed by (appId, namespace)
and never crosses apps. Every snapshot must be structured-clone serializable.
Methods
Section titled “Methods”get<S>(namespace): S | undefined;The last-known snapshot for a namespace, or undefined before the first sync.
Type Parameters
Section titled “Type Parameters”S = unknown
Parameters
Section titled “Parameters”namespace
Section titled “namespace”string
Returns
Section titled “Returns”S | undefined
publish()
Section titled “publish()”publish<S>(namespace, initial): StateWriter<S>;Claim the (single) writer slot for a namespace and seed its snapshot; returns a StateWriter.
Type Parameters
Section titled “Type Parameters”S = unknown
Parameters
Section titled “Parameters”namespace
Section titled “namespace”string
initial
Section titled “initial”S
Returns
Section titled “Returns”StateWriter<S>
subscribe()
Section titled “subscribe()”subscribe<S>(namespace, handler): () => void;Observe a namespace: the current snapshot (if one exists) and every later update. Read-only; returns an unsubscribe.
Type Parameters
Section titled “Type Parameters”S = unknown
Parameters
Section titled “Parameters”namespace
Section titled “namespace”string
handler
Section titled “handler”(snapshot, rev) => void
Returns
Section titled “Returns”() => void