import { assocPath } from 'ramda'; import { FLOW_ACTIONS } from './constants'; import { flowSetNodes, flowSetHeroes, flowSetRecent, flowSetUpdated, flowSetFlow, flowSetSearch, } from './actions'; import { IFlowState } from './reducer'; const setNodes = (state: IFlowState, { nodes }: ReturnType) => assocPath(['nodes'], nodes, state); const setHeroes = (state: IFlowState, { heroes }: ReturnType) => assocPath(['heroes'], heroes, state); const setRecent = (state: IFlowState, { recent }: ReturnType) => assocPath(['recent'], recent, state); const setUpdated = (state: IFlowState, { updated }: ReturnType) => assocPath(['updated'], updated, state); const setFlow = (state: IFlowState, { data }: ReturnType): IFlowState => ({ ...state, ...data, }); const setSearch = ( state: IFlowState, { search }: ReturnType ): IFlowState => ({ ...state, search: { ...state.search, ...search, }, }); export const FLOW_HANDLERS = { [FLOW_ACTIONS.SET_NODES]: setNodes, [FLOW_ACTIONS.SET_HEROES]: setHeroes, [FLOW_ACTIONS.SET_RECENT]: setRecent, [FLOW_ACTIONS.SET_UPDATED]: setUpdated, [FLOW_ACTIONS.SET_FLOW]: setFlow, [FLOW_ACTIONS.SET_SEARCH]: setSearch, };