diff --git a/src/client/configureStore.js b/src/client/configureStore.js new file mode 100644 index 0000000000000000000000000000000000000000..eebcfd88c7212c1fd83462d7585195ad5acf6ed7 --- /dev/null +++ b/src/client/configureStore.js @@ -0,0 +1,26 @@ +import { createStore, applyMiddleware, compose, bindActionCreators } from 'redux' +import { createEpicMiddleware } from 'redux-observable' +import { actions as toastrActions } from 'react-redux-toastr' +import reducer from './reducers' +import rootEpic from './epics' + +export default function configureStore (preloadedState) { + const epicMiddleware = createEpicMiddleware() + const middlewares = [epicMiddleware] + + // https://github.com/zalmoxisus/redux-devtools-extension#11-basic-store + const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose + + const composedEnhancers = composeEnhancers( + applyMiddleware(...middlewares) + // other store enhancers could be added here + ) + + const store = createStore(reducer, preloadedState, composedEnhancers) + + epicMiddleware.run(rootEpic) + + bindActionCreators(toastrActions, store.dispatch) + + return store +} diff --git a/src/client/index.js b/src/client/index.js index 35e8261a100a5e2f9c478070929e441d0f2305c5..3f65f304e59e2cff9659c72e4f6f1ea56218b488 100644 --- a/src/client/index.js +++ b/src/client/index.js @@ -1,13 +1,10 @@ import React from 'react' import { render } from 'react-dom' -import { createStore, applyMiddleware, compose, bindActionCreators } from 'redux' -import { createEpicMiddleware } from 'redux-observable' import { Provider } from 'react-redux' -import ReduxToastr, { actions as toastrActions } from 'react-redux-toastr' +import ReduxToastr from 'react-redux-toastr' import { Router } from 'react-router-dom' import history from './History' -import reducer from './reducers' -import rootEpic from './epics' +import configureStore from './configureStore' import App from './components/App' import { availableLocales } from './epics/index.js' import { loadLocales } from './actions' @@ -19,22 +16,7 @@ import 'react-sortable-tree/style.css' import 'react-redux-toastr/lib/css/react-redux-toastr.min.css' import 'mapbox-gl/dist/mapbox-gl.css' -const epicMiddleware = createEpicMiddleware() - -const middleware = applyMiddleware(epicMiddleware) - -const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose - -const store = createStore( - reducer, - compose( - composeEnhancers(middleware) - ) -) - -epicMiddleware.run(rootEpic) - -bindActionCreators(toastrActions, store.dispatch) +const store = configureStore() // init locale const localeFromUrl = window.location.pathname.substr(1, 2)