]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(devtools): extract same logic into `createDevtoolsHook` (#1608)
authorunderfin <2218301630@qq.com>
Fri, 17 Jul 2020 15:25:33 +0000 (23:25 +0800)
committerGitHub <noreply@github.com>
Fri, 17 Jul 2020 15:25:33 +0000 (11:25 -0400)
packages/runtime-core/src/devtools.ts

index cd1e6fecc32a0285244a96dad815b431c814c5d5..6e62ee76eabf72efbdf3b92006ef08fae24002a5 100644 (file)
@@ -47,32 +47,24 @@ export function appUnmounted(app: App) {
   devtools.emit(DevtoolsHooks.APP_UNMOUNT, app)
 }
 
-export function componentAdded(component: ComponentInternalInstance) {
-  if (!devtools || !component.appContext.__app) return
-  devtools.emit(
-    DevtoolsHooks.COMPONENT_ADDED,
-    component.appContext.__app,
-    component.uid,
-    component.parent ? component.parent.uid : undefined
-  )
-}
+export const componentAdded = createDevtoolsHook(DevtoolsHooks.COMPONENT_ADDED)
 
-export function componentUpdated(component: ComponentInternalInstance) {
-  if (!devtools || !component.appContext.__app) return
-  devtools.emit(
-    DevtoolsHooks.COMPONENT_UPDATED,
-    component.appContext.__app,
-    component.uid,
-    component.parent ? component.parent.uid : undefined
-  )
-}
+export const componentUpdated = createDevtoolsHook(
+  DevtoolsHooks.COMPONENT_UPDATED
+)
+
+export const componentRemoved = createDevtoolsHook(
+  DevtoolsHooks.COMPONENT_REMOVED
+)
 
-export function componentRemoved(component: ComponentInternalInstance) {
-  if (!devtools || !component.appContext.__app) return
-  devtools.emit(
-    DevtoolsHooks.COMPONENT_REMOVED,
-    component.appContext.__app,
-    component.uid,
-    component.parent ? component.parent.uid : undefined
-  )
+function createDevtoolsHook(hook: DevtoolsHooks) {
+  return (component: ComponentInternalInstance) => {
+    if (!devtools || !component.appContext.__app) return
+    devtools.emit(
+      hook,
+      component.appContext.__app,
+      component.uid,
+      component.parent ? component.parent.uid : undefined
+    )
+  }
 }