michaltakac/mathworldvr

View on GitHub
src/store/configureStore.dev.js

Summary

Maintainability
A
0 mins
Test Coverage
import { createStore, applyMiddleware, compose } from 'redux'
import thunk from 'redux-thunk'
import { createLogger } from 'redux-logger'
import rootReducer from '../reducers'

const logger = createLogger({
  collapsed: true,
  duration: true,
})

const configureStore = initialState => {
  const hasWindow = typeof window !== 'undefined'

  const store = createStore(
    rootReducer,
    initialState,
    compose(
      applyMiddleware(thunk, logger),
      hasWindow && window.devToolsExtension ? window.devToolsExtension() : f => f
    )
  )

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

  return store
}

export default configureStore