@@ -47,32 +47,24 @@ export function appUnmounted(app: App) {
47
47
devtools . emit ( DevtoolsHooks . APP_UNMOUNT , app )
48
48
}
49
49
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 )
59
51
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
+ )
69
59
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
+ }
78
70
}
0 commit comments