From f88fc9aba2fad7a47188e1226200fba36d472ef8 Mon Sep 17 00:00:00 2001 From: Oskar Klintrot Date: Fri, 25 Dec 2015 11:15:55 +0100 Subject: [PATCH 1/5] Removed inconsistent semicolons --- src/actions.js | 6 +++--- src/app.js | 2 +- src/components/count.js | 14 +++++++------- src/components/home.js | 5 +---- src/initial-state.js | 3 +-- src/reducers/count.js | 16 ++++++++-------- src/routes.js | 8 ++++---- src/store.js | 10 +++++----- 8 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/actions.js b/src/actions.js index ea49772..c497cdc 100644 --- a/src/actions.js +++ b/src/actions.js @@ -1,8 +1,8 @@ export default { countIncrease (){ - return {type: 'COUNT_INC'}; + return {type: 'COUNT_INC'} }, countDecrease (){ - return {type: 'COUNT_DEC'}; + return {type: 'COUNT_DEC'} } -}; \ No newline at end of file +} diff --git a/src/app.js b/src/app.js index d70f2e4..89e8892 100644 --- a/src/app.js +++ b/src/app.js @@ -10,4 +10,4 @@ ReactDom.render( , document.getElementById('app') -); \ No newline at end of file +) diff --git a/src/components/count.js b/src/components/count.js index a902d86..82fe576 100644 --- a/src/components/count.js +++ b/src/components/count.js @@ -4,7 +4,7 @@ import actions from '../actions' class Count extends Component { render () { - const { currentValue, increase, decrease } = this.props; + const { currentValue, increase, decrease } = this.props return (

Count

@@ -21,19 +21,19 @@ class Count extends Component { 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); \ No newline at end of file +export default connect(mapStateToProps, mapDispatchToProps)(Count) diff --git a/src/components/home.js b/src/components/home.js index 88dba2b..71be493 100644 --- a/src/components/home.js +++ b/src/components/home.js @@ -1,4 +1,4 @@ -import React, { Component } from 'react'; +import React, { Component } from 'react' export default class Home extends Component { render() { @@ -10,6 +10,3 @@ export default class Home extends Component { ) } } - - - diff --git a/src/initial-state.js b/src/initial-state.js index 747fb11..c72d757 100644 --- a/src/initial-state.js +++ b/src/initial-state.js @@ -4,5 +4,4 @@ export default () => { currentValue: 0 } } -}; - +} diff --git a/src/reducers/count.js b/src/reducers/count.js index 5df96ff..5d30a50 100644 --- a/src/reducers/count.js +++ b/src/reducers/count.js @@ -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 \ No newline at end of file +export default CountReducer diff --git a/src/routes.js b/src/routes.js index 954f6b8..d873f51 100644 --- a/src/routes.js +++ b/src/routes.js @@ -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 ( -); \ No newline at end of file +) diff --git a/src/store.js b/src/store.js index 4b0e120..7d1b8f2 100644 --- a/src/store.js +++ b/src/store.js @@ -1,10 +1,10 @@ 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; \ No newline at end of file +export default store From dc67ddc8df4843361184e4ecbec696df3cf3466b Mon Sep 17 00:00:00 2001 From: Oskar Klintrot Date: Fri, 25 Dec 2015 11:22:23 +0100 Subject: [PATCH 2/5] Using new ES2015 keyword const instead of using a funtion that returns an object to achive read only --- src/initial-state.js | 10 +++++----- src/reducers/count.js | 2 +- src/store.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/initial-state.js b/src/initial-state.js index c72d757..c4919ed 100644 --- a/src/initial-state.js +++ b/src/initial-state.js @@ -1,7 +1,7 @@ -export default () => { - return { - count: { - currentValue: 0 - } +const initialState = { + count: { + currentValue: 0 } } + +export default initialState diff --git a/src/reducers/count.js b/src/reducers/count.js index 5d30a50..e494e22 100644 --- a/src/reducers/count.js +++ b/src/reducers/count.js @@ -10,7 +10,7 @@ const CountReducer = (state, action) => { newState.currentValue -= 1 return newState default: - return state || initialState().count + return state || initialState.count } } diff --git a/src/store.js b/src/store.js index 7d1b8f2..62ea03c 100644 --- a/src/store.js +++ b/src/store.js @@ -5,6 +5,6 @@ var reducers = combineReducers({ count: countReducer }) -var store = createStore(reducers, initialState()) +var store = createStore(reducers, initialState) export default store From c0905c0a98dc87e07dda260a6a4d805038a81b70 Mon Sep 17 00:00:00 2001 From: Oskar Klintrot Date: Fri, 25 Dec 2015 11:29:38 +0100 Subject: [PATCH 3/5] Using React 0.14 stateless function components --- src/components/count.js | 29 ++++++++++++++--------------- src/components/home.js | 20 ++++++++++---------- src/components/nav.js | 25 ++++++++++++------------- src/components/wrap.js | 24 +++++++++++++----------- 4 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/components/count.js b/src/components/count.js index 82fe576..1670be7 100644 --- a/src/components/count.js +++ b/src/components/count.js @@ -1,21 +1,20 @@ -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 ( -
-

Count

-

Current count: {currentValue}

-

- - -

-
- ) - } +const Count = (props) => { + const { currentValue, increase, decrease } = props + + return ( +
+

Count

+

Current count: {currentValue}

+

+ + +

+
+ ) } Count.propTypes = { diff --git a/src/components/home.js b/src/components/home.js index 71be493..a1ab7c2 100644 --- a/src/components/home.js +++ b/src/components/home.js @@ -1,12 +1,12 @@ -import React, { Component } from 'react' +import React from 'react' -export default class Home extends Component { - render() { - return ( -
-

Hello World!

-

Simple static component with not special content at all.

-
- ) - } +const Home = () => { + return ( +
+

Hello World!

+

Simple static component with not special content at all.

+
+ ) } + +export default Home diff --git a/src/components/nav.js b/src/components/nav.js index 81ec4b3..598304f 100644 --- a/src/components/nav.js +++ b/src/components/nav.js @@ -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 ( -