import { applyMiddleware , compose , createStore } from 'redux' ; import thunk from 'redux-thunk' ; import { createHashHistory } from 'history' ; import { createLogger } from 'redux-logger' ; import createRootReducer from '../reducers' ; import api from '../middleware/api' ; import handler from '../middleware/handler' ; const history = createHashHistory ( ) ; const rootReducer = createRootReducer ( history ) ; const configureStore = ( initialState ) => { const middleware = [ ] ; const enhancers = [ ] ; middleware . push ( thunk ) ; middleware . push ( api ) ; middleware . push ( handler ) ; const logger = createLogger ( { level : 'info' , collapsed : true , } ) ; if ( process . env . NODE_ENV !== 'test' ) { middleware . push ( logger ) ; } const actionCreators = { } ; const composeEnhancers = window . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ( { actionCreators , } ) : compose ; enhancers . push ( applyMiddleware ( ... middleware ) ) ; const enhancer = composeEnhancers ( ... enhancers ) ; const store = createStore ( rootReducer , initialState , enhancer ) ; if ( module . hot ) { module . hot . accept ( '../reducers' , ( ) => store . replaceReducer ( require ( '../reducers' ) . default ) ) ; } return store ; } ; export default { configureStore , history } ;