-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): expose activeComponent to window (#427)
- Loading branch information
1 parent
0b57f13
commit 91f8ef4
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const MAX_$VM = 10 | ||
const $vmQueue: any[] = [] | ||
|
||
// Expose instance data to window | ||
// Copied from https://github.com/vuejs/devtools/blob/f03590025b0b4910cf539531c91384be51a8f8fa/packages/app-backend-core/src/component.ts#L57-L72 | ||
export function exposeInstanceToWindow(componentInstance: any) { | ||
const win = window as any | ||
if (typeof win === 'undefined') | ||
return | ||
|
||
if (!componentInstance) | ||
return | ||
|
||
win.$vm = componentInstance | ||
|
||
// $vm0, $vm1, $vm2, ... | ||
if ($vmQueue[0] !== componentInstance) { | ||
if ($vmQueue.length >= MAX_$VM) { | ||
$vmQueue.pop() | ||
} | ||
for (let i = $vmQueue.length; i > 0; i--) { | ||
win[`$vm${i}`] = $vmQueue[i] = $vmQueue[i - 1] | ||
} | ||
win.$vm0 = $vmQueue[0] = componentInstance | ||
} | ||
} |