Last active
April 7, 2016 16:37
-
-
Save emilong/5e8fe5925912fa12dfe3dd35686ae383 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function fetchSomething(thingId) { | |
return (dispatch) => { | |
// update call metadata | |
dispatch(startRequest(thingId)) | |
return fetch(`https://api.example.com/things/${thingId}`) | |
.then((response) => response.json()) | |
// send the result of the call, probably updating the request metadata as well | |
.then((json) => dispatch(receiveAThing(json))) | |
// update the metadata to indicate a failure | |
.catch((err) => dispatch(thingGettingFailed(err))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment