ComponentStore
Defined in: src/component-store.ts:126
Map from EntityId to component data, with change ticks and lifecycle hooks.
set() and getMut record a change; mutating the object returned by
get() does not (call markChanged, or use getMut).
Lifecycle hooks are exposed via subscribe(event, fn) and returns an
unsubscribe function. Multiple observers are supported: the spatial index,
DEV-mode dependency validation, dev inspectors, and plugins can all attach
independently without clobbering each other.
Emission order within set(): validate → delete (if replacing an
existing value) → set.
Type Parameters
Section titled “Type Parameters”T
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ComponentStore<
T>(clock?):ComponentStore<T>
Defined in: src/component-store.ts:136
Parameters
Section titled “Parameters”clock?
Section titled “clock?”ChangeClock = ...
Stamp source; a world passes its shared clock. Defaults to a private one.
Returns
Section titled “Returns”ComponentStore<T>
Properties
Section titled “Properties”
readonlyclock:ChangeClock
Defined in: src/component-store.ts:129
The clock this store stamps added / changed ticks from; shared by every store in a world.
Implementation of
Section titled “Implementation of”Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get size():
number
Defined in: src/component-store.ts:270
Returns
Section titled “Returns”number
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”[iterator]()
Section titled “[iterator]()”[iterator]():
MapIterator<[EntityId,T]>
Defined in: src/component-store.ts:294
Returns
Section titled “Returns”MapIterator<[EntityId, T]>
Implementation of
Section titled “Implementation of”addedTick()
Section titled “addedTick()”addedTick(
id):number
Defined in: src/component-store.ts:140
Clock tick at which the entity gained this component, or 0 when absent.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”number
Implementation of
Section titled “Implementation of”changedTick()
Section titled “changedTick()”changedTick(
id):number
Defined in: src/component-store.ts:142
Clock tick of the entity’s last recorded change (insert included), or 0 when absent.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”number
Implementation of
Section titled “Implementation of”ComponentStoreLike.changedTick
clear()
Section titled “clear()”clear():
void
Defined in: src/component-store.ts:144
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”delete()
Section titled “delete()”delete(
id):boolean
Defined in: src/component-store.ts:153
Parameters
Section titled “Parameters”Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”entries()
Section titled “entries()”entries():
MapIterator<[EntityId,T]>
Defined in: src/component-store.ts:177
Returns
Section titled “Returns”MapIterator<[EntityId, T]>
Implementation of
Section titled “Implementation of”get(
id):T|undefined
Defined in: src/component-store.ts:235
Read a value. Not recorded as a change — mutate through getMut for that.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”T | undefined
Implementation of
Section titled “Implementation of”getMut()
Section titled “getMut()”getMut(
id):T|undefined
Defined in: src/component-store.ts:237
Read a value for in-place mutation, recording the entity as changed.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”T | undefined
Implementation of
Section titled “Implementation of”has(
id):boolean
Defined in: src/component-store.ts:244
Parameters
Section titled “Parameters”Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”keys()
Section titled “keys()”keys():
MapIterator<EntityId>
Defined in: src/component-store.ts:246
Returns
Section titled “Returns”MapIterator<EntityId>
Implementation of
Section titled “Implementation of”markChanged()
Section titled “markChanged()”markChanged(
id):void
Defined in: src/component-store.ts:248
Record a present entity as changed after a write the store cannot see.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”ComponentStoreLike.markChanged
set(
id,value):this
Defined in: src/component-store.ts:254
Insert or replace a component value. Fires validate → delete (if replacing) → set handlers.
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”this
Implementation of
Section titled “Implementation of”subscribe()
Section titled “subscribe()”Call Signature
Section titled “Call Signature”subscribe(
event,fn): () =>void
Defined in: src/component-store.ts:275
Register a handler for a store event. Returns an unsubscribe function. Multiple handlers per event are supported; they run in registration order.
Parameters
Section titled “Parameters”"set"
Returns
Section titled “Returns”() => void
Implementation of
Section titled “Implementation of”Call Signature
Section titled “Call Signature”subscribe(
event,fn): () =>void
Defined in: src/component-store.ts:276
Register a handler for a store event. Returns an unsubscribe function. Multiple handlers per event are supported; they run in registration order.
Parameters
Section titled “Parameters”"delete"
Returns
Section titled “Returns”() => void
Implementation of
Section titled “Implementation of”Call Signature
Section titled “Call Signature”subscribe(
event,fn): () =>void
Defined in: src/component-store.ts:277
Register a handler for a store event. Returns an unsubscribe function. Multiple handlers per event are supported; they run in registration order.
Parameters
Section titled “Parameters”"validate"
Returns
Section titled “Returns”() => void
Implementation of
Section titled “Implementation of”toSerialized()
Section titled “toSerialized()”toSerialized(
def):unknown
Defined in: src/component-store.ts:303
Serialize all entries for persistence. Returns a plain [id, value]
tuple array when the component is unversioned (def.version is
unset or 0), for backward compatibility. Versioned components
emit { version, entries: [[id, value], ...] } so loaders can pick
the right migration chain.
Parameters
Section titled “Parameters”ComponentDef<T>
Returns
Section titled “Returns”unknown
Implementation of
Section titled “Implementation of”ComponentStoreLike.toSerialized
validate()
Section titled “validate()”validate(
id):void
Defined in: src/component-store.ts:315
Fire all validate handlers for a given id. Used by World for post-spawn dependency checks.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”fromSerialized()
Section titled “fromSerialized()”
staticfromSerialized<T>(raw,label,def):ComponentStore<T>
Defined in: src/component-store.ts:185
Reconstruct a store from serialized data. Accepts both the legacy
tuple array and the versioned { version, entries } wrapper; when
the saved version is lower than def.version, the relevant entries
in def.migrations are applied in order before def.deserialize.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”unknown
string
ComponentDef<T>
Returns
Section titled “Returns”ComponentStore<T>