import { Actions , EnableAction } from '../../actions' ; import { computeGroupState , FormGroupState , KeyValue } from '../../state' ; import { childReducer , dispatchActionPerChild } from './util' ; export function enableReducer < TValue extends KeyValue > ( state , action ) { if ( action . type !== EnableAction . TYPE ) { return state ; } if ( action . controlId !== state . id ) { return childReducer ( state , action ) ; } const controls = dispatchActionPerChild ( state . controls , controlId => new EnableAction ( controlId ) ) ; if ( controls === state . controls ) { return state ; } return computeGroupState ( state . id , controls , state . value , state . errors , state . pendingValidations , state . userDefinedProperties , { wasOrShouldBeDirty : state . isDirty , wasOrShouldBeEnabled : true , wasOrShouldBeTouched : state . isTouched , wasOrShouldBeSubmitted : state . isSubmitted , } ) ; }