add<T extends Object> method

  1. @override
Registration add<T extends Object>(
  1. ComponentCodec<T> codec, {
  2. bool published = false,
})
override

Says how components of type T are written down. Throws a NameTakenException when codec's id is taken by another type.

Implementation

@override
Registration add<T extends Object>(
  ComponentCodec<T> codec, {
  bool published = false,
}) {
  final id = codec.id;
  if (_scope?.manifest.nameProblem(id, what: 'the component')
      case final problem?) {
    throw PluginException(problem);
  }
  for (final MapEntry(key: type, value: info) in _store.infos.entries) {
    if (type != T && info.id == id) {
      throw NameTakenException(
        id,
        what: 'the component',
        owner: 'the type $type',
      );
    }
  }
  final info = ComponentInfo(
    type: T,
    id: id,
    version: codec.version,
    published: published,
    declaredBy: _by,
  );
  _store.infos[T] = info;
  _store.codecs[T] = codec;
  return _track(
    Registration(() {
      if (!identical(_store.infos[T], info)) return;
      _store.infos.remove(T);
      _store.codecs.remove(T);
    }),
  );
}