import { IHeaderState , IHeaderAction } from './header.interface' ; import { PUSH_HEADER , REPLACE_HEADER , REMOVE_KEY_HEADER } from './header.types' ; const initialState = { headers : { } } ; const headerReducer = ( state = initialState , action ) : IHeaderState => { switch ( action . type ) { case PUSH_HEADER : { return { ... state , headers : { ... state . headers , [ action . payload . key as string ] : action . payload . header } } ; } case REPLACE_HEADER : { const hasKey = action . payload . key in state . headers ; if ( ! hasKey ) { return { ... state } ; } return { ... state , headers : { ... state . headers , [ action . payload . key as string ] : action . payload . header } } ; } case REMOVE_KEY_HEADER : { const newData = state ; if ( newData . headers [ action . payload . key ] ) { delete newData . headers [ action . payload . key ] ; } return { ... newData } ; } default : return state ; } } ; export default headerReducer ;