import { createStore , applyMiddleware , compose } from 'redux' ; import { fromJS } from 'immutable' ; import { routerMiddleware } from 'react-router-redux' ; import createSagaMiddleware from 'redux-saga' ; import { History } from 'history' ; import { IStore } from './Interfaces/store' ; import createReducer from './reducers' ; const sagaMiddleware = createSagaMiddleware ( ) ; export default function configureStore ( initialState = { } , history ) { const middlewares = [ sagaMiddleware , routerMiddleware ( history ) ] ; const enhancers = [ applyMiddleware ( ... middlewares ) ] ; const composeEnhancers = process . env . NODE_ENV !== 'production' && typeof window === 'object' && window . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : compose ; const store = createStore ( createReducer ( ) , fromJS ( initialState ) , composeEnhancers ( ... enhancers ) ) as IStore ; store . runSaga = sagaMiddleware . run ; store . injectedReducers = { } ; store . injectedSagas = { } ; if ( module . hot ) { module . hot . accept ( './reducers' , ( ) => { store . replaceReducer ( createReducer ( store . injectedReducers ) ) ; } ) ; } return store ; }