This repository has been archived on 2018-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
image-juicer/app/store/configureStore.development.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

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 = {}) => {
// Redux Configuration
2017-04-06 15:23:47 -04:00
const middleware = [];
const enhancers = [];
// Thunk Middleware
2017-04-06 15:23:47 -04:00
middleware.push(thunk);
// Logging Middleware
2017-04-06 15:23:47 -04:00
const logger = createLogger({
level: 'info',
collapsed: true
});
middleware.push(logger);
// Router Middleware
2017-04-06 15:23:47 -04:00
const router = routerMiddleware(hashHistory);
middleware.push(router);
// Redux DevTools Configuration
2017-04-06 15:23:47 -04:00
const actionCreators = {
2017-04-06 15:23:47 -04:00
push,
};
// 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__
? 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,
})
: 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);
// Create Store
2017-04-06 15:23:47 -04:00
const store = createStore(rootReducer, initialState, enhancer);
2017-04-06 15:23:47 -04:00
if (module.hot) {
module.hot.accept('../reducers', () =>
store.replaceReducer(require('../reducers')) // eslint-disable-line global-require
);
2017-04-06 15:23:47 -04:00
}
2017-04-06 15:23:47 -04:00
return store;
};