Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.

Add root store with middleware. #30

Merged
merged 4 commits into from
Feb 9, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/Index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ 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 { Provider } from 'react-redux';

import App from './components/App.jsx';

import reducers from './reducers/reducers.js';
//import reducers from './reducers/reducers.js';
import Home from './components/Home.jsx';
import Teachers from './components/Teachers.jsx';
import TeachersDashboard from './components/TeachersDashboard.jsx'
import MapExplorer from './components/MapExplorer.jsx';
import Styles from './styles/main.styl';

import configureStore from './store/configureStore';

const store = configureStore();

window.React = React;
let store = createStore(reducers)

ReactDOM.render(
<Provider store={store}>
<Router>
Expand Down
18 changes: 18 additions & 0 deletions src/store/configureStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
//import rootReducer from '../reducers';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trash this if we don't need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rogerhutchings updated.

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
}