Skip to content

Commit

Permalink
feat(effects): normoalize onFieldInit
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Apr 16, 2021
1 parent 8a309cf commit 98922c8
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions 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>(
}
)
}
const _onFieldInit = createFieldEffect(LifeCycleTypes.ON_FIELD_INIT)
export 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,20 +53,6 @@ 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 98922c8

Please sign in to comment.