emit method
This function triggers all the handlers currently listening
to event
and passes them data
.
Implementation
void emit(String event, [dynamic data]) {
final list0 = this._events[event];
// todo: try to optimize this. Maybe remember the off() handlers and remove later?
// handler might be off() inside handler; make a copy first
final list = list0 != null ? new List.from(list0) : null;
list?.forEach((handler) {
handler(data);
});
this._eventsOnce.remove(event)?.forEach((EventHandler handler) {
handler(data);
});
this._eventsAny.forEach((AnyEventHandler handler) {
handler(event, data);
});
}