declare<T extends BusEvent> method
Registration
declare<T extends BusEvent>(
- String name, {
- BusChannel channel = BusChannel.step,
- String? description,
- EventCodec<
T> ? codec,
override
Says that events of type T are published under name, so a tool can
list them and two plugins cannot claim one name.
codec, when given, is how the event is written for a run file, the
network, a tool and the view's PublishedState, and what its digest is
taken of (see EventCodec).
A step-channel event has one. The view reads a step's events encoded, and a replay digests what the codec writes, so an event published on the step channel without a declared codec is a bug: the engine's bus asserts it in a debug build, naming the event. Only a frame-channel event, which no replay sees, may go without.
Throws a NameTakenException naming both claimants when name is
taken.
Implementation
@override
Registration declare<T extends BusEvent>(
String name, {
BusChannel channel = BusChannel.step,
String? description,
EventCodec<T>? codec,
}) {
if (_scope?.manifest.nameProblem(name, what: 'the event')
case final problem?) {
throw PluginException(problem);
}
if (_store.declared.any((d) => d.name == name)) {
throw NameTakenException(name, what: 'the event');
}
final declaration = EventDeclaration(
name: name,
type: T,
channel: channel,
declaredBy: _scope?.manifest.id ?? 'app',
description: description,
codec: codec as EventCodec<BusEvent>?,
);
_store.declared.add(declaration);
return _track(Registration(() => _store.declared.remove(declaration)));
}