const { createStore, combineReducers } = require('redux')
const { prop, identity, defaultTo, add, subtract, concat, always } = require('ramda')
const [INCREMENT, DECREMENT, PUSH, RESET] = ['INCREMENT', 'DECREMENT', 'PUSH', 'RESET']
const createAction = type => payload => ({ type, payload })
const createReducer = (actions, INITIAL) =>
(state = INITIAL, { type, payload }) =>
defaultTo(identity, prop(type, actions))(state, payload)
const addNumbers = createAction(PUSH)
const decrementCount = createAction(DECREMENT)
const count = createReducer({ [INCREMENT]: add, [DECREMENT]: subtract }, 0)
const numbers = createReducer({ [PUSH]: concat, [RESET]: always([]) }, [])
const { subscribe, dispatch, getState } = createStore(combineReducers({ count, numbers }))
subscribe(() => console.log(getState()))
dispatch(addNumbers([1, 2, 3]))
dispatch(decrementCount(10))