on method

EventEmitterListener on({
  1. required String eventName,
  2. required FutureOr onCallback(
    1. EventEmitterListener listener,
    2. dynamic update
    ),
  3. Map? stateData,
})

Implementation

EventEmitterListener on({
  required String eventName,
  required FutureOr<dynamic> Function(
          EventEmitterListener listener, dynamic update)
      onCallback,
  Map? stateData,
}) {
  final Map<String, EventEmitterListener> event_datas =
      events.putIfAbsent(eventName, () {
    return {};
  });

  final EventEmitterListener eventEmitterListenerGeneralLib =
      EventEmitterListener(
    stateData: stateData ?? {},
  );
  eventEmitterListenerGeneralLib.ensureInitiaLized(
    eventName: eventName,
    eventUniqueId: generateNewUniqueId(event_datas: event_datas),
    onUpdate: onCallback,
    onCancel: (event) {
      event_datas.remove(event.event_unique_id);
      remove(eventName: eventName, uniqueId: event.event_unique_id);
      event.dispose();
    },
  );
  event_datas[eventEmitterListenerGeneralLib.event_unique_id] =
      eventEmitterListenerGeneralLib;
  return eventEmitterListenerGeneralLib;
}