Skip to content

Commit

Permalink
perf: 优化编辑器性能 (baidu#9432)
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop committed Jan 15, 2024
1 parent 4603f46 commit f45cb59
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
5 changes: 3 additions & 2 deletions packages/amis-editor-core/src/component/ContainerWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ export class ContainerWrapper extends React.Component<ContainerWrapperProps> {
];
}

const region = Array.isArray(rest[key])
? rest[key].concat()
let region = Array.isArray(rest[key])
? rest[key]
: rest[key]
? [rest[key]]
: defaultRegion;

if (!region.length) {
region = region.concat();
region.push({children: () => null});
}

Expand Down
25 changes: 14 additions & 11 deletions packages/amis-editor-core/src/store/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,23 @@ export const EditorNode = types
},

get uniqueChildren() {
let children = self.children.filter(
(child, index, list) =>
list.findIndex(a =>
child.isRegion
? a.id === child.id && a.region === child.region
: a.id === child.id
) === index
);
let children: Array<any> = [];
let map: Record<string, any> = {};
self.children.forEach(child => {
const key = child.isRegion ? `${child.region}-${child.id}` : child.id;
if (map[key]) {
return;
}

map[key] = true;
children.push(child);
});

if (Array.isArray(this.schema)) {
const arr = this.schema;
const arr = this.schema.map(item => item?.$$id).filter(item => item);
children = children.sort((a, b) => {
const idxa = findIndex(arr, item => item?.$$id === a.id);
const idxb = findIndex(arr, item => item?.$$id === b.id);
const idxa = arr.indexOf(a.id);
const idxb = arr.indexOf(b.id);
return idxa - idxb;
});
}
Expand Down

0 comments on commit f45cb59

Please sign in to comment.