diff --git a/src/Index.jsx b/src/Index.jsx index 6392387..24251cf 100644 --- a/src/Index.jsx +++ b/src/Index.jsx @@ -3,22 +3,25 @@ import 'babel-polyfill'; import React from 'react'; import ReactDOM from 'react-dom'; import { Router, Route, IndexRoute } from 'react-router'; -import { createStore } from 'redux'; -import { Provider } from 'react-redux'; -import reducers from './reducers/reducers.js'; +import { Provider } from 'react-redux'; import App from './components/App.jsx'; import Home from './components/Home.jsx'; import LoginHandler from './components/LoginHandler.jsx'; + import MapExplorer from './components/MapExplorer.jsx'; import Teachers from './components/Teachers.jsx'; import TeachersDashboard from './components/TeachersDashboard.jsx'; import Styles from './styles/main.styl'; +import configureStore from './store/configureStore'; + +const store = configureStore(); + window.React = React; -let store = createStore(reducers); + ReactDOM.render( diff --git a/src/store/configureStore.js b/src/store/configureStore.js new file mode 100644 index 0000000..1df8c2e --- /dev/null +++ b/src/store/configureStore.js @@ -0,0 +1,17 @@ +import { createStore, applyMiddleware } from 'redux'; +import thunkMiddleware from 'redux-thunk'; +import rootReducer from '../reducers/reducers'; +const createStoreWithMiddleware = applyMiddleware(thunkMiddleware)(createStore); + +export default function configureStore(initialState) { + const store = createStoreWithMiddleware(rootReducer, initialState); + + if (module.hot) { + // Enable Webpack hot module replacement for reducers + module.hot.accept('../reducers/reducers', () => { + const nextRootReducer = require('../reducers/reducers'); + store.replaceReducer(nextRootReducer); + }); + } + return store; +}