Created
November 16, 2015 13:30
-
-
Save namelos/3c1ade12f748513d00fc 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
export default store => next => action => { | |
if (!action.request) | |
return next(action) | |
const { types, request, ...rest } = action | |
const [ REQUEST, SUCCESS, FAILURE ] = types | |
next({ ...rest, type: REQUEST }) | |
fetch(request) | |
.then(res => res.json()) | |
.then(json => next({ ...rest, json, type: SUCCESS })) | |
.catch(err => { | |
console.error('error when fetch data: ', err) | |
next({ ...rest, err, type: FAILURE }) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment