Documentation / @super-store/store / StoreValue
Class: StoreValue<T>
Defined in: store-value.ts:133
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
Constructors
Constructor
new StoreValue<
T>(value,options?):StoreValue<T>
Defined in: store-value.ts:164
Parameters
value
T
options?
Returns
StoreValue<T>
Properties
_debug
protected_debug:boolean
Defined in: store-value.ts:139
_name
protected_name:string
Defined in: store-value.ts:138
_partialUpdateSupported
protected_partialUpdateSupported:boolean
Defined in: store-value.ts:137
_shape
protected_shape:Shape<keyofT>
Defined in: store-value.ts:140
_value
protected_value:T
Defined in: store-value.ts:134
getSnapshot
getSnapshot: () =>
InferStoreValueSnapshot<T>
Defined in: store-value.ts:144
Returns
isEqual
protectedisEqual: (a,b) =>boolean
Defined in: store-value.ts:136
Parameters
a
T
b
T
Returns
boolean
listeners
protectedlisteners:Set<() =>void>
Defined in: store-value.ts:135
subscribe
subscribe: (
listener) => () =>void
Defined in: store-value.ts:145
Parameters
listener
() => void
Returns
() => void
Accessors
canRedo
Get Signature
get canRedo():
boolean
Defined in: store-value.ts:387
Returns
boolean
canUndo
Get Signature
get canUndo():
boolean
Defined in: store-value.ts:383
Returns
boolean
doc
Get Signature
get doc():
Doc
Defined in: store-value.ts:195
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:392
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:189
Returns
T
Methods
_getSnapshot()
_getSnapshot():
InferStoreValueSnapshot<T>
Defined in: store-value.ts:447
Returns
_subscribe()
_subscribe(
listener): () =>void
Defined in: store-value.ts:326
Parameters
listener
() => void
Returns
() => void
applyUpdate()
applyUpdate(
update):void
Defined in: store-value.ts:226
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:340
Tear down observers and, if this store created its own private doc, destroy it.
Returns
void
emitChange()
emitChange():
void
Defined in: store-value.ts:333
Returns
void
enableUndo()
enableUndo(
options?):void
Defined in: store-value.ts:361
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:216
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:202
The backing Yjs shared type. Lazily binds (private doc) if needed.
Returns
AbstractType<unknown>
onUpdate()
onUpdate(
listener): () =>void
Defined in: store-value.ts:236
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:379
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:396
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:253
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:374
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:284
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
StoreUpdate<T>
Returns
boolean