Documentation / @super-store/store / StoreValue
Class: StoreValue<T, M>
Defined in: store-value.ts:180
Reactive primitive backed by Yjs. A StoreValue is a typed handle over a Yjs shared type. It has two backing modes:
- unbound — a plain in-memory value (identical semantics to the original in-memory store). This is the state for local-only stores and for children that have not yet been adopted by a bound parent.
- bound — backed by a Yjs type inside a
Y.Doc. Reads materialise from the doc; writes go throughdoc.transactas a diff-and-patch; reactivity is driven byobserveDeep.
Binding is lazy and cascades from the root: a root binds when a doc is injected or on first access to .doc / .getYType(); nested children bind when their parent binds (their value is copied into a nested Y type and their handle repointed — instance identity is preserved).
Type Parameters
T
T
M
M extends StoreMode = "shallow"
Constructors
Constructor
new StoreValue<
T,M>(value,options?):StoreValue<T,M>
Defined in: store-value.ts:216
Parameters
value
T
options?
StoreValueOptions<T, M>
Returns
StoreValue<T, M>
Properties
_debug
protected_debug:boolean
Defined in: store-value.ts:186
_name
protected_name:string
Defined in: store-value.ts:185
_partialUpdateSupported
protected_partialUpdateSupported:boolean
Defined in: store-value.ts:184
_shape
protected_shape:Shape<keyofT>
Defined in: store-value.ts:187
_value
protected_value:T
Defined in: store-value.ts:181
getSnapshot
getSnapshot: () =>
InferStoreValueSnapshot<T>
Defined in: store-value.ts:191
Returns
isEqual
protectedisEqual: (a,b) =>boolean
Defined in: store-value.ts:183
Parameters
a
T
b
T
Returns
boolean
listeners
protectedlisteners:Set<() =>void>
Defined in: store-value.ts:182
subscribe
subscribe: (
listener) => () =>void
Defined in: store-value.ts:192
Parameters
listener
() => void
Returns
() => void
Accessors
canRedo
Get Signature
get canRedo():
boolean
Defined in: store-value.ts:452
Returns
boolean
canUndo
Get Signature
get canUndo():
boolean
Defined in: store-value.ts:448
Returns
boolean
doc
Get Signature
get doc():
Doc
Defined in: store-value.ts:249
The backing Yjs document. Accessing it lazily binds an unbound store to a private in-memory doc. Attach persistence/sync providers here.
Returns
Doc
undoManager
Get Signature
get undoManager():
UndoManager|null
Defined in: store-value.ts:457
The underlying Yjs UndoManager, or null if undo is not enabled.
Returns
UndoManager | null
value
Get Signature
get value():
T
Defined in: store-value.ts:243
Returns
T
Methods
_getSnapshot()
_getSnapshot():
InferStoreValueSnapshot<T>
Defined in: store-value.ts:512
Returns
_subscribe()
_subscribe(
listener): () =>void
Defined in: store-value.ts:391
Parameters
listener
() => void
Returns
() => void
applyUpdate()
applyUpdate(
update):void
Defined in: store-value.ts:280
Merge an update produced by another store's encodeState/onUpdate. Tagged so onUpdate reports it as not-local (it must not be echoed back), and so an opt-in UndoManager never undoes a remote merge. Drives reactivity (snapshot rebuild + listeners) exactly like a local write.
Parameters
update
Uint8Array
Returns
void
dispose()
dispose():
void
Defined in: store-value.ts:405
Tear down observers and, if this store created its own private doc, destroy it.
Returns
void
emitChange()
emitChange():
void
Defined in: store-value.ts:398
Returns
void
enableUndo()
enableUndo(
options?):void
Defined in: store-value.ts:426
Attach a Yjs UndoManager scoped to this root, tracking only this store's own (STORE_ORIGIN) writes — remote merges are never undone. Lazily binds to a private doc if unbound. Idempotent. captureTimeout (default 0) controls how aggressively consecutive writes merge into one undo step.
Parameters
options?
captureTimeout?
number
Returns
void
encodeState()
encodeState():
Uint8Array
Defined in: store-value.ts:270
The full document state as a single update, for a catch-up snapshot or persistence. Apply it to another store with applyUpdate.
Returns
Uint8Array
getYType()
getYType():
AbstractType<unknown>
Defined in: store-value.ts:256
The backing Yjs shared type. Lazily binds (private doc) if needed.
Returns
AbstractType<unknown>
onUpdate()
onUpdate(
listener): () =>void
Defined in: store-value.ts:290
Observe outgoing CRDT updates. meta.local is true for changes this store produced (user writes and undo/redo) and false for ones injected via applyUpdate — so a sync layer pushes only local updates and avoids echoing remote merges. Returns an unsubscribe.
Parameters
listener
(update, meta) => void
Returns
() => void
redo()
redo():
void
Defined in: store-value.ts:444
Redo the last undone change. No-op if undo is not enabled.
Returns
void
select()
select<
R>(selector,isEqual?):object
Defined in: store-value.ts:461
Type Parameters
R
R
Parameters
selector
(snapshot) => R
isEqual?
(a, b) => boolean
Returns
object
getSnapshot
getSnapshot: () =>
R
Returns
R
subscribe
subscribe: (
listener) => () =>void
Parameters
listener
() => void
Returns
() => void
set()
set(
value):boolean
Defined in: store-value.ts:307
Replace the value. In bound mode this is a recursive diff-and-patch inside a single transaction — unchanged data is never rewritten (so the doc does not bloat and concurrent edits merge). Returns true iff the value was considered changed under isEqual.
Parameters
value
T
Returns
boolean
undo()
undo():
void
Defined in: store-value.ts:439
Undo the last tracked local change. No-op if undo is not enabled. The resulting Yjs change flows through the normal observer, so listeners fire and the snapshot refreshes.
Returns
void
update()
update(
value):boolean
Defined in: store-value.ts:338
Apply a partial update. Object stores only. Plain keys are merged; nested StoreValue children receive a recursive update() so partial updates propagate without losing child identity. In bound mode the whole update is one transaction (one emit per affected handle).
Parameters
value
UpdateArg<T, M>
Returns
boolean