import { Reducer } from 'redux' ; import { ADD_SLOT_TO_ON_FILL_STACK , REMOVE_SLOT_FROM_ON_FILL_STACK } from '../actions' ; import { OnFillStackItem } from '../types' ; import { removeSlotFromSlotIdArray } from '../helpers' ; const reducer = ( prev = [ ] , action ) : OnFillStackItem [ ] => { if ( action . type === ADD_SLOT_TO_ON_FILL_STACK ) { const slotToAdd = { slotName : action . payload . slotName , abilityName : action . payload . abilityName , message : action . payload . value } ; return [ ... prev , slotToAdd ] ; } if ( action . type === REMOVE_SLOT_FROM_ON_FILL_STACK ) { const slotToRemove = action . payload ; const { slotName , abilityName } = slotToRemove ; const updatedState = removeSlotFromSlotIdArray ( prev , { slotName , abilityName } ) ; return updatedState ; } return prev ; } ; export default reducer ;