serialize method
Serializes component to a ComponentSpec, or returns null if this codec
does not handle that component instance.
The default implementation derives the spec from propertySchema: when claims accepts the component, each property's value is read through its ComponentPropertyDef.read. Codecs whose serialization is not a flat field read (a mesh recovering resource ids) override this.
Implementation
ComponentSpec? serialize(Component component, SerializeContext context) {
if (!claims(component)) return null;
return ComponentSpec(
type,
properties: {
for (final def in propertySchema) def.name: def.read!(component),
},
);
}