Skip to content

Commit 9449dfb

Browse files
committed
refactor: events tweak
1 parent 85bcc2b commit 9449dfb

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

Diff for: packages/runtime-dom/src/modules/events.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function patchEvent(
1717
}
1818

1919
const eventCounts: Record<string, number> = {}
20-
const attachedGlobalHandlers: Record<string, Function> = {}
20+
const attachedGlobalHandlers: Record<string, Function | null> = {}
2121

2222
export function handleDelegatedEvent(
2323
el: any,
@@ -38,18 +38,16 @@ export function handleDelegatedEvent(
3838
}
3939
store[name] = value
4040
} else if (store && store[name]) {
41-
eventCounts[name]--
42-
store[name] = null
43-
if (count === 1) {
41+
if (--eventCounts[name] === 0) {
4442
removeGlobalHandler(name)
4543
}
44+
store[name] = null
4645
}
4746
}
4847

4948
function attachGlobalHandler(name: string) {
5049
const handler = (attachedGlobalHandlers[name] = (e: Event) => {
51-
const { type } = e
52-
const isClick = type === 'click' || type === 'dblclick'
50+
const isClick = e.type === 'click' || e.type === 'dblclick'
5351
if (isClick && (e as MouseEvent).button !== 0) {
5452
e.stopPropagation()
5553
return false
@@ -114,7 +112,7 @@ function invokeEvents(e: Event, value: EventValue) {
114112

115113
function removeGlobalHandler(name: string) {
116114
document.removeEventListener(name, attachedGlobalHandlers[name] as any)
117-
eventCounts[name] = 0
115+
attachedGlobalHandlers[name] = null
118116
}
119117

120118
function handleNormalEvent(el: Element, name: string, prev: any, next: any) {

0 commit comments

Comments
 (0)