Skip to content

Commit

Permalink
feat(devtools): catch events
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Aug 23, 2020
1 parent 10293c7 commit 23233dc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/runtime-core/src/componentEmits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { callWithAsyncErrorHandling, ErrorCodes } from './errorHandling'
import { warn } from './warning'
import { normalizePropsOptions } from './componentProps'
import { UnionToIntersection } from './helpers/typeUtils'
import { devtoolsComponentEmit } from './devtools'

export type ObjectEmitsOptions = Record<
string,
Expand Down Expand Up @@ -67,6 +68,10 @@ export function emit(
}
}

if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
devtoolsComponentEmit(instance, event, args)
}

let handlerName = `on${capitalize(event)}`
let handler = props[handlerName]
// for v-model update:xxx events, also trigger kebab-case equivalent
Expand Down
18 changes: 17 additions & 1 deletion packages/runtime-core/src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const enum DevtoolsHooks {
APP_UNMOUNT = 'app:unmount',
COMPONENT_UPDATED = 'component:updated',
COMPONENT_ADDED = 'component:added',
COMPONENT_REMOVED = 'component:removed'
COMPONENT_REMOVED = 'component:removed',
COMPONENT_EMIT = 'component:emit'
}

interface DevtoolsHook {
Expand Down Expand Up @@ -70,3 +71,18 @@ function createDevtoolsComponentHook(hook: DevtoolsHooks) {
)
}
}

export function devtoolsComponentEmit(
component: ComponentInternalInstance,
event: string,
params: any[]
) {
if (!devtools) return
devtools.emit(
DevtoolsHooks.COMPONENT_EMIT,
component.appContext.app,
component.uid,
event,
params
)
}

0 comments on commit 23233dc

Please sign in to comment.