Skip to content

Commit

Permalink
fix(core): rollback onFieldInit behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Apr 16, 2021
1 parent a54cf82 commit 15f9a56
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/core/src/effects/onFieldEffects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function createFieldEffect<Result extends GeneralField = GeneralField>(
}
)
}
export const onFieldInit = createFieldEffect(LifeCycleTypes.ON_FIELD_INIT)
const _onFieldInit = createFieldEffect(LifeCycleTypes.ON_FIELD_INIT)
export const onFieldMount = createFieldEffect(LifeCycleTypes.ON_FIELD_MOUNT)
export const onFieldUnmount = createFieldEffect(LifeCycleTypes.ON_FIELD_UNMOUNT)
export const onFieldValueChange = createFieldEffect<DataField>(
Expand All @@ -53,6 +53,20 @@ export const onFieldValidateSuccess = createFieldEffect<DataField>(
LifeCycleTypes.ON_FIELD_VALIDATE_SUCCESS
)

export function onFieldInit(
pattern: FormPathPattern,
callback?: (field: GeneralField, form: Form) => void
) {
const form = useEffectForm()
const count = form.query(pattern).reduce((count, field) => {
callback(field, form)
return count + 1
}, 0)
if (count === 0) {
_onFieldInit(pattern, callback)
}
}

export function onFieldReact(
pattern: FormPathPattern,
callback?: (field: GeneralField, form: Form) => void
Expand Down

0 comments on commit 15f9a56

Please sign in to comment.