Documentation
    Preparing search index...

    Interface ComponentSerializer<T>

    How one component type crosses the document boundary (§79).

    Declared with method syntax on purpose: TypeScript's methods are bivariant in their parameters, which is what lets a ComponentSerializer<PoseTarget> be stored in a registry that hands out ComponentSerializer<Component>. The substitution is sound here because the registry is keyed by typeName, so the component a serializer is handed is always an instance of the very class it was registered with.

    interface ComponentSerializer<T extends Component> {
        deserialize(data: JsonValue, node: Node): T;
        serialize(component: T): JsonValue;
    }

    Type Parameters

    Index
    • Rebuilds the component from a payload.

      node is the node the component is about to be attached to, for the rare component that needs it while constructing. Attaching is the caller's job: instantiateScene calls node.addComponent on the returned instance. A deserializer that attaches it itself is harmless — §6a's registry treats re-adding the same instance as a no-op — but it is not required.

      Parameters

      Returns T

    • Produces the component's payload. Must return representable JSON — the document validator refuses anything else, naming the field.

      Parameters

      • component: T

      Returns JsonValue