Skip to content

Commit

Permalink
refactor(core): revert field unmount to skip validate (#2379)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Nov 2, 2021
1 parent 831ba8b commit 8a01679
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/__tests__/field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,11 @@ test('fields unmount and selfValidate', async () => {
} catch {}
expect(form.invalid).toBeTruthy()
field.onUnmount()
try {
await form.validate()
} catch {}
expect(form.invalid).toBeTruthy()
form.clearFormGraph('parent')
await form.validate()
expect(form.invalid).toBeFalsy()
})
Expand Down
20 changes: 14 additions & 6 deletions packages/core/src/__tests__/form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,14 @@ test('validate will skip unmounted', async () => {
await form.validate()
} catch (e) {
expect(e).toEqual([
{
triggerType: 'onInput',
type: 'error',
code: 'ValidateError',
messages: ['error'],
address: 'aa',
path: 'aa',
},
{
triggerType: 'onInput',
type: 'error',
Expand All @@ -1423,18 +1431,18 @@ test('validate will skip unmounted', async () => {
},
])
}
expect(validateA).toBeCalledTimes(1)
expect(validateA).toBeCalledTimes(2)
expect(validateB).toBeCalledTimes(2)
expect(aa.invalid).toBeFalsy()
expect(aa.invalid).toBeTruthy()
expect(bb.invalid).toBeTruthy()
expect(validator).toBeCalledTimes(3)
bb.onUnmount()
expect(validator).toBeCalledTimes(4)
form.clearFormGraph('*(aa,bb)')
await form.validate()
expect(validateA).toBeCalledTimes(1)
expect(validateA).toBeCalledTimes(2)
expect(validateB).toBeCalledTimes(2)
expect(aa.invalid).toBeFalsy()
expect(bb.invalid).toBeFalsy()
expect(validator).toBeCalledTimes(3)
expect(validator).toBeCalledTimes(4)
})

test('validate will skip uneditable', async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/models/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ export class Field<
}
),
reaction(
() => [this.pattern, this.unmounted],
([pattern, unmounted]) => {
if (pattern !== 'editable' || unmounted) {
() => this.pattern,
(pattern) => {
if (pattern !== 'editable') {
this.setFeedback({
type: 'error',
messages: [],
Expand Down
14 changes: 2 additions & 12 deletions packages/core/src/shared/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,12 +886,7 @@ export const batchValidate = async (
) => {
if (isForm(target)) target.setValidating(true)
else {
if (
target.pattern !== 'editable' ||
target.display !== 'visible' ||
target.unmounted
)
return
if (target.pattern !== 'editable' || target.display !== 'visible') return
}
const tasks = []
target.query(pattern).forEach((field) => {
Expand Down Expand Up @@ -946,12 +941,7 @@ export const validateSelf = batch.bound(
}
}

if (
target.pattern !== 'editable' ||
target.display !== 'visible' ||
target.unmounted
)
return {}
if (target.pattern !== 'editable' || target.display !== 'visible') return {}
start()
if (!triggerType) {
const allTriggerTypes = parseValidatorDescriptions(target.validator).map(
Expand Down

0 comments on commit 8a01679

Please sign in to comment.