Skip to content

Commit

Permalink
perf: improve performance of ArrayTable (#3574)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Nov 28, 2022
1 parent d1ee69b commit 0c0c3b0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
7 changes: 4 additions & 3 deletions packages/antd/src/array-base/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@ export const ArrayBase: ComposedArrayBase = (props) => {
}

ArrayBase.Item = ({ children, ...props }) => {
const index = props.index
const record = takeRecord(props.record, props.index)
return (
<ItemContext.Provider value={props}>
<RecordScope getIndex={() => index} getRecord={() => record}>
<RecordScope
getIndex={() => props.index}
getRecord={() => takeRecord(props.record, props.index)}
>
{children}
</RecordScope>
</ItemContext.Provider>
Expand Down
5 changes: 3 additions & 2 deletions packages/antd/src/array-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const useArrayTableSources = () => {
}

const useArrayTableColumns = (
dataSource: any[],
field: ArrayField,
sources: ObservableColumnSource[]
): TableProps<any>['columns'] => {
Expand All @@ -133,7 +134,7 @@ const useArrayTableColumns = (
key,
dataIndex: name,
render: (value: any, record: any) => {
const index = field?.value?.indexOf(record)
const index = dataSource?.indexOf(record)
const children = (
<ArrayBase.Item index={index} record={() => field?.value?.[index]}>
<RecursionField schema={schema} name={index} onlyRenderProperties />
Expand Down Expand Up @@ -295,7 +296,7 @@ export const ArrayTable: ComposedArrayTable = observer(
const prefixCls = usePrefixCls('formily-array-table')
const dataSource = Array.isArray(field.value) ? field.value.slice() : []
const sources = useArrayTableSources()
const columns = useArrayTableColumns(field, sources)
const columns = useArrayTableColumns(dataSource, field, sources)
const pagination = isBool(props.pagination) ? {} : props.pagination
const addition = useAddition()
const defaultRowKey = (record: any) => {
Expand Down
7 changes: 4 additions & 3 deletions packages/next/src/array-base/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@ export const ArrayBase: ComposedArrayBase = (props) => {
}

ArrayBase.Item = ({ children, ...props }) => {
const index = props.index
const record = takeRecord(props.record, props.index)
return (
<ItemContext.Provider value={props}>
<RecordScope getIndex={() => index} getRecord={() => record}>
<RecordScope
getIndex={() => props.index}
getRecord={() => takeRecord(props.record, props.index)}
>
{children}
</RecordScope>
</ItemContext.Provider>
Expand Down
5 changes: 3 additions & 2 deletions packages/next/src/array-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const useArrayTableSources = () => {
}

const useArrayTableColumns = (
dataSource: any[],
field: ArrayField,
sources: ObservableColumnSource[]
): TableProps['columns'] => {
Expand All @@ -131,7 +132,7 @@ const useArrayTableColumns = (
key,
dataIndex: name,
cell: (value: any, _: number, record: any) => {
const index = field.value?.indexOf(record)
const index = dataSource?.indexOf(record)
const children = (
<ArrayBase.Item
key={index}
Expand Down Expand Up @@ -299,7 +300,7 @@ export const ArrayTable: ComposedArrayTable = observer(
const prefixCls = usePrefixCls('formily-array-table')
const dataSource = Array.isArray(field.value) ? field.value.slice() : []
const sources = useArrayTableSources()
const columns = useArrayTableColumns(field, sources)
const columns = useArrayTableColumns(dataSource, field, sources)
const pagination = isBool(props.pagination) ? {} : props.pagination
const addition = useAddition()

Expand Down

0 comments on commit 0c0c3b0

Please sign in to comment.