MCPcopy
hub / github.com/vuejs/core / setDevtoolsHook

Function setDevtoolsHook

packages/runtime-core/src/devtools.ts:52–88  ·  view source on GitHub ↗
(hook: DevtoolsHook, target: any)

Source from the content-addressed store, hash-verified

50}
51
52export function setDevtoolsHook(hook: DevtoolsHook, target: any): void {
53 devtools = hook
54 if (devtools) {
55 devtools.enabled = true
56 buffer.forEach(({ event, args }) => devtools.emit(event, ...args))
57 buffer = []
58 } else if (
59 // handle late devtools injection - only do this if we are in an actual
60 // browser environment to avoid the timer handle stalling test runner exit
61 // (#4815)
62 typeof window !== 'undefined' &&
63 // some envs mock window but not fully
64 window.HTMLElement &&
65 // also exclude jsdom
66 // eslint-disable-next-line no-restricted-syntax
67 !window.navigator?.userAgent?.includes('jsdom')
68 ) {
69 const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
70 target.__VUE_DEVTOOLS_HOOK_REPLAY__ || [])
71 replay.push((newHook: DevtoolsHook) => {
72 setDevtoolsHook(newHook, target)
73 })
74 // clear buffer after 3s - the user probably doesn't have devtools installed
75 // at all, and keeping the buffer will cause memory leaks (#4738)
76 setTimeout(() => {
77 if (!devtools) {
78 target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null
79 devtoolsNotInstalled = true
80 buffer = []
81 }
82 }, 3000)
83 } else {
84 // non-browser env, assume not installed
85 devtoolsNotInstalled = true
86 buffer = []
87 }
88}
89
90export function devtoolsInitApp(app: App, version: string): void {
91 emit(DevtoolsHooks.APP_INIT, app, version, {

Callers 1

baseCreateRendererFunction · 0.90

Calls 2

forEachMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected