Skip to content

ComponentDef

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

Schema definition for a component type — handles serialization, optional dependency declarations, and optional schema evolution.

T

readonly optional columns?: readonly ColumnField[]

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

When present, the component is all-numeric and stored columnar (Structure-of-Arrays): one typed-array column per field, each with its own element kind. Set automatically by simpleComponent when every schema field is numeric. world.registerComponent uses it to pick a columnar ColumnStore over the object-backed ComponentStore. Never set for components with a boolean / string field or a hand-written serialize / deserialize.

Per-field precision is explicit via NumericColumnKind: 'number' is f64 (lossless, the safe default — entity-id refs and large counters stay exact), and a hot spatial field opts into 'f32' for half-size, cache-friendlier storage.


deserialize: (raw, label) => T

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

unknown

string

T


readonly optional migrations?: Readonly<Record<number, ComponentMigration>>

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

Per-version upgrade functions. migrations[n] transforms a raw value serialized at version n into the shape expected at version n + 1. The chain runs from the saved version up to def.version before the final deserialize.

A save written with no version info (legacy array shape) is treated as version 0, so migrations[0], migrations[1], … are applied in order.


readonly name: string

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


readonly optional requires?: readonly string[]

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

Other component names that must be present on the same entity.


serialize: (value) => unknown

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

T

unknown


readonly optional version?: number

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

Current schema version of this component. Defaults to 0 (unversioned). When > 0, ComponentStore.toSerialized wraps the payload with { version, entries } so loaders know which migrations to apply.