Skip to content

Commit a1c4def

Browse files
authored
Merge pull request #30 from combine/react-router-v4
Upgrade to React Router v4
2 parents c9eed8d + dd66bd9 commit a1c4def

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1096
-1043
lines changed

.babelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"react"
55
],
66
"plugins": [
7+
"react-hot-loader/babel",
78
"transform-class-properties",
89
"transform-decorators",
910
"transform-object-rest-spread",

.npmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

.nvmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ Direct your browser to `http://localhost:3000`.
2626

2727
## Directory Structure
2828
```
29-
├── client
30-
│   └── index.js
31-
├── common
29+
├── client # Client-side code
30+
├── common # Shared code between client and server
3231
│   ├── css
3332
│   ├── fonts
3433
│   ├── images
@@ -40,22 +39,10 @@ Direct your browser to `http://localhost:3000`.
4039
│   │   ├── middleware # Middleware for redux
4140
│   │   ├── reducers # Redux reducers
4241
│   │   ├── routes # Routes each have an index.js which exports a react-router Route.
43-
│   │   ├── selectors # Selectors for getting state data
4442
│   │   └── store # Store configuration for production and dev.
4543
│   └── layouts # Layout files to be rendered by the server.
46-
├── nodemon.json
47-
├── package.json
48-
├── server
49-
│   ├── config.js
50-
│   ├── index.js
51-
│   └── server.js
52-
├── webpack
53-
│   ├── base.js
54-
│   ├── config.js
55-
│   ├── development.hot.js
56-
│   ├── development.js
57-
│   ├── isomorphic.js
58-
│   └── production.js
44+
├── server # Server-side code
45+
├── webpack # Webpack configuration files
5946
```
6047

6148
## CSS Modules

client/index.js

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import 'babel-polyfill';
22
import React from 'react';
33
import ReactDOM from 'react-dom';
44
import { Provider } from 'react-redux';
5-
import { Router } from 'react-router';
6-
import { browserHistory } from 'react-router';
7-
import { syncHistoryWithStore } from 'react-router-redux';
5+
import { ConnectedRouter } from 'react-router-redux';
6+
import { AppContainer } from 'react-hot-loader';
7+
import createHistory from 'history/createBrowserHistory';
88
import configureStore from 'store';
9-
import routes from 'routes';
9+
import App from 'containers/App';
10+
11+
const history = createHistory();
1012

1113
/* Images
1214
* This space is reserved for images that are required by server rendering,
@@ -20,13 +22,26 @@ const rootElement = document.getElementById('app');
2022
// Creates the Redux store based on the initial state passed down by the server
2123
// rendering.
2224
const initialState = window.__INITIAL_STATE__;
23-
const store = configureStore(initialState);
24-
const history = syncHistoryWithStore(browserHistory, store);
25+
const store = configureStore(initialState, history);
26+
27+
const render = (Component) => {
28+
ReactDOM.render(
29+
<Provider store={store}>
30+
<AppContainer>
31+
<ConnectedRouter history={history}>
32+
<Component />
33+
</ConnectedRouter>
34+
</AppContainer>
35+
</Provider>,
36+
rootElement
37+
);
38+
};
39+
40+
render(App);
2541

26-
// Render the app!
27-
ReactDOM.render(
28-
<Provider store={store}>
29-
<Router history={history} routes={routes} />
30-
</Provider>,
31-
rootElement
32-
);
42+
if (module.hot) {
43+
// We need to re-require the main App module.
44+
module.hot.accept('../common/js/containers/App', () => {
45+
render(require('../common/js/containers/App').default);
46+
});
47+
}

common/js/actions/.gitkeep

Whitespace-only changes.

common/js/actions/todos.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { ADD_TODO, REMOVE_TODO, TOGGLE_TODO } from 'constants';
2+
import generateActionCreator from 'lib/generateActionCreator';
3+
4+
export const addTodo = generateActionCreator(ADD_TODO, 'text');
5+
export const removeTodo = generateActionCreator(REMOVE_TODO, 'id');
6+
export const toggleTodo = generateActionCreator(TOGGLE_TODO, 'id');
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* 404.js
3+
* Renders a 404 page.
4+
*/
5+
6+
import React from 'react';
7+
import PropTypes from 'prop-types';
8+
9+
const ERROR_MESSAGES = {
10+
404: 'The page you requested was not found.',
11+
500: 'The server encountered an error.'
12+
};
13+
14+
const ErrorPage = (props) => {
15+
const { message } = props;
16+
17+
return (
18+
<div>
19+
<h1>Sorry!</h1>
20+
<p>{message}</p>
21+
</div>
22+
);
23+
};
24+
25+
ErrorPage.propTypes = {
26+
code: PropTypes.number,
27+
message: PropTypes.string
28+
};
29+
30+
ErrorPage.defaultProps = {
31+
code: 404,
32+
message: ERROR_MESSAGES[404]
33+
};
34+
35+
export default ErrorPage;

common/js/components/Example/index.js

Lines changed: 0 additions & 24 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)