Skip to content

simpleComponent

simpleComponent<T>(name, schema, options?): ComponentDef<T>

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

Build a ComponentDef from a flat schema of primitives.

For a component type T whose every field is a number, boolean, or string, this helper generates serialize (shallow copy of the declared fields) and deserialize (per-field as* validation). Extra fields present on runtime values are ignored by the generated serialize; extra fields present on raw saves are ignored by deserialize.

For components with nested objects, arrays, enum narrowing, or other shaped data, write the ComponentDef by hand instead.

T extends { [K in string | number | symbol]: string | number | boolean }

string

SimpleSchema<T>

SimpleComponentOptions = {}

ComponentDef<T>

interface Position { x: number; y: number }
const PositionDef = simpleComponent<Position>('position', { x: 'number', y: 'number' });