Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions src/actions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export default {
countIncrease (){
return {type: 'COUNT_INC'};
return { type: 'COUNT_INC' }
},
countDecrease (){
return {type: 'COUNT_DEC'};
return { type: 'COUNT_DEC' }
}
};
}
6 changes: 3 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import routes from './routes'
import store from './store'

ReactDom.render(
<Provider store={store}>
<Router routes={routes}/>
<Provider store={ store }>
<Router routes={ routes }/>
</Provider>,
document.getElementById('app')
);
)
41 changes: 20 additions & 21 deletions src/components/count.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
import React, { Component, PropTypes } from 'react'
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import actions from '../actions'

class Count extends Component {
render () {
const { currentValue, increase, decrease } = this.props;
return (
<div>
<h2>Count</h2>
<p>Current count: {currentValue}</p>
<p>
<button onClick={increase}>+</button>
<button onClick={decrease}>-</button>
</p>
</div>
)
}
const Count = (props) => {
const { currentValue, increase, decrease } = props

return (
<div>
<h2>Count</h2>
<p>Current count: { currentValue }</p>
<p>
<button onClick={ increase }>+</button>
<button onClick={ decrease }>-</button>
</p>
</div>
)
}

Count.propTypes = {
increase : PropTypes.func.isRequired,
decrease : PropTypes.func.isRequired
};
}

const mapStateToProps = (state) => state.count;
const mapStateToProps = (state) => state.count

const mapDispatchToProps = (dispatch) => {
return {
increase() {
dispatch(actions.countIncrease());
dispatch(actions.countIncrease())
},
decrease() {
dispatch(actions.countDecrease());
dispatch(actions.countDecrease())
}
}
};
}

export default connect(mapStateToProps, mapDispatchToProps)(Count);
export default connect(mapStateToProps, mapDispatchToProps)(Count)
23 changes: 10 additions & 13 deletions src/components/home.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import React, { Component } from 'react';

export default class Home extends Component {
render() {
return (
<div>
<h2>Hello World!</h2>
<p>Simple static component with not special content at all.</p>
</div>
)
}
import React from 'react'

const Home = () => {
return (
<div>
<h2>Hello World!</h2>
<p>Simple static component with not special content at all.</p>
</div>
)
}



export default Home
25 changes: 12 additions & 13 deletions src/components/nav.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import React, { Component } from 'react'
import React from 'react'
import { Link } from 'react-router'

export default class Nav extends Component {
render () {
return (
<div id="nav">
<ul>
<li><Link to="/">Home</Link></li>
<li><Link to="/count">Count</Link></li>
</ul>
<div className="clear"/>
</div>
)
}
const Nav = () => {
return (
<div id="nav">
<ul>
<li><Link to="/">Home</Link></li>
<li><Link to="/count">Count</Link></li>
</ul>
<div className="clear"/>
</div>
)
}

export default Nav
24 changes: 13 additions & 11 deletions src/components/wrap.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React, { Component } from 'react'
import React from 'react'
import Nav from './nav'

export default class Wrap extends Component {
render (){
return (
<div id="wrap">
<h1>React, React Router &amp; Redux example</h1>
<Nav/>
{ this.props.children }
</div>
)
}
const Wrap = (props) => {
const { children } = props

return (
<div id="wrap">
<h1>React, React Router &amp; Redux example</h1>
<Nav/>
{ children }
</div>
)
}

export default Wrap
7 changes: 4 additions & 3 deletions src/initial-state.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export default () => {
const initialState = () => {
return {
count: {
currentValue: 0
currentValue: 0
}
}
};
}

export default initialState
16 changes: 8 additions & 8 deletions src/reducers/count.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import initialState from './../initial-state'

const CountReducer = (state, action) => {
const newState = Object.assign({}, state);
const newState = Object.assign({}, state)
switch(action.type){
case 'COUNT_INC':
newState.currentValue += 1;
return newState;
newState.currentValue += 1
return newState
case 'COUNT_DEC':
newState.currentValue -= 1;
return newState;
newState.currentValue -= 1
return newState
default:
return state || initialState().count;
return state || initialState().count
}
};
}

export default CountReducer
export default CountReducer
14 changes: 7 additions & 7 deletions src/routes.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react'
import ReactRouter, { IndexRoute, Route } from 'react-router'
import Wrap from './components/wrap';
import Home from './components/home';
import Count from './components/count';
import Wrap from './components/wrap'
import Home from './components/home'
import Count from './components/count'

export default (
<Route path='/' component={Wrap}>
<IndexRoute component={Home}/>
<Route path='/count' component={Count}/>
<Route path='/' component={ Wrap }>
<IndexRoute component={ Home }/>
<Route path='/count' component={ Count }/>
</Route>
);
)
11 changes: 6 additions & 5 deletions src/store.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { combineReducers, createStore } from 'redux'
import initialState from './initial-state';
import countReducer from './reducers/count';
import initialState from './initial-state'
import countReducer from './reducers/count'

var reducers = combineReducers({
count: countReducer
});
})

var store = createStore(reducers, initialState());
var store = createStore(reducers, initialState())

export default store;
export default store