setHandler<T> method

  1. @override
void setHandler<T>({
  1. T? initalData,
  2. String? path,
  3. String? target,
  4. required Handler<T> handler,
})
override

Sets a handler for a specific topic. If an EventNode already exists for that topic, it updates the handler. Otherwise, it creates a new EventNode with the handler and initial data.

Implementation

@override
void setHandler<T>({T? initalData, String? path, String? target, required Handler<T> handler}) {
  var t = Topic.create<T>(path: path, target: target);
  var node = _eventsMap[t];
  if (node != null && node is EventNode<T>) {
    node.handler = handler;
  } else {
    _eventsMap[t] = EventNode<T>(handler: handler, lastData: initalData);
  }
}