import { AppStore } from './app-store' ; import { createStore , combineReducers , applyMiddleware , compose } from 'redux' ; import thunk from 'redux-thunk' ; export function applyDevTools ( debug ) { let isDebug = false ; if ( debug == undefined ) { isDebug = window && ! ! window . location . href . match ( /[?&]debug=([^&]+)\b/ ) ; } else { if ( debug instanceof Function ) { isDebug = debug ( ) ; } else { isDebug = debug ; } } isDebug = isDebug && window && window [ 'devToolsExtension' ] ; return isDebug ? window [ 'devToolsExtension' ] ( ) : f => f ; } /**
 * Factory for app store
 */ export function createAppStoreFactory ( reducers ? , additionalMiddlewares ? ) { return createAppStoreFactoryWithOptions ( { reducers , additionalMiddlewares } ) ; } export function createAppStoreFactoryWithOptions ( { reducers , additionalMiddlewares = [ ] , debug = false } ) { return ( ) => { let reducer = reducers ; if ( typeof reducer === 'object' ) { reducer = combineReducers ( reducers ) ; } const middleware = [ thunk ] ; let reduxAppStore ; let createStoreWithEnhancers ; if ( debug === undefined || ! debug ) { createStoreWithEnhancers = applyMiddleware ( ... middleware ) ( createStore ) ; reduxAppStore = createStoreWithEnhancers ( reducer ) ; } else { reduxAppStore = createStore ( reducer , compose ( applyMiddleware ( ... middleware , ... additionalMiddlewares ) , applyDevTools ( debug ) ) ) ; } return new AppStore ( reduxAppStore ) ; } ; }