Skip to content

Commit

Permalink
update 170420 20:12
Browse files Browse the repository at this point in the history
  • Loading branch information
SPxiaomin committed Apr 20, 2017
1 parent 66ce00f commit 63df585
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 29 deletions.
1 change: 1 addition & 0 deletions Test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"jquery": "^3.1.1",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-redux": "^5.0.4",
"redux": "^3.6.0"
},
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions Test/src/actions/index.js
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'
};
};
14 changes: 14 additions & 0 deletions Test/src/components/App.js
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;
9 changes: 9 additions & 0 deletions Test/src/components/Change.js
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;
9 changes: 9 additions & 0 deletions Test/src/components/Hello.js
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;
18 changes: 18 additions & 0 deletions Test/src/containers/ClickChange.js
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;
24 changes: 24 additions & 0 deletions Test/src/containers/VisibleHello.js
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;
26 changes: 10 additions & 16 deletions Test/src/index.js
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);
28 changes: 20 additions & 8 deletions Test/src/reducers/index.js
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;
2 changes: 1 addition & 1 deletion react-redux-es6-quickstart/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { createStore, bindActionCreators } from 'redux';
import { Provider, connect } from 'react-redux';
import { Provider } from 'react-redux';
import myApp from './reducers';
import App from './components/App';

Expand Down

0 comments on commit 63df585

Please sign in to comment.