Skip to content

Commit

Permalink
feat(TreeData): 遍历优化
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Dec 16, 2020
1 parent 1e2b035 commit f432090
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/utils/TreeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,27 +129,27 @@ export class TreeData<TNode extends TreeDataNode> {

let currentNode: typeof nodes[0] | undefined
const removeNodes: Array<[siblings: TNode[], indexes: number[]]> = []
let isRemove = false
let isExit = false
let isSkipChildrenTraverse = false
const removeNode = () => (isRemove = true)
const exit = () => (isExit = true)
const skipChildrenTraverse = () => (isSkipChildrenTraverse = true)
while ((currentNode = nodes.shift())) {
const [node, index, parentNode, siblings, depth, path] = currentNode

let isRemove = false
let isExit = false
let isSkipChildrenTraverse = false
isRemove = false
isExit = false
isSkipChildrenTraverse = false

fn({
node: node,
parentNode: parentNode,
depth: depth,
path: path,
removeNode: () => {
isRemove = true
},
exit: () => {
isExit = true
},
skipChildrenTraverse: () => {
isSkipChildrenTraverse = true
},
removeNode: removeNode,
exit: exit,
skipChildrenTraverse: skipChildrenTraverse,
})

if (isRemove) {
Expand Down Expand Up @@ -183,11 +183,11 @@ export class TreeData<TNode extends TreeDataNode> {
}
}

let removeNode: typeof removeNodes[0] | undefined
while ((removeNode = removeNodes.shift())) {
let _removeNode: typeof removeNodes[0] | undefined
while ((_removeNode = removeNodes.shift())) {
let removeNodeIndex: number | undefined
while ((removeNodeIndex = removeNode[1].pop()) != null) {
removeNode[0].splice(removeNodeIndex, 1)
while ((removeNodeIndex = _removeNode[1].pop()) != null) {
_removeNode[0].splice(removeNodeIndex, 1)
}
}
}
Expand Down

0 comments on commit f432090

Please sign in to comment.