perf: 优化编辑器性能 (#9432)

This commit is contained in:
liaoxuezhi 2024-01-15 15:49:37 +08:00 committed by GitHub
parent 4603f4648b
commit f45cb59072
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 13 deletions

View File

@ -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});
}

View File

@ -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;
});
}