Last active
August 14, 2019 17:28
-
-
Save danroberts/0fe1b7ed58bc7c9f08e299529c346e80 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
function getSatellites() { | |
return (dispatch, getState) { | |
api.fetch('getOrganizations').then((response) { | |
//if handling this data response is at all complicated, then you need to duplicate it. | |
dispatch(recieveOrganizations(response.data)) | |
api.fetch('getSatellites', getState().organizations).then(response) { | |
dispatch(receiveSatellites(response.data)) | |
} | |
}) | |
} | |
} | |
function someOtherFunctionThatNeedsOrganizations() { | |
return (dispatch, getState) { | |
api.fetch('getOrganizations').then((response) { | |
dispatch(recieveOrganizations(response.data)) | |
api.fetch('otherApiCall', getState().organizations).then(response) { | |
dispatch(receiveOther(response.data)) | |
} | |
}) | |
} | |
} |
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
// using thunks that return promises | |
function getOrganizations() { | |
return (dispatch, getState) { | |
return api.fetch('getOrganizations').then((response) { | |
dispatch(recieveOrganizations(response.data)) | |
} | |
} | |
} | |
function getSatellites() { | |
return (dispatch, getState) { | |
dispatch(getOrganizations).then(() => { | |
api.fetch('getSatellites', getState().organizations).then(response) { | |
dispatch(receiveSatellites(response.data)) | |
} | |
}) | |
} | |
} | |
function someOtherFunctionThatNeedsOrganizations() { | |
return (dispatch, getState) { | |
dispatch(getOrganizations).then(() => { | |
api.fetch('otherApiCall', getState().organizations).then(response) { | |
dispatch(receiveOther(response.data)) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment