Skip to content

Commit

Permalink
feat(TreeData): index
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Jan 20, 2021
1 parent 0467079 commit 74cebdc
Show file tree
Hide file tree
Showing 3 changed files with 581 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/utils/TreeData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ describe('TreeData', () => {
expect(new TreeData(data).pickNodeProps(['id']).export()).toMatchSnapshot()
})

test('index', () => {
expect(
new TreeData(data)
.setNodeProps({
index: _ => _.index,
})
.export(),
).toMatchSnapshot()
})

test('filter', () => {
expect(
new TreeData(data).filter(_ => _.node.id.endsWith('.2')).export(),
Expand Down
6 changes: 6 additions & 0 deletions src/utils/TreeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export interface TreeDataTraverseFnPayload<TNode extends TreeDataNode> {
*/
node: TNode

/**
* 当前节点索引。
*/
index: number

/**
* 当前深度。从 `0` 开始。
*/
Expand Down Expand Up @@ -161,6 +166,7 @@ export class TreeData<TNode extends TreeDataNode> {

fn({
node: node,
index: index,
parentNode: parentNode,
depth: depth,
path: path,
Expand Down
Loading

0 comments on commit 74cebdc

Please sign in to comment.