serialize method

  1. @override
ComponentSpec? serialize(
  1. Component component,
  2. SerializeContext context
)
override

Serializes component to a ComponentSpec, or returns null if this codec does not handle that component instance.

The returned spec must be freshly built (or a copy); the registry adjusts its properties in place, so a spec aliased by the live component (a retained placeholder spec) would see snapshots change retroactively.

Implementation

@override
ComponentSpec? serialize(Component component, SerializeContext context) {
  if (!claims(component)) return null;
  final spec = (component as ForeignComponent).spec;
  return ComponentSpec(spec.type, properties: {...spec.properties});
}