Skip to content

Commit

Permalink
fix(@uform/core): fix push buffer with path.pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Jul 1, 2019
1 parent 7cb6316 commit eb89850
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/Tutorials/Questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
## 7. 如何定制UForm的样式?

## 8. value和initialValues的差别是什么?

## 9. 为什么effects函数不能配合react hooks使用?
2 changes: 1 addition & 1 deletion packages/core/src/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class Form {
field.dirty = false
}
if (path.hasWildcard) {
this.updateBuffer.push(path.string, callback, { path, resolve })
this.updateBuffer.push(path.pattern, callback, { path, resolve })
}
if (field.dirty) {
const dirtyType = field.dirtyType
Expand Down
43 changes: 42 additions & 1 deletion packages/react/src/__tests__/effects.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import SchemaForm, {
registerFormField,
connect,
registerFieldMiddleware,
createFormActions
createFormActions,
FormPath
} from '../index'
import { render, fireEvent, act } from '@testing-library/react'

Expand Down Expand Up @@ -214,3 +215,43 @@ test('set errors in effects', async () => {
await sleep(33)
expect(callback).toHaveBeenCalledTimes(0)
})

test('setFieldState from buffer', async () => {
const callback = jest.fn()
const TestComponent = () => {
return (
<SchemaForm
effects={($, { setFieldState }) => {
$('onFormInit').subscribe(() => {
setFieldState(FormPath.match('*'), state => {
state.title = '1123'
})
})
$('onFieldChange', 'kkk').subscribe(() => {
setFieldState(FormPath.match('dd.*'), state => {
state.visible = false
})
})
}}
onSubmit={callback}
>
<Field type="object" name="dd" title="DD">
<Field type="string" name="bbb" title="ccc" />
</Field>
<Field
type="string"
name="kkk"
title="String"
x-props={{ 'data-testid': 'test' }}
/>
<button type="submit" data-testid="btn">
Submit
</button>
</SchemaForm>
)
}

const { queryByTestId } = render(<TestComponent />)
await sleep(33)
expect(queryByTestId('test')).toBeVisible()
})

0 comments on commit eb89850

Please sign in to comment.