import { createStore , compose , applyMiddleware , Reducer , Store } from 'redux' ; import localForage from 'localforage' ; import { persistReducer , persistStore } from 'redux-persist' ; import { api } from '../middlewares/api' ; import { exportStateMiddleware } from '../middlewares/exportState' ; import { rootReducer , StoreState } from '../reducers' ; import { StoreAction } from '../actions' ; const persistConfig = { key : 'redux-devtools' , blacklist : [ 'instances' , 'socket' ] , storage : localForage , } ; const persistedReducer = persistReducer ( persistConfig , rootReducer ) as any ; export default function configureStore ( callback ) { let composeEnhancers = compose ; if ( process . env . NODE_ENV !== 'production' ) { if ( ( window as unknown as { __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? : typeof compose ; } ) . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ) { composeEnhancers = ( window as unknown as { __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : typeof compose ; } ) . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ; } if ( module . hot ) { module . hot . accept ( '../reducers' , ( ) => { const nextReducer = require ( '../reducers' ) ; store . replaceReducer ( nextReducer as Reducer < StoreState , StoreAction > ) ; } ) ; } } const store = createStore ( persistedReducer , composeEnhancers ( applyMiddleware ( exportStateMiddleware , api ) ) ) ; const persistor = persistStore ( store , null , ( ) => { callback ( store ) ; } ) ; return { store , persistor } ; }