-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react' | ||
|
||
const increment = (state) => ({ count: state.count + 1 }) | ||
const decrement = (state) => ({ count: state.count - 1 }) | ||
|
||
class CounterPlain extends React.Component { | ||
state = { count: 0 } | ||
|
||
render () { | ||
return ( | ||
<div> | ||
<div>{this.state.count}</div> | ||
<button type='button' onClick={() => this.setState(increment)}>+</button> | ||
<button type='button' onClick={() => this.setState(decrement)}>-</button> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
module.exports = CounterPlain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react' | ||
import { connect } from 'react-redux' | ||
import { incrementCounter, decrementCounter } from './actions' | ||
|
||
const Counter = (props) => ( | ||
<div> | ||
<div>{props.count}</div> | ||
<button onClick={props.incrementCounter}>+</button> | ||
<button onClick={props.decrementCounter}>-</button> | ||
</div> | ||
) | ||
|
||
const mapStateToProps = (state) => ({ | ||
count: state.count | ||
}) | ||
|
||
const mapDispatchToProps = (dispatch) => ({ | ||
incrementCounter: () => dispatch(incrementCounter()), | ||
decrementCounter: () => dispatch(decrementCounter()) | ||
}) | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(Counter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const incrementCounter = (amount = 1) => ({ | ||
type: 'INCREMENT', | ||
value: amount | ||
}) | ||
|
||
export const decrementCounter = (amount = 1) => ({ | ||
type: 'DECREMENT', | ||
value: amount | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { createStore } from 'redux' | ||
import counterReducer from './reducer' | ||
import Counter from './Counter' | ||
|
||
const store = createStore(counterReducer) | ||
|
||
const CounterRedux = () => ( | ||
<Provider store={store}> | ||
<Counter /> | ||
</Provider> | ||
) | ||
|
||
export default CounterRedux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const counterReducer = (state = { count: 0 }, action) => { | ||
switch (action.type) { | ||
case 'INCREMENT': | ||
return { count: state.count + 1 } | ||
case 'DECREMENT': | ||
return { count: state.count - 1 } | ||
default: | ||
return state | ||
} | ||
} | ||
|
||
export default counterReducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react' | ||
import Code from '../../components/Code' | ||
import PageTitle from '../../components/PageTitle' | ||
import Example from '../../components/Example' | ||
import CounterPlain from './CounterPlain' | ||
import CounterRedux from './CounterRedux' | ||
|
||
const Page = (props) => ( | ||
<div> | ||
<PageTitle text='State Management' /> | ||
|
||
<p> | ||
blah, blah, blah, choose something | ||
</p> | ||
|
||
<Code language='jsx'>{`/* CounterPlain/index.js */ | ||
import React from 'react' | ||
const increment = (state) => ({ count: state.count + 1 }) | ||
const decrement = (state) => ({ count: state.count - 1 }) | ||
class CounterPlain extends React.Component { | ||
state = { count: 0 } | ||
render () { | ||
return ( | ||
<div> | ||
<div>{this.state.count}</div> | ||
<button type='button' onClick={() => this.setState(increment)}>+</button> | ||
<button type='button' onClick={() => this.setState(decrement)}>-</button> | ||
</div> | ||
) | ||
} | ||
} | ||
module.exports = CounterPlain`}</Code> | ||
|
||
<Example live> | ||
<CounterPlain /> | ||
</Example> | ||
|
||
<PageTitle text='State management systems' /> | ||
|
||
<p>Redux</p> | ||
|
||
<Example live> | ||
<CounterRedux /> | ||
</Example> | ||
|
||
<p>MobX</p> | ||
</div> | ||
) | ||
|
||
export default Page |