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

export default (preloadState = {}, history) => {
  const middlewares = [
    routerMiddleware(history)
  ]

  const composeEnhancers =
    process.env.NODE_ENV !== 'production' &&
    typeof window === 'object' &&
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
      window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose

  const enhancer = composeEnhancers(applyMiddleware(...middlewares))

  const store = createStore(TebukuroApp, {}, enhancer)

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

  return store
}

@@ -105,24 +105,70 @@
 uter-redux'%0A
+import promiseMiddleware from 'redux-promise'%0A
 import Tebuk
@@ -296,16 +296,39 @@
 history)
+,%0A    promiseMiddleware
 %0A  %5D%0A%0A  

Add redux-promise middleware