chore: 调整右侧面板构建优化对象属性下发减少re-render (#9961)

This commit is contained in:
liaoxuezhi 2024-04-03 11:54:14 +08:00 committed by GitHub
parent e64b239dd3
commit 671cfcc06d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,6 +20,7 @@ import type {DataScope} from 'amis-core';
import type {RendererConfig} from 'amis-core'; import type {RendererConfig} from 'amis-core';
import type {SchemaCollection} from 'amis'; import type {SchemaCollection} from 'amis';
import {SchemaFrom} from './base/SchemaForm'; import {SchemaFrom} from './base/SchemaForm';
import memoize from 'lodash/memoize';
// 创建 Node Store 并构建成树 // 创建 Node Store 并构建成树
export function makeWrapper( export function makeWrapper(
@ -237,6 +238,9 @@ export function makeSchemaFormRender(
} }
) { ) {
const env = {...manager.env, session: 'schema-form'}; const env = {...manager.env, session: 'schema-form'};
const filterBody = memoize(body =>
body ? flatten(Array.isArray(body) ? body : [body]) : undefined
);
return ({value, onChange, popOverContainer, id, store, node}: PanelProps) => { return ({value, onChange, popOverContainer, id, store, node}: PanelProps) => {
const ctx = {...manager.store.ctx}; const ctx = {...manager.store.ctx};
@ -260,26 +264,17 @@ export function makeSchemaFormRender(
schema.formKey ? schema.formKey : '' schema.formKey ? schema.formKey : ''
}`; }`;
const body = filterBody(schema.body);
const controls = filterBody(schema.controls);
return ( return (
<SchemaFrom <SchemaFrom
key={curFormKey} key={curFormKey}
propKey={curFormKey} propKey={curFormKey}
api={schema.api} api={schema.api}
definitions={schema.definitions} definitions={schema.definitions}
body={ body={body}
schema.body controls={controls}
? flatten(Array.isArray(schema.body) ? schema.body : [schema.body])
: undefined
}
controls={
schema.controls
? flatten(
Array.isArray(schema.controls)
? schema.controls
: [schema.controls]
)
: undefined
}
value={value} value={value}
ctx={ctx} ctx={ctx}
pipeIn={schema.pipeIn} pipeIn={schema.pipeIn}