Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Display functional components in component tree #719

Merged
merged 9 commits into from
Aug 2, 2018
Prev Previous commit
Next Next commit
fix: Recursively find component in vnodes
znck committed Aug 1, 2018
commit d34470df99e9dcd7c5d2604f894274fa884397af
33 changes: 23 additions & 10 deletions src/backend/index.js
Original file line number Diff line number Diff line change
@@ -279,7 +279,7 @@ function findQualifiedChildren (instance) {
? capture(instance)
: findQualifiedChildrenFromList(instance.$children).concat(
instance._vnode && instance._vnode.children
? instance._vnode.children.filter(child => child.fnContext).map(capture)
? flatten(instance._vnode.children.filter(child => !child.componentInstance).map(captureChild))
: []
)
}
@@ -296,6 +296,25 @@ function isQualified (instance) {
return name.indexOf(filter) > -1
}

function flatten (items) {
return items.reduce((acc, item) => {
if (item instanceof Array) acc.push(...flatten(item))
else if (item) acc.push(item)

return acc
}, [])
}

function captureChild (child) {
if (child.fnContext) {
return capture(child)
} else if (child.componentInstance) {
if (!child._isBeingDestroyed) return capture(child.componentInstance)
} else if (child.children) {
return flatten(child.children.map(captureChild))
}
}

/**
* Capture the meta information of an instance. (recursive)
*
@@ -338,15 +357,9 @@ function capture (instance, _, list) {
renderKey: getRenderKey(instance.$vnode ? instance.$vnode['key'] : null),
inactive: !!instance._inactive,
isFragment: !!instance._isFragment,
children: [
...(instance._vnode.children ? [] : instance.$children)
.filter(child => !child._isBeingDestroyed)
.map(capture),
...(instance._vnode.children || [])
.map((child, index) => {
if (child.fnContext) return capture(child)
else if (child.componentInstance) return capture(child.componentInstance)
}).filter(Boolean)]
children: instance._vnode.children
? flatten((instance._vnode.children).map(captureChild))
: instance.$children.filter(child => !child._isBeingDestroyed).map(capture)
}
// record screen position to ensure correct ordering
if ((!list || list.length > 1) && !instance._inactive) {