Skip to content

Commit 80197ef

Browse files
committed
Change examples to explicitly use replaceReducer() for hot reloading
1 parent 7f00f29 commit 80197ef

File tree

18 files changed

+128
-113
lines changed

18 files changed

+128
-113
lines changed

examples/async/containers/AsyncApp.js renamed to examples/async/containers/App.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { selectReddit, fetchPostsIfNeeded, invalidateReddit } from '../actions';
44
import Picker from '../components/Picker';
55
import Posts from '../components/Posts';
66

7-
class AsyncApp extends Component {
7+
class App extends Component {
88
constructor(props) {
99
super(props);
1010
this.handleChange = this.handleChange.bind(this);
@@ -72,7 +72,7 @@ class AsyncApp extends Component {
7272
}
7373
}
7474

75-
AsyncApp.propTypes = {
75+
App.propTypes = {
7676
selectedReddit: PropTypes.string.isRequired,
7777
posts: PropTypes.array.isRequired,
7878
isFetching: PropTypes.bool.isRequired,
@@ -99,4 +99,4 @@ function mapStateToProps(state) {
9999
};
100100
}
101101

102-
export default connect(mapStateToProps)(AsyncApp);
102+
export default connect(mapStateToProps)(App);

examples/async/containers/Root.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/async/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import 'babel-core/polyfill';
2-
32
import React from 'react';
4-
import Root from './containers/Root';
3+
import { Provider } from 'react-redux';
4+
import App from './containers/App';
5+
import configureStore from './store/configureStore';
6+
7+
const store = configureStore();
58

69
React.render(
7-
<Root />,
10+
<Provider store={store}>
11+
{() => <App />}
12+
</Provider>,
813
document.getElementById('root')
914
);

examples/async/store/configureStore.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,15 @@ const createStoreWithMiddleware = applyMiddleware(
99
)(createStore);
1010

1111
export default function configureStore(initialState) {
12-
return createStoreWithMiddleware(rootReducer, initialState);
12+
const store = createStoreWithMiddleware(rootReducer, initialState);
13+
14+
if (module.hot) {
15+
// Enable Webpack hot module replacement for reducers
16+
module.hot.accept('../reducers', () => {
17+
const nextRootReducer = require('../reducers');
18+
store.replaceReducer(nextRootReducer);
19+
});
20+
}
21+
22+
return store;
1323
}
File renamed without changes.

examples/counter/containers/Root.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/counter/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import React from 'react';
2-
import Root from './containers/Root';
2+
import { Provider } from 'react-redux';
3+
import App from './containers/App';
4+
import configureStore from './store/configureStore';
5+
6+
const store = configureStore();
37

48
React.render(
5-
<Root />,
9+
<Provider store={store}>
10+
{() => <App />}
11+
</Provider>,
612
document.getElementById('root')
713
);
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import { createStore, applyMiddleware } from 'redux';
22
import thunk from 'redux-thunk';
3-
import rootReducer from '../reducers';
3+
import reducer from '../reducers';
44

55
const createStoreWithMiddleware = applyMiddleware(
66
thunk
77
)(createStore);
88

99
export default function configureStore(initialState) {
10-
return createStoreWithMiddleware(rootReducer, initialState);
10+
const store = createStoreWithMiddleware(reducer, initialState);
11+
12+
if (module.hot) {
13+
// Enable Webpack hot module replacement for reducers
14+
module.hot.accept('../reducers', () => {
15+
const nextReducer = require('../reducers');
16+
store.replaceReducer(nextReducer);
17+
});
18+
}
19+
20+
return store;
1121
}

examples/counter/test/containers/CounterApp.spec.js renamed to examples/counter/test/containers/App.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import expect from 'expect';
22
import jsdomReact from '../jsdomReact';
33
import React from 'react/addons';
44
import { Provider } from 'react-redux';
5-
import CounterApp from '../../containers/CounterApp';
5+
import App from '../../containers/App';
66
import configureStore from '../../store/configureStore';
77

88
const { TestUtils } = React.addons;
@@ -11,7 +11,7 @@ function setup(initialState) {
1111
const store = configureStore(initialState);
1212
const app = TestUtils.renderIntoDocument(
1313
<Provider store={store}>
14-
{() => <CounterApp />}
14+
{() => <App />}
1515
</Provider>
1616
);
1717
return {

examples/real-world/containers/Root.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)