]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: events tweak
authorEvan You <yyx990803@gmail.com>
Wed, 19 Dec 2018 23:14:41 +0000 (18:14 -0500)
committerEvan You <yyx990803@gmail.com>
Wed, 19 Dec 2018 23:14:41 +0000 (18:14 -0500)
packages/runtime-dom/src/modules/events.ts

index 559fbfae8ceb1402ec6314a5b062411684332334..a23e1166a9b565b488a7842ec605bb2831d89e7b 100644 (file)
@@ -17,7 +17,7 @@ export function patchEvent(
 }
 
 const eventCounts: Record<string, number> = {}
-const attachedGlobalHandlers: Record<string, Function> = {}
+const attachedGlobalHandlers: Record<string, Function | null> = {}
 
 export function handleDelegatedEvent(
   el: any,
@@ -38,18 +38,16 @@ export function handleDelegatedEvent(
     }
     store[name] = value
   } else if (store && store[name]) {
-    eventCounts[name]--
-    store[name] = null
-    if (count === 1) {
+    if (--eventCounts[name] === 0) {
       removeGlobalHandler(name)
     }
+    store[name] = null
   }
 }
 
 function attachGlobalHandler(name: string) {
   const handler = (attachedGlobalHandlers[name] = (e: Event) => {
-    const { type } = e
-    const isClick = type === 'click' || type === 'dblclick'
+    const isClick = e.type === 'click' || e.type === 'dblclick'
     if (isClick && (e as MouseEvent).button !== 0) {
       e.stopPropagation()
       return false
@@ -114,7 +112,7 @@ function invokeEvents(e: Event, value: EventValue) {
 
 function removeGlobalHandler(name: string) {
   document.removeEventListener(name, attachedGlobalHandlers[name] as any)
-  eventCounts[name] = 0
+  attachedGlobalHandlers[name] = null
 }
 
 function handleNormalEvent(el: Element, name: string, prev: any, next: any) {