serialize method

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

Serializes component, dispatching by its runtime type and falling back to the first codec that claims it. Returns null when none does.

Implementation

ComponentSpec? serialize(Component component, SerializeContext context) {
  final spec =
      _byComponentType[component.runtimeType]?.serialize(
        component,
        context,
      ) ??
      _serializeByScan(component, context);
  if (spec != null) {
    if (component.enabled) {
      // Retained specs (placeholders, deferred loads) can carry a stale
      // authored value; live state wins.
      spec.properties.remove('enabled');
    } else {
      spec.properties['enabled'] = const BoolValue(false);
    }
  }
  return spec;
}