import { createStore, applyMiddleware, compose } from 'redux'
import promiseMiddleware from 'redux-promise'
import rootReducer from '../reducers'
import createLogger from 'redux-logger'
import { compact } from 'lodash'
import { serverLogger, apiMiddleware, cacheMiddleware, pendingPromiseMiddleware } from '../middleware'

export function configureStore (initialState, req) {
  const isServer = typeof window === 'undefined'

  var middleware = compact([
    isServer && serverLogger,
    cacheMiddleware,
    apiMiddleware(req),
    pendingPromiseMiddleware,
    promiseMiddleware,
    !isServer && createLogger({collapsed: true})
  ])

  const store = compose(
    applyMiddleware(...middleware)
  )(createStore)(rootReducer, initialState)

  if (module.onReload) {
    module.onReload(() => {
      const nextRootReducer = require('../reducers/index')
      store.replaceReducer(nextRootReducer)
      return true
    })
  }

  return store
}

@@ -690,16 +690,120 @@
 dleware)
+,%0A    !isServer && typeof window.devToolsExtension !== 'undefined' ? window.devToolsExtension() : f =%3E f
 %0A  )(cre

support redux dev tools chrome extension