Skip to content

Instantly share code, notes, and snippets.

@carlosble
Last active April 5, 2017 22:05
Show Gist options
  • Save carlosble/6e67ae586a05dbd5d11690f49bbea8b7 to your computer and use it in GitHub Desktop.
Save carlosble/6e67ae586a05dbd5d11690f49bbea8b7 to your computer and use it in GitHub Desktop.
Asynchronous action processing data before sendin to the server
function saveAddress(address, serverApi) {
return function(dispatch, getState) {
dispatch({
type: types.SAVE_ADDRESS,
address: address
});
let cleanAddress = getState().address;
return serverApi.saveAddress(cleanAddress).then((json) => {
if (areEmailsDifferent(cleanAddress, address)) {
let response = Object.assign({}, json);
response.additionalMessage = messages.AddressSavedButSomeEmailsWhereWrong;
return response;
}
else {
return json;
}
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment