setHandler<T> method
void
setHandler<T>({})
override
Sets a handler for a specific topic. If initialData is provided, it will be used as the initial data for the topic.
Implementation
@override
void setHandler<T>({
T? initialData,
List<String>? paths,
String? separator,
required Handler<T> handler,
}) {
_checkNotDisposed();
final topic = Topic.create<T>(
paths: paths, separator: separator ?? defaultTopicPathSeparator);
final node = _nodeFor<T>(topic);
if (initialData != null) {
node.currentData = initialData;
}
_requestHandlers[topic] = RequestHandler(
topic: topic,
accepts: (data) => data is T,
invoke: (dto, lastData) {
final typed = EventDTO<T>(dto.data as T,
topic: dto.topic, arguments: dto.arguments);
return handler(typed, lastData as T?);
},
);
}