Skip to content

Commit 23233dc

Browse files
committed
feat(devtools): catch events
1 parent 10293c7 commit 23233dc

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/runtime-core/src/componentEmits.ts

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { callWithAsyncErrorHandling, ErrorCodes } from './errorHandling'
1313
import { warn } from './warning'
1414
import { normalizePropsOptions } from './componentProps'
1515
import { UnionToIntersection } from './helpers/typeUtils'
16+
import { devtoolsComponentEmit } from './devtools'
1617

1718
export type ObjectEmitsOptions = Record<
1819
string,
@@ -67,6 +68,10 @@ export function emit(
6768
}
6869
}
6970

71+
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
72+
devtoolsComponentEmit(instance, event, args)
73+
}
74+
7075
let handlerName = `on${capitalize(event)}`
7176
let handler = props[handlerName]
7277
// for v-model update:xxx events, also trigger kebab-case equivalent

packages/runtime-core/src/devtools.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ const enum DevtoolsHooks {
1414
APP_UNMOUNT = 'app:unmount',
1515
COMPONENT_UPDATED = 'component:updated',
1616
COMPONENT_ADDED = 'component:added',
17-
COMPONENT_REMOVED = 'component:removed'
17+
COMPONENT_REMOVED = 'component:removed',
18+
COMPONENT_EMIT = 'component:emit'
1819
}
1920

2021
interface DevtoolsHook {
@@ -70,3 +71,18 @@ function createDevtoolsComponentHook(hook: DevtoolsHooks) {
7071
)
7172
}
7273
}
74+
75+
export function devtoolsComponentEmit(
76+
component: ComponentInternalInstance,
77+
event: string,
78+
params: any[]
79+
) {
80+
if (!devtools) return
81+
devtools.emit(
82+
DevtoolsHooks.COMPONENT_EMIT,
83+
component.appContext.app,
84+
component.uid,
85+
event,
86+
params
87+
)
88+
}

0 commit comments

Comments
 (0)