Skip to content

Instantly share code, notes, and snippets.

@namelos
Created November 16, 2015 13:30
Show Gist options
  • Save namelos/3c1ade12f748513d00fc to your computer and use it in GitHub Desktop.
Save namelos/3c1ade12f748513d00fc to your computer and use it in GitHub Desktop.
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