Skip to content

Instantly share code, notes, and snippets.

@kazagkazag
Created July 8, 2016 12:41
Show Gist options
  • Select an option

  • Save kazagkazag/ef2f404b783178df80e9e5d89ad2ec4e to your computer and use it in GitHub Desktop.

Select an option

Save kazagkazag/ef2f404b783178df80e9e5d89ad2ec4e to your computer and use it in GitHub Desktop.
export const fetchAllStart = () => {
return {
type: constants.FETCH_ALL
};
};
export const fetchAllSuccess = (items) => {
return {
type: constants.FETCH_ALL_SUCCESS,
items
};
};
export const fetchAllError = (errorMessage) => {
return {
type: constants.FETCH_ALL_ERROR,
errorMessage
};
};
export const fetchAll = () => {
return (dispatch) => {
dispatch(fetchAllStart());
return fetch(constants.FETCH_ALL_URL)
.then(response => {
if(response.ok) {
return response.json();
}
else {
throw new Error(`${response.status} - ${response.statusText}`);
}
})
.then(data => {
dispatch(fetchAllSuccess(data.accounts));
})
.catch(error => {
dispatch(fetchAllError(error.message));
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment