Skip to content

Commit fb40a77

Browse files
authored
Merge pull request #40 from combine/feature/upgrade-to-rhl4
Feature: Upgrade to react-hot-loader v4
2 parents 2ffd187 + d67b1b8 commit fb40a77

File tree

6 files changed

+2836
-382
lines changed

6 files changed

+2836
-382
lines changed

.eslintrc

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"parser": "babel-eslint",
33
"rules": {
4+
"max-len": [
5+
"error",
6+
{ "code": 80, "tabWidth": 2 }
7+
],
48
"indent": [
59
1,
610
2,
@@ -30,10 +34,12 @@
3034
"node": true
3135
},
3236
"globals": {
33-
'__BASE_URL__': true,
34-
expect: true
37+
"expect": true
3538
},
36-
"extends": "eslint:recommended",
39+
"extends": [
40+
"eslint:recommended",
41+
"plugin:react/recommended"
42+
],
3743
"parserOptions": {
3844
"sourceType": "module",
3945
"ecmaFeatures": {
@@ -43,6 +49,7 @@
4349
"ecmaVersion": 6
4450
},
4551
"plugins": [
46-
"react"
52+
"babel",
53+
"react"
4754
]
4855
}

client/index.js

+11-29
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,21 @@ import React from 'react';
33
import ReactDOM from 'react-dom';
44
import { Provider } from 'react-redux';
55
import { ConnectedRouter } from 'react-router-redux';
6-
import { AppContainer } from 'react-hot-loader';
76
import createHistory from 'history/createBrowserHistory';
87
import configureStore from 'store';
98
import App from 'containers/App';
109

11-
const history = createHistory();
12-
13-
// The root element of your app
14-
const rootElement = document.getElementById('app');
15-
16-
// Creates the Redux store based on the initial state passed down by the server
17-
// rendering.
10+
// Hydrate the redux store from server state.
1811
const initialState = window.__INITIAL_STATE__;
12+
const history = createHistory();
1913
const store = configureStore(initialState, history);
2014

21-
const render = (Component) => {
22-
ReactDOM.hydrate(
23-
<Provider store={store}>
24-
<AppContainer>
25-
<ConnectedRouter history={history}>
26-
<Component />
27-
</ConnectedRouter>
28-
</AppContainer>
29-
</Provider>,
30-
rootElement
31-
);
32-
};
33-
34-
render(App);
35-
36-
if (module.hot) {
37-
// We need to re-require the main App module.
38-
module.hot.accept('../common/js/containers/App', () => {
39-
render(require('../common/js/containers/App').default);
40-
});
41-
}
15+
// Render the application
16+
ReactDOM.hydrate(
17+
<Provider store={store}>
18+
<ConnectedRouter history={history}>
19+
<App />
20+
</ConnectedRouter>
21+
</Provider>,
22+
document.getElementById('app')
23+
);

common/js/containers/App/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Switch } from 'react-router-dom';
33
import { RouteWithSubRoutes } from 'components/common';
44
import { Container } from 'semantic-ui-react';
55
import { Header, Footer } from 'components/common';
6+
import { hot } from 'react-hot-loader';
67
import routes from 'routes';
78

89
const App = () => (
@@ -17,4 +18,4 @@ const App = () => (
1718
</Container>
1819
);
1920

20-
export default App;
21+
export default hot(module)(App);

common/js/containers/Todos/index.js

+25-16
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,28 @@ import PropTypes from 'prop-types';
33
import { connect } from 'react-redux';
44
import { Helmet } from 'react-helmet';
55
import { addTodo, toggleTodo, removeTodo, fetchTodos } from 'actions/todos';
6-
import { Container, Header, Checkbox, List, Button, Form } from 'semantic-ui-react';
6+
import {
7+
Container,
8+
Header,
9+
Checkbox,
10+
List,
11+
Button,
12+
Form
13+
} from 'semantic-ui-react';
714
import classnames from 'classnames';
815
import css from './index.scss';
916

1017
const cx = classnames.bind(css);
1118

1219
class TodosContainer extends Component {
20+
static fetchData = ({ store }) => {
21+
return store.dispatch(fetchTodos());
22+
};
1323

1424
static propTypes = {
1525
todos: PropTypes.object.isRequired,
1626
dispatch: PropTypes.func.isRequired
17-
}
27+
};
1828

1929
state = { todoText: '' };
2030

@@ -26,30 +36,30 @@ class TodosContainer extends Component {
2636
}
2737
}
2838

29-
submitTodo = (ev) => {
39+
submitTodo = ev => {
3040
const { dispatch } = this.props;
3141
const { todoText } = this.state;
3242

3343
ev.preventDefault();
3444
dispatch(addTodo(todoText));
3545
this.setState({ todoText: '' });
36-
}
46+
};
3747

38-
checkTodo = (id) => {
48+
checkTodo = id => {
3949
const { dispatch } = this.props;
4050

4151
dispatch(toggleTodo(id));
42-
}
52+
};
4353

44-
removeTodo = (id) => {
54+
removeTodo = id => {
4555
const { dispatch } = this.props;
4656

4757
dispatch(removeTodo(id));
48-
}
58+
};
4959

50-
onTodoChange = (ev) => {
60+
onTodoChange = ev => {
5161
this.setState({ todoText: ev.target.value });
52-
}
62+
};
5363

5464
render() {
5565
const { todos: { todos } } = this.props;
@@ -81,7 +91,9 @@ class TodosContainer extends Component {
8191
onChange={() => this.checkTodo(id)}
8292
/>
8393
</List.Content>
84-
<List.Content className={cx(css.text, { [css.completed]: completed })}>
94+
<List.Content
95+
className={cx(css.text, { [css.completed]: completed })}
96+
>
8597
{text}
8698
</List.Content>
8799
</List.Item>
@@ -94,7 +106,8 @@ class TodosContainer extends Component {
94106
onChange={this.onTodoChange}
95107
value={todoText}
96108
type="text"
97-
placeholder="Add a todo..." />
109+
placeholder="Add a todo..."
110+
/>
98111
<Form.Button content="Add" icon="plus" />
99112
</Form.Group>
100113
</Form>
@@ -103,10 +116,6 @@ class TodosContainer extends Component {
103116
}
104117
}
105118

106-
TodosContainer.fetchData = ({ store }) => {
107-
return store.dispatch(fetchTodos());
108-
};
109-
110119
const mapStateToProps = ({ todos }) => ({ todos });
111120

112121
export default connect(mapStateToProps)(TodosContainer);

0 commit comments

Comments
 (0)