From: underfin <2218301630@qq.com> Date: Fri, 17 Jul 2020 15:25:33 +0000 (+0800) Subject: refactor(devtools): extract same logic into `createDevtoolsHook` (#1608) X-Git-Tag: v3.0.0-rc.1~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8966457d38dcbf9787dc64eca8236d3a13af4a1;p=thirdparty%2Fvuejs%2Fcore.git refactor(devtools): extract same logic into `createDevtoolsHook` (#1608) --- diff --git a/packages/runtime-core/src/devtools.ts b/packages/runtime-core/src/devtools.ts index cd1e6fecc3..6e62ee76ea 100644 --- a/packages/runtime-core/src/devtools.ts +++ b/packages/runtime-core/src/devtools.ts @@ -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 + ) + } }