MCPcopy
hub / github.com/di-sukharev/opencommit / dispatchEvent

Function dispatchEvent

out/cli.cjs:10294–10342  ·  view source on GitHub ↗

* Dispatch a given event. * @param {Event|{type:string}} event The event to dispatch. * @returns {boolean} `false` if canceled.

(event)

Source from the content-addressed store, hash-verified

10292 * @returns {boolean} `false` if canceled.
10293 */
10294 dispatchEvent(event) {
10295 if (event == null || typeof event.type !== "string") {
10296 throw new TypeError('"event.type" should be a string.');
10297 }
10298 const listeners = getListeners(this);
10299 const eventName = event.type;
10300 let node = listeners.get(eventName);
10301 if (node == null) {
10302 return true;
10303 }
10304 const wrappedEvent = wrapEvent(this, event);
10305 let prev = null;
10306 while (node != null) {
10307 if (node.once) {
10308 if (prev !== null) {
10309 prev.next = node.next;
10310 } else if (node.next !== null) {
10311 listeners.set(eventName, node.next);
10312 } else {
10313 listeners.delete(eventName);
10314 }
10315 } else {
10316 prev = node;
10317 }
10318 setPassiveListener(
10319 wrappedEvent,
10320 node.passive ? node.listener : null
10321 );
10322 if (typeof node.listener === "function") {
10323 try {
10324 node.listener.call(this, wrappedEvent);
10325 } catch (err) {
10326 if (typeof console !== "undefined" && typeof console.error === "function") {
10327 console.error(err);
10328 }
10329 }
10330 } else if (node.listenerType !== ATTRIBUTE && typeof node.listener.handleEvent === "function") {
10331 node.listener.handleEvent(wrappedEvent);
10332 }
10333 if (isStopped(wrappedEvent)) {
10334 break;
10335 }
10336 node = node.next;
10337 }
10338 setPassiveListener(wrappedEvent, null);
10339 setEventPhase(wrappedEvent, 0);
10340 setCurrentTarget(wrappedEvent, null);
10341 return !wrappedEvent.defaultPrevented;
10342 }
10343 };
10344 Object.defineProperty(EventTarget2.prototype, "constructor", {
10345 value: EventTarget2,

Callers

nothing calls this directly

Calls 10

getListenersFunction · 0.85
wrapEventFunction · 0.85
setPassiveListenerFunction · 0.85
isStoppedFunction · 0.85
setEventPhaseFunction · 0.85
setCurrentTargetFunction · 0.85
getMethod · 0.45
setMethod · 0.45
deleteMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…