Skip to content

Commit

Permalink
fix(react): fix ArrayTable index and FormSpy (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Jun 19, 2020
1 parent 9906a0c commit 944891f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
2 changes: 2 additions & 0 deletions packages/antd-components/src/array-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,11 @@ export const ArrayTable: any = styled(
})
}
const renderTable = () => {
let index = 0
return (
<Table
{...componentProps}
rowKey={() => index++}
pagination={false}
columns={columns}
dataSource={toArr(value)}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,14 +774,14 @@ describe('setFormState', () => {
})
a.getState() //手动同步
expect(form.getFormState(state => state.values)).toEqual({ a: '1234' })
expect(fieldChange).toBeCalledTimes(2)
expect(fieldChange).toBeCalledTimes(1)
expect(formChange).toBeCalledTimes(2)

form.setFormState(state => (state.values = { a: '5678' }), true)
a.getState() //手动同步
expect(form.getFormState(state => state.values)).toEqual({ a: '5678' })
expect(formChange).toBeCalledTimes(2)
expect(fieldChange).toBeCalledTimes(2)
expect(fieldChange).toBeCalledTimes(1)
})
})

Expand Down
10 changes: 2 additions & 8 deletions packages/core/src/externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,10 @@ export const createFormExternals = (
return getFormInitialValuesIn(name)
},
unControlledValueChanged() {
if (field.state.modified) {
nextTick(() => {
//如果在ArrayList场景状态交换走hostUpdate方式,需要在nextTick中执行
heart.publish(LifeCycleTypes.ON_FIELD_VALUE_CHANGE, field)
heart.publish(LifeCycleTypes.ON_FIELD_CHANGE, field)
})
} else {
nextTick(() => {
heart.publish(LifeCycleTypes.ON_FIELD_VALUE_CHANGE, field)
heart.publish(LifeCycleTypes.ON_FIELD_CHANGE, field)
}
})
}
})
field.subscription = {
Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/hooks/useFormSpy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ export const useFormSpy = (props: IFormSpyProps): ISpyHook => {
)
const subscriber = useCallback<FormHeartSubscriber>(({ type, payload }) => {
if (initializedRef.current) return
clearTimeout(timerRef.current[type])
timerRef.current[type] = setTimeout(() => {
const key = `${type}_${payload?.state?.name}`
clearTimeout(timerRef.current[key])
timerRef.current[key] = setTimeout(() => {
if (unmountRef.current) return
payload = payload && isFn(payload.getState) ? payload.getState() : payload
if (isStr(props.selector) && FormPath.parse(props.selector).match(type)) {
Expand Down

0 comments on commit 944891f

Please sign in to comment.