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]) let region = Array.isArray(rest[key])
? rest[key].concat() ? rest[key]
: rest[key] : rest[key]
? [rest[key]] ? [rest[key]]
: defaultRegion; : defaultRegion;
if (!region.length) { if (!region.length) {
region = region.concat();
region.push({children: () => null}); region.push({children: () => null});
} }

View File

@ -222,20 +222,23 @@ export const EditorNode = types
}, },
get uniqueChildren() { get uniqueChildren() {
let children = self.children.filter( let children: Array<any> = [];
(child, index, list) => let map: Record<string, any> = {};
list.findIndex(a => self.children.forEach(child => {
child.isRegion const key = child.isRegion ? `${child.region}-${child.id}` : child.id;
? a.id === child.id && a.region === child.region if (map[key]) {
: a.id === child.id return;
) === index }
);
map[key] = true;
children.push(child);
});
if (Array.isArray(this.schema)) { 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) => { children = children.sort((a, b) => {
const idxa = findIndex(arr, item => item?.$$id === a.id); const idxa = arr.indexOf(a.id);
const idxb = findIndex(arr, item => item?.$$id === b.id); const idxb = arr.indexOf(b.id);
return idxa - idxb; return idxa - idxb;
}); });
} }