Created
July 8, 2016 12:41
-
-
Save kazagkazag/ef2f404b783178df80e9e5d89ad2ec4e 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
| 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