Skip to content

Commit e7132f3

Browse files
committed
fix: wip async vue2 walk tree
1 parent 3db4702 commit e7132f3

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

packages/app-backend-vue2/src/components/tree.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ const functionalIds = new Map()
1919
// Some instances may be both on a component and on a child abstract/functional component
2020
const captureIds = new Map()
2121

22-
export function walkTree (instance, pFilter: string, ctx: BackendContext): ComponentTreeNode[] {
22+
export async function walkTree (instance, pFilter: string, ctx: BackendContext): Promise<ComponentTreeNode[]> {
2323
initCtx(ctx)
2424
filter = pFilter
2525
functionalIds.clear()
2626
captureIds.clear()
27-
const result = findQualifiedChildren(instance)
27+
const result: ComponentTreeNode[] | ComponentTreeNode = await findQualifiedChildren(instance)
2828
if (Array.isArray(result)) {
2929
return result
3030
}
@@ -71,7 +71,7 @@ function initCtx (ctx: BackendContext) {
7171
* traversal - e.g. if an instance is not matched, we will
7272
* recursively go deeper until a qualified child is found.
7373
*/
74-
function findQualifiedChildrenFromList (instances: any[]): any[] {
74+
function findQualifiedChildrenFromList (instances: any[]): ComponentTreeNode[] {
7575
instances = instances
7676
.filter(child => !isBeingDestroyed(child))
7777
return !filter
@@ -84,7 +84,7 @@ function findQualifiedChildrenFromList (instances: any[]): any[] {
8484
* If the instance itself is qualified, just return itself.
8585
* This is ok because [].concat works in both cases.
8686
*/
87-
function findQualifiedChildren (instance) {
87+
async function findQualifiedChildren (instance): Promise<ComponentTreeNode[] | ComponentTreeNode> {
8888
if (isQualified(instance)) {
8989
return capture(instance)
9090
} else {
@@ -102,13 +102,10 @@ function findQualifiedChildren (instance) {
102102
/**
103103
* Get children from a component instance.
104104
*/
105-
function getInternalInstanceChildren (instance) {
105+
function getInternalInstanceChildren (instance): any[] {
106106
if (instance.$children) {
107107
return instance.$children
108108
}
109-
if (Array.isArray(instance.subTree.children)) {
110-
return instance.subTree.children.filter(vnode => !!vnode.component).map(vnode => vnode.component)
111-
}
112109
return []
113110
}
114111

@@ -142,7 +139,7 @@ function captureChild (child) {
142139
/**
143140
* Capture the meta information of an instance. (recursive)
144141
*/
145-
function capture (instance, index?: number, list?: any[]): ComponentTreeNode {
142+
async function capture (instance, index?: number, list?: any[]): Promise<ComponentTreeNode> {
146143
if (instance.__VUE_DEVTOOLS_FUNCTIONAL_LEGACY__) {
147144
instance = instance.vnode
148145
}
@@ -216,10 +213,9 @@ function capture (instance, index?: number, list?: any[]): ComponentTreeNode {
216213
mark(instance)
217214
const name = getInstanceName(instance)
218215

219-
const children = getInternalInstanceChildren(instance)
216+
const children = (await Promise.all((await getInternalInstanceChildren(instance))
220217
.filter(child => !isBeingDestroyed(child))
221-
.map(capture)
222-
.filter(Boolean)
218+
.map(capture))).filter(Boolean)
223219

224220
const ret: ComponentTreeNode = {
225221
uid: instance._uid,

packages/app-backend-vue2/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export const backend: DevtoolsBackend = {
2424
payload.root = payload.app
2525
})
2626

27-
api.on.walkComponentTree((payload, ctx) => {
28-
payload.componentTreeData = walkTree(payload.componentInstance, payload.filter, ctx)
27+
api.on.walkComponentTree(async (payload, ctx) => {
28+
payload.componentTreeData = await walkTree(payload.componentInstance, payload.filter, ctx)
2929
})
3030

3131
api.on.walkComponentParents((payload, ctx) => {

0 commit comments

Comments
 (0)