|
import type { BackendContext } from '@vue-devtools/app-backend-api' |
|
import { HookEvents } from '@vue-devtools/shared-utils' |
|
|
|
const internalRE = /^(?:pre-)?hook:/ |
|
|
|
function wrap(app, Vue, method, ctx: BackendContext) { |
|
const original = Vue.prototype[method] |
|
if (original) { |
|
Vue.prototype[method] = function (...args) { |
|
const res = original.apply(this, args) |
|
logEvent(this, method, args[0], args.slice(1)) |
|
return res |
|
} |
|
} |
|
|
|
function logEvent(vm, type, eventName, payload) { |
|
|
|
|
|
|
|
|
|
if (typeof eventName === 'string' && !internalRE.test(eventName)) { |
|
const instance = vm._self || vm |
|
ctx.hook.emit(HookEvents.COMPONENT_EMIT, app, instance, eventName, payload) |
|
} |
|
} |
|
} |
|
|
|
export function wrapVueForEvents(app, Vue, ctx: BackendContext) { |
|
['$emit', '$broadcast', '$dispatch'].forEach((method) => { |
|
wrap(app, Vue, method, ctx) |
|
}) |
|
} |
|
|