MCPcopy
hub / github.com/marktext/marktext / emit

Method emit

packages/muya/src/event/index.ts:119–132  ·  view source on GitHub ↗

* emit custom event

(event: string, ...data: unknown[])

Source from the content-addressed store, hash-verified

117 * emit custom event
118 */
119 emit(event: string, ...data: unknown[]) {
120 const eventListener = this.listeners[event];
121
122 if (eventListener && Array.isArray(eventListener)) {
123 // Snapshot before iterating: a once-listener removes itself via
124 // off() during emit, which mutates the same array and causes
125 // forEach to skip the adjacent element. Iterate a copy instead.
126 eventListener.slice().forEach(({ listener, once }) => {
127 listener(...data);
128 if (once)
129 this.off(event, listener);
130 });
131 }
132 }
133
134 /**
135 * Remove all pub/sub subscriptions. Called from muya.destroy() to

Callers 15

_bindFocusBlurEventsMethod · 0.80
setSelectionMethod · 0.80
dispatchMethod · 0.80
_emitStateChangeMethod · 0.80
overHandlerFunction · 0.80
outHandlerFunction · 0.80
hideFunction · 0.80
showFunction · 0.80
TableDragBarClass · 0.80
selectItemMethod · 0.80

Calls 2

offMethod · 0.95
forEachMethod · 0.45

Tested by

no test coverage detected