Skip to content

Commit

Permalink
feat: add reverse api to node-children model
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping authored and JackLian committed Feb 22, 2023
1 parent 319d495 commit 1f09b63
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/docs/api/model/node-children.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,21 @@ forEach(fn: (node: IPublicModelNode, index: number) => void): void;
相关类型:[IPublicModelNode](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/node.ts)
### reverse
类似数组的 reverse
```typescript
/**
* 类似数组的 reverse
* provide the same function with {Array.prototype.reverse}
*/
reverse(): IPublicModelNode[];

```
相关类型:[IPublicModelNode](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/node.ts)
### map
Expand Down
6 changes: 6 additions & 0 deletions packages/designer/src/document/node/node-children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export interface INodeChildren extends Omit<IPublicModelNodeChildren, 'forEach'

reduce(fn: (acc: any, cur: INode) => any, initialValue: any): void;

reverse(): INode[];

mergeChildren(
remover: (node: INode, idx: number) => boolean,
adder: (children: INode[]) => IPublicTypeNodeData[] | null,
Expand Down Expand Up @@ -442,6 +444,10 @@ export class NodeChildren implements INodeChildren {
return this.children.reduce(fn, initialValue);
}

reverse() {
return this.children.reverse();
}

mergeChildren(
remover: (node: INode, idx: number) => boolean,
adder: (children: INode[]) => IPublicTypeNodeData[] | null,
Expand Down
9 changes: 9 additions & 0 deletions packages/shell/src/model/node-children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ export class NodeChildren implements IPublicModelNodeChildren {
});
}

/**
* 类似数组的 reverse
*/
reverse(): IPublicModelNode[] {
return this[nodeChildrenSymbol].reverse().map(d => {
return ShellNode.create(d)!;
});
}

/**
* 类似数组的 map
* @param fn
Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/shell/model/node-children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ export interface IPublicModelNodeChildren {
*/
forEach(fn: (node: IPublicModelNode, index: number) => void): void;

/**
* 类似数组的 reverse
* provide the same function with {Array.prototype.reverse}
*/
reverse(): IPublicModelNode[];

/**
* 类似数组的 map
* provide the same function with {Array.prototype.map}
Expand Down

0 comments on commit 1f09b63

Please sign in to comment.