import { applyMiddleware, compose, combineReducers, createStore } from 'redux' import { connectRouter, routerMiddleware } from 'connected-react-router' import { createBrowserHistory } from 'history' import thunk from 'redux-thunk' import uploadReducer from 'app/views/upload/upload.reducer' import graphReducer from 'app/views/graph/graph.reducer' import pageReducer from 'app/views/page/page.reducer' import tileReducer from 'app/views/tile/tile.reducer' import siteReducer from './views/site/site.reducer' const createRootReducer = history => ( combineReducers({ auth: (state = {}) => state, router: connectRouter(history), site: siteReducer, graph: graphReducer, page: pageReducer, tile: tileReducer, upload: uploadReducer, }) ) const configureStore = (initialState = {}, history) => { const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose const store = createStore( createRootReducer(history), initialState, composeEnhancers( applyMiddleware( thunk, routerMiddleware(history) ), ), ) return store } const history = createBrowserHistory() const store = configureStore({}, history) const { dispatch } = store export { store, history, dispatch }