(appRecord: AppRecord, instanceId: string, ctx: BackendContext)
| 46 | } |
| 47 | |
| 48 | export 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 | |
| 88 | export function markSelectedInstance(instanceId: string, ctx: BackendContext) { |
| 89 | ctx.currentInspectedComponentId = instanceId |
no test coverage detected