Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
type: string
) => (...args: Props): Observable => {
if (!env.effectStart || env.effectEnd) {
throw new Error(
'EffectHook must be called synchronously within the effects callback function.'
)
}
if (!env.effectSelector) {
throw new Error('Can not found effect hook selector.')
}
return env.effectSelector(type, ...args)
}
export const FormEffectHooks = {
onFormWillInit$: createEffectHook(
LifeCycleTypes.ON_FORM_WILL_INIT
),
onFormInit$: createEffectHook(LifeCycleTypes.ON_FORM_INIT),
onFormChange$: createEffectHook(LifeCycleTypes.ON_FORM_CHANGE),
onFormInputChange$: createEffectHook(
LifeCycleTypes.ON_FORM_INPUT_CHANGE
),
onFormInitialValueChange$: createEffectHook(
LifeCycleTypes.ON_FORM_INITIAL_VALUES_CHANGE
),
onFormReset$: createEffectHook(LifeCycleTypes.ON_FORM_RESET),
onFormSubmitValidateStart$: createEffectHook(
LifeCycleTypes.ON_FORM_SUBMIT_VALIDATE_START
),
onFormSubmitValidateSuccess$: createEffectHook(
LifeCycleTypes.ON_FORM_SUBMIT_VALIDATE_SUCCESSif (type === LifeCycleTypes.ON_FORM_INPUT_CHANGE) {
if (props.onChange) {
props.onChange(
isStateModel(payload)
? payload.getState((state: IFormState) => state.values)
: {}
)
}
}
if (broadcast) {
broadcast.notify({ type, payload })
}
}
),
new FormLifeCycle(
LifeCycleTypes.ON_FORM_WILL_INIT,
(payload: IModel, form: IForm) => {
const actions = {
...form,
dispatch: form.notify
}
if (broadcast) {
broadcast.setContext(actions)
}
implementActions(actions)
}
)
],
onReset: props.onReset,
onSubmit: props.onSubmit,
onValidateFailed: props.onValidateFailed
})