Element.prototype.removeEventListener = function()

in libs/core/src/lib/renderer/geteventlisteners.ts [35:63]


Element.prototype.removeEventListener = function<K extends keyof ElementEventMap>(
  type: K,
  listener: (this: Element, ev: ElementEventMap[K]) => any,
  options?: boolean | EventListenerOptions
): void {
  if (options === undefined) options = false;

  // remove listener
  this._removeEventListener(type, listener, options);

  if (!this.eventListenerList) this.eventListenerList = {};
  if (!this.eventListenerList[type]) this.eventListenerList[type] = [];

  // Find the event in the list, If a listener is registered twice, one
  // with capture and one without, remove each one separately. Removal of
  // a capturing listener does not affect a non-capturing version of the
  // same listener, and vice versa.
  for (let i = 0; i < this.eventListenerList[type].length; i++) {
    if (
      this.eventListenerList[type][i].listener === listener &&
      this.eventListenerList[type][i].useCapture === options
    ) {
      this.eventListenerList[type].splice(i, 1);
      break;
    }
  }
  // if no more events of the removed event type are left,remove the group
  if (this.eventListenerList[type].length == 0) delete this.eventListenerList[type];
};