perf(flatten): use o(n) implementation

This commit is contained in:
07akioni 2020-09-29 16:54:09 +08:00
parent a435b7127d
commit d89bd58a00

View File

@ -1,10 +1,10 @@
import { Fragment } from 'vue'
export function flatten (vNodes) {
let result = []
// o(n) flatten
export function flatten (vNodes, result = []) {
vNodes.forEach(vNode => {
if (vNode.type === Fragment) {
result = result.concat(flatten(vNode.children))
flatten(vNode.children, result)
} else {
result.push(vNode)
}