MCPcopy
hub / github.com/facebook/react / emit

Method emit

packages/react-devtools-shared/src/events.js:28–57  ·  view source on GitHub ↗
(event: Event, ...args: Events[Event])

Source from the content-addressed store, hash-verified

26 }
27
28 emit<Event: $Keys<Events>>(event: Event, ...args: Events[Event]): void {
29 const listeners = this.listenersMap.get(event);
30 if (listeners !== undefined) {
31 if (listeners.length === 1) {
32 // No need to clone or try/catch
33 const listener = listeners[0];
34 listener.apply(null, args);
35 } else {
36 let didThrow = false;
37 let caughtError = null;
38
39 const clonedListeners = Array.from(listeners);
40 for (let i = 0; i < clonedListeners.length; i++) {
41 const listener = clonedListeners[i];
42 try {
43 listener.apply(null, args);
44 } catch (error) {
45 if (caughtError === null) {
46 didThrow = true;
47 caughtError = error;
48 }
49 }
50 }
51
52 if (didThrow) {
53 throw caughtError;
54 }
55 }
56 }
57 }
58
59 removeAllListeners(): void {
60 this.listenersMap.clear();

Callers 15

connectToDevToolsFunction · 0.45
handleCloseFunction · 0.45
dispatchEventFunction · 0.45
BridgeClass · 0.45
bridge.jsFile · 0.45
injectFunction · 0.45
installHookFunction · 0.45
initBackendFunction · 0.45
AgentClass · 0.45
flushPendingEventsFunction · 0.45
attachFunction · 0.45

Calls 2

getMethod · 0.65
applyMethod · 0.45

Tested by

no test coverage detected