-
Notifications
You must be signed in to change notification settings - Fork 4
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
10 changed files
with
110 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
export const Increment = () => { | ||
export const changeText = () => { | ||
return { | ||
type: 'INCREMENT' | ||
type: 'CHANGE_TEXT' | ||
}; | ||
}; | ||
|
||
export const Decrement = () => { | ||
export const buttonClick = () => { | ||
return { | ||
type: 'DECREMENT' | ||
type: 'BUTTON_CLICK' | ||
}; | ||
}; |
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,14 @@ | ||
import React from 'react'; | ||
import VisibleHello from '../containers/VisibleHello'; | ||
import ClickChange from '../containers/ClickChange'; | ||
|
||
const App = () => { | ||
return ( | ||
<div> | ||
<VisibleHello /> | ||
<ClickChange /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; |
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 @@ | ||
import React from 'react'; | ||
|
||
const Change = ({buttonClick}) => { | ||
return ( | ||
<button onClick={buttonClick}>change</button> | ||
); | ||
}; | ||
|
||
export default Change; |
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 @@ | ||
import React from 'react'; | ||
|
||
const Hello = ({text, changeText}) => { | ||
return ( | ||
<h1 onClick={changeText}>{text}</h1> | ||
); | ||
}; | ||
|
||
export default Hello; |
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,18 @@ | ||
import { connect } from 'react-redux'; | ||
import Change from '../components/Change'; | ||
import { buttonClick } from '../actions'; | ||
|
||
function mapDispatchToProps(dispatch) { | ||
return { | ||
buttonClick: () => { | ||
dispatch(buttonClick()); | ||
} | ||
}; | ||
} | ||
|
||
const ClickChange = connect( | ||
null, | ||
mapDispatchToProps | ||
)(Change); | ||
|
||
export default ClickChange; |
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,24 @@ | ||
import { connect } from 'react-redux'; | ||
import Hello from '../components/Hello'; | ||
import { changeText } from '../actions'; | ||
|
||
function mapStateToProps(state) { | ||
return { | ||
text: state.text | ||
}; | ||
} | ||
|
||
function mapDispatchToProps(dispatch) { | ||
return { | ||
changeText: () => { | ||
dispatch(changeText()); | ||
} | ||
}; | ||
} | ||
|
||
const VisibleHello = connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(Hello); | ||
|
||
export default VisibleHello; |
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 |
---|---|---|
@@ -1,21 +1,15 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { createStore } from 'redux'; | ||
import Counter from './components/Counter'; | ||
import counter from './reducers'; | ||
import { Increment, Decrement } from './actions'; | ||
import { createStore, bindActionCreators } from 'redux'; | ||
import { Provider } from 'react-redux'; | ||
import myApp from './reducers'; | ||
import App from './components/App'; | ||
|
||
const store = createStore(counter); | ||
const rootEl = document.getElementById('root'); | ||
let store = createStore(myApp); | ||
|
||
const render = () => ReactDOM.render( | ||
<Counter | ||
value={store.getState()} | ||
onIncrement={() => store.dispatch(Increment())} | ||
onDecrement={() => store.dispatch(Decrement())} | ||
/>, | ||
rootEl | ||
ReactDOM.render( | ||
<Provider store={store}> | ||
<App /> | ||
</Provider>, | ||
document.getElementById('root') | ||
); | ||
|
||
render(); | ||
store.subscribe(render); |
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 |
---|---|---|
@@ -1,10 +1,22 @@ | ||
export default (state = 0, actions) => { | ||
switch (actions.type) { | ||
case 'INCREMENT': | ||
return state + 1; | ||
case 'DECREMENT': | ||
return state - 1; | ||
const initialState = { | ||
text: 'Hello' | ||
}; | ||
|
||
const myApp = (state = initialState, action) => { | ||
switch (action.type) { | ||
case 'CHANGE_TEXT': | ||
return { | ||
text: state.text === 'Hello' ? 'Stark' : 'Hello' | ||
}; | ||
case 'BUTTON_CLICK': | ||
return { | ||
text: 'you just click button' | ||
}; | ||
default: | ||
return state; | ||
return { | ||
text: 'Hello' | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
export default myApp; |
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