refactor(devtools): extract same logic into createDevtoolsHook (#1608)

This commit is contained in:
underfin 2020-07-17 23:25:33 +08:00 committed by GitHub
parent 2c3427413d
commit a8966457d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View 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 function componentRemoved(component: ComponentInternalInstance) {
export const componentRemoved = createDevtoolsHook(
DevtoolsHooks.COMPONENT_REMOVED
)
function createDevtoolsHook(hook: DevtoolsHooks) {
return (component: ComponentInternalInstance) => {
if (!devtools || !component.appContext.__app) return
devtools.emit(
DevtoolsHooks.COMPONENT_REMOVED,
hook,
component.appContext.__app,
component.uid,
component.parent ? component.parent.uid : undefined
)
}
}