Skip to content

Instantly share code, notes, and snippets.

@danroberts
Last active August 14, 2019 17:28
Show Gist options
  • Save danroberts/0fe1b7ed58bc7c9f08e299529c346e80 to your computer and use it in GitHub Desktop.
Save danroberts/0fe1b7ed58bc7c9f08e299529c346e80 to your computer and use it in GitHub Desktop.
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))
}
})
}
}
// 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