2017-04-05 16:15:35 -04:00
|
|
|
import { createStore, applyMiddleware, compose } from 'redux';
|
|
|
|
import thunk from 'redux-thunk';
|
|
|
|
import { hashHistory } from 'react-router';
|
|
|
|
import { routerMiddleware, push } from 'react-router-redux';
|
|
|
|
import { createLogger } from 'redux-logger';
|
|
|
|
import rootReducer from '../reducers';
|
|
|
|
|
2017-04-05 16:28:26 -04:00
|
|
|
export default (initialState = {}) => {
|
2017-04-05 16:15:35 -04:00
|
|
|
// Redux Configuration
|
2017-04-06 15:23:47 -04:00
|
|
|
const middleware = [];
|
|
|
|
const enhancers = [];
|
2017-04-05 16:15:35 -04:00
|
|
|
|
|
|
|
// Thunk Middleware
|
2017-04-06 15:23:47 -04:00
|
|
|
middleware.push(thunk);
|
2017-04-05 16:15:35 -04:00
|
|
|
|
|
|
|
// Logging Middleware
|
2017-04-06 15:23:47 -04:00
|
|
|
const logger = createLogger({
|
|
|
|
level: 'info',
|
|
|
|
collapsed: true
|
|
|
|
});
|
|
|
|
middleware.push(logger);
|
2017-04-05 16:15:35 -04:00
|
|
|
|
|
|
|
// Router Middleware
|
2017-04-06 15:23:47 -04:00
|
|
|
const router = routerMiddleware(hashHistory);
|
|
|
|
middleware.push(router);
|
2017-04-05 16:15:35 -04:00
|
|
|
|
|
|
|
// Redux DevTools Configuration
|
2017-04-06 15:23:47 -04:00
|
|
|
const actionCreators = {
|
2017-04-05 16:15:35 -04:00
|
|
|
|
2017-04-06 15:23:47 -04:00
|
|
|
push,
|
|
|
|
};
|
2017-04-05 16:15:35 -04:00
|
|
|
// If Redux DevTools Extension is installed use it, otherwise use Redux compose
|
|
|
|
/* eslint-disable no-underscore-dangle */
|
2017-04-06 15:23:47 -04:00
|
|
|
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
|
2017-04-05 16:15:35 -04:00
|
|
|
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
|
|
|
|
// Options: http://zalmoxisus.github.io/redux-devtools-extension/API/Arguments.html
|
2017-04-06 15:23:47 -04:00
|
|
|
actionCreators,
|
|
|
|
})
|
2017-04-05 16:15:35 -04:00
|
|
|
: compose;
|
|
|
|
/* eslint-enable no-underscore-dangle */
|
|
|
|
|
|
|
|
// Apply Middleware & Compose Enhancers
|
2017-04-06 15:23:47 -04:00
|
|
|
enhancers.push(applyMiddleware(...middleware));
|
|
|
|
const enhancer = composeEnhancers(...enhancers);
|
2017-04-05 16:15:35 -04:00
|
|
|
|
|
|
|
// Create Store
|
2017-04-06 15:23:47 -04:00
|
|
|
const store = createStore(rootReducer, initialState, enhancer);
|
2017-04-05 16:15:35 -04:00
|
|
|
|
2017-04-06 15:23:47 -04:00
|
|
|
if (module.hot) {
|
|
|
|
module.hot.accept('../reducers', () =>
|
2017-04-05 16:15:35 -04:00
|
|
|
store.replaceReducer(require('../reducers')) // eslint-disable-line global-require
|
|
|
|
);
|
2017-04-06 15:23:47 -04:00
|
|
|
}
|
2017-04-05 16:15:35 -04:00
|
|
|
|
2017-04-06 15:23:47 -04:00
|
|
|
return store;
|
2017-04-05 16:15:35 -04:00
|
|
|
};
|