dispatchEvent static method

dynamic dispatchEvent(
  1. String type, [
  2. Object? payload
])

Dispatch event on given type with payload.

Since we use LinkedHashSet to store listeners internally, so all listeners will be called in the order they are added.

Implementation

static dispatchEvent(String type, [Object? payload]) {
  final listeners = _registry[type];
  if (listeners != null) {
    for (final listener in listeners) {
      listener(payload);
    }
  }
}