triggerComponentEvent function Null safety

void triggerComponentEvent(
  1. String eventName,
  2. int hashCode,
  3. String componentName,
  4. [String payload = '']
)

Implementation

void triggerComponentEvent(String eventName, int hashCode, String componentName, [String payload = '']) {

  bool? hasSubs = eventSubscriptions.containsKey(eventName);
  if(hasSubs) hasSubs = eventSubscriptions[eventName]?.containsKey(componentName);
  hasSubs ??= false;
  if(hasSubs) hasSubs = elementInstances.containsKey(hashCode);

  if (hasSubs) {
    var el = elementInstances[hashCode];
    eventSubscriptions[eventName]?[componentName]?.forEach((key, value) {
      var events = eventSubscriptions[eventName]?[componentName]?[key];
      events ??= [];
      for (var i = 0; i < events.length; i++) {
        Event evt = events[i];
        el ??= Elem();
        evt.target = el as Elem;
        evt.payload = payload;
        evt.callback(evt);
      }
    });

    //var elems = getElementsByName(componentName, 100);
    //int idx = elems.indexOf(el);
    /*
    if (idx != -1 &&
        eventSubscriptions[eventName][componentName].containsKey(idx)) {
      var events = eventSubscriptions[eventName][componentName][idx];
      for (var i = 0; i < events.length; i++) {
        Event evt = events[i];
        evt.target = el;
        evt.payload = payload;
        evt.callback(evt);
      }
    }
    */

  }
  // if (kIsWeb) {
  //   triggerComponentEventJS(eventName, hashCode, componentName, payload);
  // }
}