extend method

A2uiCatalog extend({
  1. required String id,
  2. Iterable<A2uiCatalogComponent> components = const [],
  3. Iterable<A2uiCatalogFunction> functions = const [],
  4. String? instructions,
})

Returns a copy under a new id with components and functions added, for extending a base catalog with bespoke components.

An entry named like one of this catalog's replaces it; overriding a component changes its Express positional signature, so do it deliberately. Names within each argument must be unique. instructions, when given, replaces this catalog's (pass '' to clear them). The base document's title and description are not carried over.

Implementation

A2uiCatalog extend({
  required String id,
  Iterable<A2uiCatalogComponent> components = const [],
  Iterable<A2uiCatalogFunction> functions = const [],
  String? instructions,
}) => A2uiCatalog._(
  id: id,
  components: {...this.components, ..._byName(components, (c) => c.name)},
  functions: {...this.functions, ..._byName(functions, (f) => f.name)},
  defs: defs,
  instructions: switch (instructions ?? this.instructions) {
    '' => null,
    final i => i,
  },
  extra: {
    for (final MapEntry(:key, :value) in _extra.entries)
      if (!_documentOnly.contains(key)) key: value,
  },
);