import { Action } from '@ngrx/store' ; import { Actions } from '../actions' ; import { FormControlState , FormControlValueTypes , isArrayState , isGroupState } from '../state' ; import { clearAsyncErrorReducer } from './reducer/clear-async-error' ; import { disableReducer } from './reducer/disable' ; import { enableReducer } from './reducer/enable' ; import { focusReducer } from './reducer/focus' ; import { markAsDirtyReducer } from './reducer/mark-as-dirty' ; import { markAsPristineReducer } from './reducer/mark-as-pristine' ; import { markAsSubmittedReducer } from './reducer/mark-as-submitted' ; import { markAsTouchedReducer } from './reducer/mark-as-touched' ; import { markAsUnsubmittedReducer } from './reducer/mark-as-unsubmitted' ; import { markAsUntouchedReducer } from './reducer/mark-as-untouched' ; import { resetReducer } from './reducer/reset' ; import { setAsyncErrorReducer } from './reducer/set-async-error' ; import { setErrorsReducer } from './reducer/set-errors' ; import { setUserDefinedPropertyReducer } from './reducer/set-user-defined-property' ; import { setValueReducer } from './reducer/set-value' ; import { startAsyncValidationReducer } from './reducer/start-async-validation' ; import { unfocusReducer } from './reducer/unfocus' ; export function formControlReducerInternal < TValue extends FormControlValueTypes > ( state , action ) { if ( isGroupState ( state ) || isArrayState ( state ) ) { throw new Error ( 'The state must be a control state' ) ; } if ( action . controlId !== state . id ) { return state ; } state = setValueReducer ( state , action ) ; state = setErrorsReducer ( state , action ) ; state = startAsyncValidationReducer ( state , action ) ; state = setAsyncErrorReducer ( state , action ) ; state = clearAsyncErrorReducer ( state , action ) ; state = enableReducer ( state , action ) ; state = disableReducer ( state , action ) ; state = focusReducer ( state , action ) ; state = unfocusReducer ( state , action ) ; state = markAsDirtyReducer ( state , action ) ; state = markAsPristineReducer ( state , action ) ; state = markAsTouchedReducer ( state , action ) ; state = markAsUntouchedReducer ( state , action ) ; state = markAsSubmittedReducer ( state , action ) ; state = markAsUnsubmittedReducer ( state , action ) ; state = setUserDefinedPropertyReducer ( state , action ) ; state = resetReducer ( state , action ) ; return state ; } /**
 * This reducer function updates a form control state with actions.
 */ export function formControlReducer < TValue extends FormControlValueTypes > ( state , action ) { if ( ! state ) { throw new Error ( 'The control state must be defined!' ) ; } return formControlReducerInternal ( state , action as any ) ; }