import { AbilityStatus } from '../types' ; import { Reducer } from 'redux' ; import { SET_ABILITY_STATUS } from '../actions' ; const reducer = ( prev = [ ] , action ) : AbilityStatus [ ] => { if ( action . type === SET_ABILITY_STATUS ) { const { abilityName , value : isCompleted } = action . payload ; const abilityStatus = [ ... prev ] ; const targetIndex = abilityStatus . findIndex ( ( _ ) => _ . abilityName === abilityName ) ; if ( targetIndex !== - 1 ) { abilityStatus [ targetIndex ] = { abilityName , isCompleted } ; return abilityStatus ; } abilityStatus . push ( { abilityName , isCompleted } ) ; return abilityStatus ; } return prev ; } ; export default reducer ;