Skip to content

Fat arrow functions in the counter example #1942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2016
Merged
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
11 changes: 3 additions & 8 deletions examples/counter/src/components/Counter.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import React, { Component, PropTypes } from 'react'

class Counter extends Component {
constructor(props) {
super(props)
this.incrementAsync = this.incrementAsync.bind(this)
this.incrementIfOdd = this.incrementIfOdd.bind(this)
}

incrementIfOdd() {

incrementIfOdd = () => {
if (this.props.value % 2 !== 0) {
this.props.onIncrement()
}
}

incrementAsync() {
incrementAsync = () => {
setTimeout(this.props.onIncrement, 1000)
}

Expand Down
18 changes: 8 additions & 10 deletions examples/counter/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ import counter from './reducers'
const store = createStore(counter)
const rootEl = document.getElementById('root')

function render() {
ReactDOM.render(
<Counter
value={store.getState()}
onIncrement={() => store.dispatch({ type: 'INCREMENT' })}
onDecrement={() => store.dispatch({ type: 'DECREMENT' })}
/>,
rootEl
)
}
const render = () => ReactDOM.render(
<Counter
value={store.getState()}
onIncrement={() => store.dispatch({ type: 'INCREMENT' })}
onDecrement={() => store.dispatch({ type: 'DECREMENT' })}
/>,
rootEl
)

render()
store.subscribe(render)
2 changes: 1 addition & 1 deletion examples/counter/src/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function counter(state = 0, action) {
export default (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1
Expand Down