Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add reverse api to node-children model #1619

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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