Skip to content

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.

T

new ComponentStore<T>(clock?): ComponentStore<T>

Defined in: src/component-store.ts:136

ChangeClock = ...

Stamp source; a world passes its shared clock. Defaults to a private one.

ComponentStore<T>

readonly clock: ChangeClock

Defined in: src/component-store.ts:129

The clock this store stamps added / changed ticks from; shared by every store in a world.

ComponentStoreLike.clock

get size(): number

Defined in: src/component-store.ts:270

number

ComponentStoreLike.size

[iterator](): MapIterator<[EntityId, T]>

Defined in: src/component-store.ts:294

MapIterator<[EntityId, T]>

ComponentStoreLike.[iterator]


addedTick(id): number

Defined in: src/component-store.ts:140

Clock tick at which the entity gained this component, or 0 when absent.

EntityId

number

ComponentStoreLike.addedTick


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.

EntityId

number

ComponentStoreLike.changedTick


clear(): void

Defined in: src/component-store.ts:144

void

ComponentStoreLike.clear


delete(id): boolean

Defined in: src/component-store.ts:153

EntityId

boolean

ComponentStoreLike.delete


entries(): MapIterator<[EntityId, T]>

Defined in: src/component-store.ts:177

MapIterator<[EntityId, T]>

ComponentStoreLike.entries


get(id): T | undefined

Defined in: src/component-store.ts:235

Read a value. Not recorded as a change — mutate through getMut for that.

EntityId

T | undefined

ComponentStoreLike.get


getMut(id): T | undefined

Defined in: src/component-store.ts:237

Read a value for in-place mutation, recording the entity as changed.

EntityId

T | undefined

ComponentStoreLike.getMut


has(id): boolean

Defined in: src/component-store.ts:244

EntityId

boolean

ComponentStoreLike.has


keys(): MapIterator<EntityId>

Defined in: src/component-store.ts:246

MapIterator<EntityId>

ComponentStoreLike.keys


markChanged(id): void

Defined in: src/component-store.ts:248

Record a present entity as changed after a write the store cannot see.

EntityId

void

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.

EntityId

T

this

ComponentStoreLike.set


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.

"set"

StoreSetHandler<T>

() => void

ComponentStoreLike.subscribe

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.

"delete"

StoreDeleteHandler<T>

() => void

ComponentStoreLike.subscribe

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.

"validate"

StoreValidateHandler

() => void

ComponentStoreLike.subscribe


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.

ComponentDef<T>

unknown

ComponentStoreLike.toSerialized


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.

EntityId

void

ComponentStoreLike.validate


static fromSerialized<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.

T

unknown

string

ComponentDef<T>

ComponentStore<T>