Documentation / @super-store/store / Store
Class: Store
Defined in: store.ts:31
A Store owns one Y.Doc and mints named-root StoreValues on it, so users compose a document from independently-defined sub-stores without ever importing yjs or hand-building a Y.Doc. Named roots are deterministic across peers (doc.getMap(name)), so concurrently-constructed roots merge instead of orphaning each other (unlike nested-Y.Map embedding). See DESIGN §2.
root(name, seed, opts)— define a slice where it belongs (settings-land constructs the settings root); the top level never sees its schema.export()/load()— the rare whole-document read/write (save/restore).encodeState/applyUpdate/onUpdate— the doc-level sync surface for@super-line/store-sync; one stream carries every root.doc— escape hatch for attaching providers (y-indexeddb,y-websocket).
Constructors
Constructor
new Store(
doc?):Store
Defined in: store.ts:36
Parameters
doc?
Doc
Returns
Store
Accessors
doc
Get Signature
get doc():
Doc
Defined in: store.ts:43
The backing document. Attach persistence/sync providers here if you need raw Yjs providers instead of the @super-line/store-sync surface.
Returns
Doc
Methods
applyUpdate()
applyUpdate(
update):void
Defined in: store.ts:90
Merge a remote update. Tagged so onUpdate reports it as not-local.
Parameters
update
Uint8Array
Returns
void
dispose()
dispose():
void
Defined in: store.ts:106
Dispose every root and, if this Store created the doc, destroy it.
Returns
void
encodeState()
encodeState():
Uint8Array
Defined in: store.ts:85
Full doc state as one update, for catch-up or persistence.
Returns
Uint8Array
export()
export():
Record<string,unknown>
Defined in: store.ts:68
Gather every registered root into one plain-JSON object keyed by root name. The rare whole-document read (export/save).
Returns
Record<string, unknown>
load()
load(
data):void
Defined in: store.ts:76
Route each top-level key to its registered root's set(). Whole-document restore (loadScene); unknown keys are ignored. One transaction → one update.
Parameters
data
Record<string, unknown>
Returns
void
onUpdate()
onUpdate(
listener): () =>void
Defined in: store.ts:97
Observe outgoing updates for the whole doc. meta.local is false only for updates injected via applyUpdate — so a sync layer pushes local updates and never echoes remote merges. Returns an unsubscribe.
Parameters
listener
(update, meta) => void
Returns
() => void
root()
root<
T,M>(name,seed,options?):StoreValue<T,M>
Defined in: store.ts:50
Define (or return the existing handle for) a named root on this doc. Idempotent per name — calling twice returns the same handle, so the same concern can be set up from one place without double-binding.
Type Parameters
T
T
M
M extends StoreMode = "shallow"
Parameters
name
string
seed
T
options?
StoreRootOptions<T, M>
Returns
StoreValue<T, M>