import { applyMiddleware, createStore } from 'redux'
import { routerMiddleware } from 'react-router-redux'
import thunk from 'redux-thunk'
import makeRootReducer from './reducers'

export default (initialState = {}, history) => {
  // ======================================================
  // Middleware Configuration
  // ======================================================
  const middleware = [thunk, routerMiddleware(history)]

  // ======================================================
  // Developer Tools
  // ======================================================
  if (__DEBUG__) {
    const devToolsExtension = window.devToolsExtension
    if (typeof devToolsExtension === 'function') {
      middleware.push(devToolsExtension())
    }
  }

  // ======================================================
  // Store Instantiation and HMR Setup
  // ======================================================
  const store = createStore(
    makeRootReducer(),
    initialState,
    applyMiddleware(...middleware)
  )
  store.asyncReducers = {}

  if (module.hot) {
    module.hot.accept('./reducers', () => {
      const reducers = require('./reducers').default
      store.replaceReducer(reducers)
    })
  }

  return store
}

@@ -18,16 +18,25 @@
 dleware,
+ compose,
  createS
@@ -51,24 +51,24 @@
 rom 'redux'%0A
-
 import %7B rou
@@ -508,22 +508,22 @@
  // 
-Developer Tool
+Store Enhancer
 s%0A  
@@ -580,16 +580,39 @@
 =======%0A
+  const enhancers = %5B%5D%0A
   if (__
@@ -734,26 +734,25 @@
 %7B%0A      
-middleware
+enhancers
 .push(de
@@ -1010,16 +1010,31 @@
 lState,%0A
+    compose(%0A  
     appl
@@ -1059,16 +1059,42 @@
 dleware)
+,%0A      ...enhancers%0A    )
 %0A  )%0A  s

fix devTools being applied incorrectly