Skip to content

Commit a896645

Browse files
authored
refactor(devtools): extract same logic into createDevtoolsHook (#1608)
1 parent 2c34274 commit a896645

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

packages/runtime-core/src/devtools.ts

+18-26
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,24 @@ export function appUnmounted(app: App) {
4747
devtools.emit(DevtoolsHooks.APP_UNMOUNT, app)
4848
}
4949

50-
export function componentAdded(component: ComponentInternalInstance) {
51-
if (!devtools || !component.appContext.__app) return
52-
devtools.emit(
53-
DevtoolsHooks.COMPONENT_ADDED,
54-
component.appContext.__app,
55-
component.uid,
56-
component.parent ? component.parent.uid : undefined
57-
)
58-
}
50+
export const componentAdded = createDevtoolsHook(DevtoolsHooks.COMPONENT_ADDED)
5951

60-
export function componentUpdated(component: ComponentInternalInstance) {
61-
if (!devtools || !component.appContext.__app) return
62-
devtools.emit(
63-
DevtoolsHooks.COMPONENT_UPDATED,
64-
component.appContext.__app,
65-
component.uid,
66-
component.parent ? component.parent.uid : undefined
67-
)
68-
}
52+
export const componentUpdated = createDevtoolsHook(
53+
DevtoolsHooks.COMPONENT_UPDATED
54+
)
55+
56+
export const componentRemoved = createDevtoolsHook(
57+
DevtoolsHooks.COMPONENT_REMOVED
58+
)
6959

70-
export function componentRemoved(component: ComponentInternalInstance) {
71-
if (!devtools || !component.appContext.__app) return
72-
devtools.emit(
73-
DevtoolsHooks.COMPONENT_REMOVED,
74-
component.appContext.__app,
75-
component.uid,
76-
component.parent ? component.parent.uid : undefined
77-
)
60+
function createDevtoolsHook(hook: DevtoolsHooks) {
61+
return (component: ComponentInternalInstance) => {
62+
if (!devtools || !component.appContext.__app) return
63+
devtools.emit(
64+
hook,
65+
component.appContext.__app,
66+
component.uid,
67+
component.parent ? component.parent.uid : undefined
68+
)
69+
}
7870
}

0 commit comments

Comments
 (0)