Skip to content

Commit

Permalink
fix(form-grid): improve performace
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Feb 20, 2021
1 parent 35dd3fd commit f1b7afd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
20 changes: 4 additions & 16 deletions packages/antd/docs/components/FormGrid.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React from 'react'
import { FormItem, Input, FormGrid } from '@formily/antd'
import { FormProvider, createSchemaField } from '@formily/react'
import { createForm, onFieldReact } from '@formily/core'
import { createForm } from '@formily/core'

const SchemaField = createSchemaField({
components: {
Expand All @@ -18,13 +18,7 @@ const SchemaField = createSchemaField({
},
})

const form = createForm({
effects(form) {
onFieldReact('*(ccc,ddd,eee,fff,ggg)', (field) => {
field.visible = form.values.aaa !== '123'
})
},
})
const form = createForm()

export default () => {
return (
Expand Down Expand Up @@ -92,7 +86,7 @@ export default () => {
import React from 'react'
import { FormItem, Input, FormGrid } from '@formily/antd'
import { FormProvider, createSchemaField } from '@formily/react'
import { createForm, onFieldReact } from '@formily/core'
import { createForm } from '@formily/core'

const SchemaField = createSchemaField({
components: {
Expand All @@ -102,13 +96,7 @@ const SchemaField = createSchemaField({
},
})

const form = createForm({
effects(form) {
onFieldReact('*(ccc,ddd,eee,fff,ggg)', (field) => {
field.visible = form.values.aaa !== '123'
})
},
})
const form = createForm()

const schema = {
type: 'object',
Expand Down
6 changes: 4 additions & 2 deletions packages/antd/src/form-grid/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useLayoutEffect, useRef, useState, useContext } from 'react'
import { usePrefixCls } from '../__builtins__'
import cls from 'classnames'
import { isValid, isNum, isBool } from '@formily/shared'
import { isValid, isNum, isBool, isEqual } from '@formily/shared'
import ResizeObserver from 'resize-observer-polyfill'
import { FormGridContext } from './context'

Expand Down Expand Up @@ -163,7 +163,9 @@ const useLayout = (props: ILayoutProps): ILayout => {
const params = calculateSmartColumns(ref.current)
setLayout(params)
const style = getStyle({ columnGap, rowGap, layoutParams: params, ref })
setStyles(style)
if (!isEqual(style, styles)) {
setStyles(style)
}
}
const resizeObserver = new ResizeObserver(observer)
const mutationObserver = new MutationObserver(observer)
Expand Down
6 changes: 4 additions & 2 deletions packages/next/src/form-grid/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useLayoutEffect, useRef, useState, useContext } from 'react'
import { usePrefixCls } from '../__builtins__'
import cls from 'classnames'
import { isValid, isNum, isBool } from '@formily/shared'
import { isValid, isNum, isBool, isEqual } from '@formily/shared'
import ResizeObserver from 'resize-observer-polyfill'
import { FormGridContext } from './context'

Expand Down Expand Up @@ -163,7 +163,9 @@ const useLayout = (props: ILayoutProps): ILayout => {
const params = calculateSmartColumns(ref.current)
setLayout(params)
const style = getStyle({ columnGap, rowGap, layoutParams: params, ref })
setStyles(style)
if (!isEqual(style, styles)) {
setStyles(style)
}
}
const resizeObserver = new ResizeObserver(observer)
const mutationObserver = new MutationObserver(observer)
Expand Down

0 comments on commit f1b7afd

Please sign in to comment.