All files / src/redux configureStore.js

0% Statements 0/22
0% Branches 0/6
0% Functions 0/4
0% Lines 0/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46                                                                                           
import createSagaMiddleware from 'redux-saga';
import { routerMiddleware } from 'react-router-redux';
import { applyMiddleware, compose, createStore } from 'redux';
 
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage'; // defaults to localStorage for web and AsyncStorage for react-native
 
import sagas from './rootSagas';
import rootReducer from './rootReducers';
 
const persistConfig = {
    key: 'root',
    storage
};
 
const persistedReducer = persistReducer(persistConfig, rootReducer);
 
// Redux DevTools Extension for Chrome and Firefox
const reduxDevTool = () => {
    return typeof window === 'object' && typeof window.devToolsExtension !== 'undefined'
        ? window.devToolsExtension()
        : f => f;
};
 
export default function configureStore(initialState, history) {
    const sagaMiddleware = createSagaMiddleware();
    const middleware = applyMiddleware(sagaMiddleware, routerMiddleware(history));
 
    const composedStoreEnhancer = compose(
        middleware,
        reduxDevTool()
    );
 
    const store = composedStoreEnhancer(createStore)(persistedReducer, initialState);
    const persistor = persistStore(store);
    sagaMiddleware.run(sagas);
 
    if (module.hot) {
        module.hot.accept('./rootReducers', () => {
            store.replaceReducer(require('./rootReducers'));
        });
    }
 
    return { store, persistor };
}