Skip to content

Commit

Permalink
chore: remove unused functions and improve effect execution performance
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldon66 committed May 26, 2024
1 parent 2a052ac commit dddaa4c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import { css, cx } from '@emotion/css';
import { IFormItemProps, FormItem as Item } from '@formily/antd-v5';
import { Field, onFormValuesChange, Form } from '@formily/core';
import { observer, useField, useFieldSchema, useFormEffects } from '@formily/react';
import { Field } from '@formily/core';
import { observer, useField, useFieldSchema, useForm } from '@formily/react';
import React, { useEffect, useMemo, useState } from 'react';
import { ACLCollectionFieldProvider } from '../../../acl/ACLProvider';
import { useApp } from '../../../application';
Expand All @@ -29,7 +29,6 @@ import useLazyLoadDisplayAssociationFieldsOfForm from './hooks/useLazyLoadDispla
import useParseDefaultValue from './hooks/useParseDefaultValue';
import { LinkageRuleDataKey } from '../../../schema-settings/LinkageRules/type';
import { getSatisfiedValueMap } from '../../../schema-settings/LinkageRules/compute-rules';
import { useDesignable } from '../../hooks';
import { isEmpty } from 'lodash';
Item.displayName = 'FormilyFormItem';

Expand All @@ -49,26 +48,19 @@ export const FormItem: any = withDynamicSchemaProps(
observer((props: IFormItemProps) => {
useEnsureOperatorsValid();
const field = useField<Field>();
const { dn } = useDesignable();
const schema = useFieldSchema();
const contextVariable = useContextVariable();
const variables = useVariables();
const { addActiveFieldName } = useFormActiveFields() || {};
// const form = useForm();
const [form, setForm] = useState<Form>();
const form = useForm();
const localVariables = useLocalVariables({ currentForm: { values: form?.values } as any });
const [style, setStyle] = useState({});
useEffect(() => {
variables?.registerVariable(contextVariable);
}, [contextVariable]);
useFormEffects(() => {
onFormValuesChange((form) => {
setForm(form);
});
});
const linkageStyleRules = schema[LinkageRuleDataKey.style];
useEffect(() => {
const linkageStyleRules = schema[LinkageRuleDataKey.style] || [];
if (form) {
if (form && linkageStyleRules) {
getSatisfiedValueMap({ rules: linkageStyleRules, variables, localVariables })
.then((valueMap) => {
if (!isEmpty(valueMap)) {
Expand All @@ -79,7 +71,7 @@ export const FormItem: any = withDynamicSchemaProps(
throw new Error(err.message);
});
}
}, [schema, variables, localVariables, form, dn]);
}, [variables, localVariables, form, linkageStyleRules]);
// 需要放在注冊完变量之后
useParseDefaultValue();
useLazyLoadDisplayAssociationFieldsOfForm();
Expand Down
10 changes: 1 addition & 9 deletions packages/core/client/src/schema-settings/SchemaSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -987,14 +987,6 @@ export const SchemaSettingsLinkageRules = function LinkageRules(props) {
const getRules = useCallback(() => {
return gridSchema?.[ruleKeyMap[type]] || fieldSchema?.[ruleKeyMap[type]] || [];
}, [gridSchema, fieldSchema, ruleKeyMap, type]);

const setRules = useCallback(
(rules) => {
gridSchema[ruleKeyMap[type]] = rules;
fieldSchema[ruleKeyMap[type]] = rules;
},
[[gridSchema, fieldSchema, ruleKeyMap, type]],
);
const title = titleMap[type];
const schema = useMemo<ISchema>(
() => ({
Expand Down Expand Up @@ -1041,7 +1033,7 @@ export const SchemaSettingsLinkageRules = function LinkageRules(props) {
});
dn.refresh();
},
[dn, getTemplateById, gridSchema, setRules],
[dn, getTemplateById, gridSchema, ruleKeyMap, type],
);

return (
Expand Down

0 comments on commit dddaa4c

Please sign in to comment.