import { Store } from 'redux' ; import { GenericState , UndoableStateBase } from '../models/index' ; import { applyMiddleware , compose , createStore , Middleware , StoreEnhancer } from 'redux' ; import { createActionLog } from 'redux-action-log' ; import { createLogger } from 'redux-logger' ; import thunkMiddleware from 'redux-thunk' ; import { DEFAULT_STATE , State } from '../models' ; import { rootReducer } from '../reducers' ; import { createQueryListener } from './listener' ; const loggerMiddleware = createLogger ( { collapsed : true , level : 'debug' } ) ; let composeEnhancers = compose ; const middleware = [ thunkMiddleware ] ; if ( process . env . NODE_ENV !== 'production' && process . env . NODE_ENV !== 'test' ) { composeEnhancers = ( window as any ) . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose ; middleware . push ( loggerMiddleware ) ; } export let actionLogs ; export function configureStore ( initialState = DEFAULT_STATE ) { actionLogs = createActionLog ( { limit : null } ) ; const store = createStore < State > ( rootReducer , initialState , composeEnhancers ( applyMiddleware ( ... middleware ) , actionLogs . enhancer ) as StoreEnhancer < any > ) ; if ( module . hot ) { module . hot . accept ( '../reducers' , ( ) => { const nextRootReducer = require ( '../reducers' ) . rootReducer ; store . replaceReducer ( nextRootReducer ) ; } ) ; } store . subscribe ( createQueryListener ( store ) ) ; return store ; }