Skip to content

Commit

Permalink
fix(TreeData): findNodePath、findNodePaths 的结果应包含当前节点
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Dec 11, 2020
1 parent 3f21cf7 commit 53edbb2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils/TreeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export class TreeData<TNode extends TreeDataNode> {
let path: TNode[] | undefined
this.traverse(payload => {
if (predicate(payload.node)) {
path = payload.path
path = payload.path.concat(payload.node)
payload.exit()
}
})
Expand All @@ -348,7 +348,7 @@ export class TreeData<TNode extends TreeDataNode> {
const paths: Array<TNode[]> = []
this.traverse(payload => {
if (predicate(payload.node)) {
paths.push(payload.path)
paths.push(payload.path.concat(payload.node))
}
})
return paths
Expand Down
8 changes: 8 additions & 0 deletions src/utils/__snapshots__/TreeData.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Array [
],
"id": "1",
},
Object {
"children": Array [],
"id": "1.1",
},
]
`;

Expand Down Expand Up @@ -109,6 +113,10 @@ Array [
],
"id": "1",
},
Object {
"children": Array [],
"id": "1.1",
},
],
]
`;
Expand Down

0 comments on commit 53edbb2

Please sign in to comment.