MCPcopy Create free account
hub / github.com/BetaSu/big-react / dispatchEvent

Function dispatchEvent

packages/react-dom/src/SyntheticEvent.ts:60–84  ·  view source on GitHub ↗
(container: Container, eventType: string, e: Event)

Source from the content-addressed store, hash-verified

58}
59
60function dispatchEvent(container: Container, eventType: string, e: Event) {
61 const targetElement = e.target;
62
63 if (targetElement === null) {
64 console.warn('事件不存在target', e);
65 return;
66 }
67
68 // 1. 收集沿途的事件
69 const { bubble, capture } = collectPaths(
70 targetElement as DOMElement,
71 container,
72 eventType
73 );
74 // 2. 构造合成事件
75 const se = createSyntheticEvent(e);
76
77 // 3. 遍历captue
78 triggerEventFlow(capture, se);
79
80 if (!se.__stopPropagation) {
81 // 4. 遍历bubble
82 triggerEventFlow(bubble, se);
83 }
84}
85
86function triggerEventFlow(paths: EventCallback[], se: SyntheticEvent) {
87 for (let i = 0; i < paths.length; i++) {

Callers 1

initEventFunction · 0.85

Calls 3

collectPathsFunction · 0.85
createSyntheticEventFunction · 0.85
triggerEventFlowFunction · 0.85

Tested by

no test coverage detected