Commit 9684e55f authored by chenos's avatar chenos
Browse files

feat: memoized schema component

parent 3c543930
main 0.7 0.7.6 Dunqing-feat-select-m2o-next acl-field acl-module api-fields app-manager audit-logs auditlogs block-schema changed-with-associations chore/error-message create-with-reverse-field dev doc/api-database doc/db-repository doc/dev-res-action doc/new-user-manual doc/plugin-workflow doc/relation-repository enable-permission example/custom-signup-page example/util examples excel-function feat-add-block-title-feature feat-add-default-sort feat-association-field-block feat-association-field-features feat-default-value feat-fix-time-and-collection-pagination feat-fk-input feat-form-validator feat-kanban-add-description feat-m2o-sub-form-mode feat-record-block-initializers-fields-pick feat-relation-field-uischema feat/associate-operate feat/batch-operation feat/cache feat/changed-with-associations feat/collection-inherits feat/collection-templates feat/create-nocobase-app feat/database feat/dev-ci feat/field-unique feat/form-save-tip feat/get-json-schema-with-async-node feat/grap-collection feat/inherit-collection feat/kanban feat/logger feat/non-paged-list feat/plugin-export feat/plugin-file-manager feat/plugin-import feat/plugin-import-2 feat/plugin-manager feat/plugin-manager-0823 feat/plugin-user-groups feat/plugin-users-with-jwt feat/plugin-verification feat/plugin-workflow feat/plugin-workflow-collection-field feat/pm feat/pnpm-support feat/reference-check feat/remove-assoc-fields-after-table-destroy feat/request-logs feat/resize-grid-columns feat/safer-update feat/submodule-graph-collection feat/table-related-components feat/tree-table-block feat/workflow-request feature/add-slate-component feature/custom_operation feature/insert-field-schema-after feature/nocobase-next-calendar feature/nocobase-next-filter fix-acl fix-acl-role fix-acl-target-action-error fix-drag-area fix-formula-bug fix-link-to-default-value fix-multi-app-manager fix-multiple-apps fix-repository-test fix-reverse-field-update fix-template-menu fix-template-with-fields-only fix-timezone fix-ui-schema-transaction fix/association-deleted fix/attachment-upload fix/block-select-collection-menu fix/bulk-update-db-locked fix/collection-manager fix/collection-manager-0719 fix/collection-manager-del-foreign-key fix/create-inherits fix/custom-assign-value fix/database-find-with-appends fix/database-view-error fix/destroy-fields-by-array fix/docker-ci fix/empty-response fix/export-date fix/export-percent fix/form-item-label-style fix/form-sys-fields-default-edit-mode fix/kanban-image-thumbnail fix/kanban-text-overflow fix/menu-schema fix/menu-url-style fix/merge-include fix/plugin-cm fix/plugin-workflow fix/table-data fix/table-field-overflow is-current-user migrator nocobase-build nocobase-next nocobase-next-action-log nocobase-next-kanban perf/cache-schema perf/token plugin-acl plugin-application plugin-multiple-apps plugin-ui-schema pre-release refactor/client refactor/database refactor/plugin-workflow refactor/plugin-workflow-ui relationships rollback sort-filed-init-value table-demo tree tree-demo v0.8.0-alpha.13 v0.8.0-alpha.11 v0.8.0-alpha.9 v0.8.0-alpha.8 v0.8.0-alpha.7 v0.8.0-alpha.6 v0.8.0-alpha.5 v0.8.0-alpha.3 v0.8.0-alpha.2 v0.8.0-alpha.1 v0.7.7-alpha.1 v0.7.6-alpha.2 v0.7.5-alpha.1.1666403334 v0.7.5-alpha.1 v0.7.4-alpha.7 v0.7.4-alpha.4 v0.7.4-alpha.1 v0.7.3-alpha.1 v0.7.2-alpha.2 v0.7.2-alpha.1 v0.7.1-alpha.5 v0.7.1-alpha.4 v0.7.0-alpha.82 v0.7.0-alpha.67 v0.7.0-alpha.64 v0.7.0-alpha.60 v0.7.0-alpha.59 v0.7.0-alpha.58 v0.7.0-alpha.57 v0.7.0-alpha.34 v0.7.0-alpha.33 v0.7.0-alpha.30 v0.7.0-alpha.29 v0.7.0-alpha.28 v0.7.0-alpha.24 v0.7.0-alpha.16 v0.7.0-alpha.15 v0.7.0-alpha.6 v0.7.0-alpha.5 v0.7.0-alpha.4 v0.7.0-alpha.3 v0.7.0-alpha.2 v0.7.0-alpha.1 v0.7.0-alpha.0 v0.6.2-alpha.12 v0.6.2-alpha.11 v0.6.2-alpha.10 v0.6.2-alpha.9 v0.6.2-alpha.7 v0.6.2-alpha.6 v0.6.2-alpha.5 v0.6.2-alpha.4 v0.6.2-alpha.3 v0.6.2-alpha.1 v0.6.2-alpha.0 v0.6.1-alpha.0 v0.6.0 v0.6.0-alpha.1
No related merge requests found
Showing with 21 additions and 5 deletions
+21 -5
......@@ -18,13 +18,29 @@ function toSchema(schema?: any) {
return new Schema(schema);
}
export function SchemaComponent(props: ISchemaFieldProps) {
const useMemoizedSchema = (schema) => {
return useMemo(() => toSchema(schema), []);
};
const RecursionSchemaComponent = (props: ISchemaFieldProps) => {
const { components, scope, schema, ...others } = props;
const s = useMemo(() => toSchema(schema), []);
console.log('SchemaComponent', { components, scope });
return (
<SchemaComponentOptions inherit components={components} scope={scope}>
<RecursionField {...others} schema={s} />
<RecursionField {...others} schema={toSchema(schema)} />
</SchemaComponentOptions>
);
}
};
const MemoizedSchemaComponent = (props: ISchemaFieldProps) => {
const { schema, ...others } = props;
const s = useMemoizedSchema(schema);
return <RecursionSchemaComponent {...others} schema={s} />;
};
export const SchemaComponent = (props: ISchemaFieldProps & { memoized?: boolean }) => {
const { memoized, ...others } = props;
if (memoized) {
return <MemoizedSchemaComponent {...others} />;
}
return <RecursionSchemaComponent {...others} />;
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment