(container: Container, eventType: string, e: Event)
| 58 | } |
| 59 | |
| 60 | function 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 | |
| 86 | function triggerEventFlow(paths: EventCallback[], se: SyntheticEvent) { |
| 87 | for (let i = 0; i < paths.length; i++) { |
no test coverage detected