Skip to content

Commit 73a3c19

Browse files
committed
Simpler setup
1 parent 7243b00 commit 73a3c19

File tree

14 files changed

+893
-641
lines changed

14 files changed

+893
-641
lines changed

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
"version": "0.1.0",
44
"private": true,
55
"devDependencies": {
6-
"react-scripts": "0.8.4"
6+
"react-scripts": "^0.9.5"
77
},
88
"dependencies": {
99
"react": "^15.4.2",
1010
"react-dom": "^15.4.2",
11-
"react-redux": "^5.0.1",
12-
"react-router": "^3.0.0",
13-
"react-router-redux": "^4.0.7",
11+
"react-redux": "^5.0.3",
12+
"react-router": "^4.0.0",
13+
"react-router-dom": "^4.0.0",
14+
"react-router-redux": "next",
1415
"redux": "^3.6.0",
15-
"redux-thunk": "^2.1.0"
16+
"redux-thunk": "^2.2.0",
17+
"sanitize.css": "^5.0.0"
1618
},
1719
"scripts": {
1820
"start": "react-scripts start",

src/containers/about/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import React from 'react'
22

3-
export default () => (
3+
const About = () => (
44
<div>
5-
<h1>About Us</h1>
6-
<p>We are interesting. I promise!</p>
5+
<h1>About Page</h1>
6+
<p>Did you get here via Redux?</p>
77
</div>
88
)
9+
10+
export default About

src/containers/app/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
2-
import { Link } from 'react-router'
2+
import { Link } from 'react-router-dom'
33

4-
export default ({ children }) => (
4+
const App = ({ children }) => (
55
<div>
66
<header>
77
<Link to="/">Home</Link>
@@ -13,3 +13,5 @@ export default ({ children }) => (
1313
</main>
1414
</div>
1515
)
16+
17+
export default App

src/containers/home/index.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
1-
import React, { Component } from 'react'
1+
import React from 'react'
22
import { push } from 'react-router-redux'
33
import { bindActionCreators } from 'redux'
44
import { connect } from 'react-redux'
5-
import { incrementAsync, decrementAsync } from '../../modules/counter'
5+
import {
6+
increment,
7+
incrementAsync,
8+
decrement,
9+
decrementAsync
10+
} from '../../modules/counter'
611

7-
class Home extends Component {
8-
render() {
9-
const { count, incrementAsync, decrementAsync, isIncrementing, isDecrementing, changePage } = this.props
12+
const Home = props => (
13+
<div>
14+
<h1>Home</h1>
15+
<p>Count: {props.count}</p>
1016

11-
return (
12-
<div>
13-
<h1>Home</h1>
14-
<p>Welcome home!</p>
15-
<p>Count: {count}</p>
16-
<p><button onClick={incrementAsync} disabled={isIncrementing}>Increment Async</button> <button onClick={decrementAsync} disabled={isDecrementing}>Decrement Async</button></p>
17-
<button onClick={() => changePage()}>Go to about page via redux</button>
18-
</div>
19-
)
20-
}
21-
}
17+
<p>
18+
<button onClick={props.increment} disabled={props.isIncrementing}>Increment</button>
19+
<button onClick={props.incrementAsync} disabled={props.isIncrementing}>Increment Async</button>
20+
</p>
21+
22+
<p>
23+
<button onClick={props.decrement} disabled={props.isDecrementing}>Decrementing</button>
24+
<button onClick={props.decrementAsync} disabled={props.isDecrementing}>Decrement Async</button>
25+
</p>
26+
27+
<p><button onClick={() => props.changePage()}>Go to about page via redux</button></p>
28+
</div>
29+
)
2230

2331
const mapStateToProps = state => ({
2432
count: state.counter.count,
@@ -27,11 +35,16 @@ const mapStateToProps = state => ({
2735
})
2836

2937
const mapDispatchToProps = dispatch => bindActionCreators({
38+
increment,
3039
incrementAsync,
40+
decrement,
3141
decrementAsync,
3242
changePage: () => {
3343
dispatch(push('/about-us'))
3444
}
3545
}, dispatch)
3646

37-
export default connect(mapStateToProps, mapDispatchToProps)(Home)
47+
export default connect(
48+
mapStateToProps,
49+
mapDispatchToProps
50+
)(Home)

src/index.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
html {
2+
font-size: 100%;
3+
}
4+
15
body {
26
margin: 0;
37
padding: 0;
4-
font-family: sans-serif;
8+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
9+
font-size: 1rem;
10+
line-height: 1.5;
511
}

src/index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
import React from 'react'
22
import { render } from 'react-dom'
33
import { Provider } from 'react-redux'
4-
import store from './store'
5-
6-
import Routes from './routes'
4+
import { Route } from 'react-router'
5+
import { ConnectedRouter } from 'react-router-redux'
6+
import store, { history } from './store'
7+
import App from './containers/app'
8+
import Home from './containers/home'
9+
import About from './containers/about'
710

11+
import 'sanitize.css/sanitize.css'
812
import './index.css'
913

1014
const target = document.querySelector('#root')
1115

1216
render(
1317
<Provider store={store}>
14-
<Routes />
18+
<ConnectedRouter history={history}>
19+
<App>
20+
<Route exact path="/" component={Home} />
21+
<Route exact path="/about-us" component={About} />
22+
</App>
23+
</ConnectedRouter>
1524
</Provider>,
1625
target
1726
)

src/modules/counter.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ export default (state = initialState, action) => {
4242
}
4343
}
4444

45+
export const increment = () => {
46+
return dispatch => {
47+
dispatch({
48+
type: INCREMENT_REQUESTED
49+
})
50+
51+
dispatch({
52+
type: INCREMENT
53+
})
54+
}
55+
}
56+
4557
export const incrementAsync = () => {
4658
return dispatch => {
4759
dispatch({
@@ -56,6 +68,18 @@ export const incrementAsync = () => {
5668
}
5769
}
5870

71+
export const decrement = () => {
72+
return dispatch => {
73+
dispatch({
74+
type: DECREMENT_REQUESTED
75+
})
76+
77+
dispatch({
78+
type: DECREMENT
79+
})
80+
}
81+
}
82+
5983
export const decrementAsync = () => {
6084
return dispatch => {
6185
dispatch({

src/modules/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { routerReducer } from 'react-router-redux'
33
import counter from './counter'
44

55
export default combineReducers({
6-
routing: routerReducer,
6+
router: routerReducer,
77
counter
88
})

src/routes.js

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

src/store.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { createStore, applyMiddleware, compose } from 'redux'
2+
import { routerMiddleware } from 'react-router-redux'
3+
import thunk from 'redux-thunk'
4+
import createHistory from 'history/createBrowserHistory'
5+
import rootReducer from './modules'
6+
7+
export const history = createHistory()
8+
9+
const initialState = {}
10+
const enhancers = []
11+
const middleware = [
12+
thunk,
13+
routerMiddleware(history)
14+
]
15+
16+
if (process.env.NODE_ENV === 'development') {
17+
const devToolsExtension = window.devToolsExtension
18+
19+
if (typeof devToolsExtension === 'function') {
20+
enhancers.push(devToolsExtension())
21+
}
22+
}
23+
24+
const composedEnhancers = compose(
25+
applyMiddleware(...middleware),
26+
...enhancers
27+
)
28+
29+
const store = createStore(
30+
rootReducer,
31+
initialState,
32+
composedEnhancers
33+
)
34+
35+
export default store

0 commit comments

Comments
 (0)