text: import { applyMiddleware, compose, createStore } from 'redux';
  import { routerMiddleware } from 'react-router-redux';
  import thunk from 'redux-thunk';
  import makeRootReducer from './reducers';
  
  const stores = {};
  
  export const getStore = (storeKey = 'main') => stores[storeKey];
  
  export default (initialState = {}, history, storeKey = 'main') => {
    if (stores[storeKey]) return stores[storeKey];
  
    // ======================================================
    // Middleware Configuration
    // ======================================================
    const middleware = [thunk, routerMiddleware(history)];
  
    // ======================================================
    // Store Enhancers
    // ======================================================
    const enhancers = [];
    if (__DEBUG__) {
      const devToolsExtension = window.devToolsExtension;
      if (typeof devToolsExtension === 'function') {
        enhancers.push(devToolsExtension());
      }
    }
  
    // ======================================================
    // Store Instantiation and HMR Setup
    // ======================================================
    const store = createStore(
      makeRootReducer(),
      initialState,
      compose(
        applyMiddleware(...middleware),
        ...enhancers
      )
    );
    store.asyncReducers = {};
  
    if (module.hot) {
      module.hot.accept('./reducers', () => {
        const reducers = require('./reducers').default;
        store.replaceReducer(reducers);
      });
    }
  
    stores[storeKey] = store;
  
    return store;
  };
  