subscribe<T> method
Null safety
- String topic,
- EventHandler<
T> ? handler
Subscribe to an event topic. Events that get posted to that topic will trigger the provided handler
topic
The topic to subscribe tohandler
The event handler
Implementation
subscribe<T>(String topic, EventHandler<T>? handler) {
List<EventHandler<T>>? handlers = _callbackMaps[topic];
if (handler == null) {
_callbackMaps.remove(topic);
return;
}
if (handlers == null) {
handlers = [];
_callbackMaps[topic] = handlers;
}
handlers.add(handler);
}