Created
July 20, 2019 06:57
-
-
Save yaodong/6e00d7d15a2a316d26ad1ff7a8b18f94 to your computer and use it in GitHub Desktop.
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
a.js | |
const mapDispatchToProps = (dispatch) => { | |
create: function(name) { | |
dispatch(createUser(name)); | |
dispatch(displayUser(name)); | |
} | |
} | |
connect(mapDispatchToProps)(A) | |
-------------------------------------------------- | |
action.js | |
function createUserSuccess(name) { | |
return {type: "CREAT_URSER_OK", name: name}; | |
} | |
function createUserError(error) { | |
return {type: "CREAT_URSER_ERROR", error: error}; | |
} | |
function createUser(name) { | |
return function(dispatch) { | |
fetch(url).then((name) => { | |
dispatch(createUserSuccess(name)); | |
}) | |
.catch((error) => { | |
dispatch(createUserError(error)); | |
}) | |
} | |
} | |
function displayUser(name) { | |
return function(dispatch) { | |
validate() | |
.then(() => dispatch({type: "DISPLAY_USER", name: name})) | |
} | |
} | |
-------------------------------------------------------- | |
b.js | |
const mapDispatchToProps = (dispatch) => { | |
create: function(name) { | |
dispatch(createUser(name)); | |
dispatch(displayUser(name)); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment