Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡️ feat(form): optimize query filter performance #1074

Merged
merged 8 commits into from Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/field/src/index.tsx
Expand Up @@ -413,6 +413,7 @@ const ProField: React.ForwardRefRenderFunction<any, ProFieldPropsType> = (
// fieldProps 优先级更高,在类似 LightFilter 场景下需要覆盖默认的 value 和 onChange
...omitUndefined(rest?.fieldProps),
};

return (
<React.Fragment>
{defaultRenderText(text ?? fieldProps?.value ?? '', valueType || 'text', {
Expand Down
19 changes: 6 additions & 13 deletions packages/form/src/BaseForm/index.tsx
Expand Up @@ -80,10 +80,9 @@ const BaseForm: React.FC<BaseFormProps> = (props) => {
* 因为 protable 里面的值无法保证刚开始就存在
* 所以多进行了一次触发,这样可以解决部分问题
*/
const [formInit, forgetUpdate] = useState(false);
const [, forgetUpdate] = useState(false);

const items = React.Children.toArray(children);

const submitterProps: Omit<SubmitterProps, 'form'> =
typeof submitter === 'boolean' || !submitter ? {} : submitter;

Expand All @@ -93,6 +92,7 @@ const BaseForm: React.FC<BaseFormProps> = (props) => {
const submitterNode =
submitter === false ? undefined : (
<Submitter
key="submitter"
{...submitterProps}
form={userForm || form}
submitButtonProps={{
Expand Down Expand Up @@ -156,17 +156,10 @@ const BaseForm: React.FC<BaseFormProps> = (props) => {
/>
<Form.Item noStyle shouldUpdate>
{(formInstance) => {
// 不 setTimeout 一下拿到的是比较旧的
setTimeout(() => {
// 支持 fromRef,这里 ref 里面可以随时拿到最新的值
if (propsFormRef) {
if (!formInit) {
forgetUpdate(true);
}
propsFormRef.current = formInstance as FormInstance;
}
formRef.current = formInstance as FormInstance;
}, 0);
// 支持 fromRef,这里 ref 里面可以随时拿到最新的值
if (propsFormRef && !propsFormRef.current) forgetUpdate(true);
if (propsFormRef) propsFormRef.current = formInstance as FormInstance;
formRef.current = formInstance as FormInstance;
}}
</Form.Item>
{content}
Expand Down