MCPcopy
hub / github.com/vuejs/devtools-v6 / sendSelectedComponentData

Function sendSelectedComponentData

packages/app-backend-core/src/component.ts:48–86  ·  view source on GitHub ↗
(appRecord: AppRecord, instanceId: string, ctx: BackendContext)

Source from the content-addressed store, hash-verified

46}
47
48export async function sendSelectedComponentData(appRecord: AppRecord, instanceId: string, ctx: BackendContext) {
49 if (!instanceId || appRecord !== ctx.currentAppRecord) {
50 return
51 }
52 const instance = getComponentInstance(appRecord, instanceId, ctx)
53 if (!instance) {
54 sendEmptyComponentData(instanceId, ctx)
55 }
56 else {
57 // Expose instance on window
58 if (typeof window !== 'undefined') {
59 const win = window as any
60 win.$vm = instance
61
62 // $vm0, $vm1, $vm2, ...
63 if ($vmQueue[0] !== instance) {
64 if ($vmQueue.length >= MAX_$VM) {
65 $vmQueue.pop()
66 }
67 for (let i = $vmQueue.length; i > 0; i--) {
68 win[`$vm${i}`] = $vmQueue[i] = $vmQueue[i - 1]
69 }
70 win.$vm0 = $vmQueue[0] = instance
71 }
72 }
73 if (SharedData.debugInfo) {
74 // eslint-disable-next-line no-console
75 console.log('[DEBUG] inspect', instance)
76 }
77 const parentInstances = await appRecord.backend.api.walkComponentParents(instance)
78 const payload = {
79 instanceId,
80 data: stringify(await appRecord.backend.api.inspectComponent(instance, ctx.currentAppRecord.options.app)),
81 parentIds: parentInstances.map(i => i.__VUE_DEVTOOLS_UID__),
82 }
83 ctx.bridge.send(BridgeEvents.TO_FRONT_COMPONENT_SELECTED_DATA, payload)
84 markSelectedInstance(instanceId, ctx)
85 }
86}
87
88export function markSelectedInstance(instanceId: string, ctx: BackendContext) {
89 ctx.currentInspectedComponentId = instanceId

Callers 4

connectFunction · 0.90
connectBridgeFunction · 0.90
editComponentStateFunction · 0.85
getFunction · 0.85

Calls 8

stringifyFunction · 0.90
getComponentInstanceFunction · 0.85
sendEmptyComponentDataFunction · 0.85
markSelectedInstanceFunction · 0.85
logMethod · 0.80
sendMethod · 0.80
walkComponentParentsMethod · 0.45
inspectComponentMethod · 0.45

Tested by

no test coverage detected