Last active
April 1, 2016 01:39
-
-
Save lulalachen/d59327c6f6977b70a43de5c4482d4e39 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
const fetcherCreateReduxStandardAPIActionMiddleware = () => { | |
return next => action => { | |
const { promise, type, ...rest } = action | |
if (!promise) return next(action) | |
const SUCCESS = type + '_SUCCESS' | |
const REQUEST = type + '_REQUEST' | |
const FAILURE = type + '_FAILURE' | |
next({ ...rest, type: REQUEST }) | |
return promise | |
.then(req => { | |
next({ ...rest, req, type: SUCCESS }) | |
return true | |
}) | |
.catch(error => { | |
next({ ...rest, error, type: FAILURE }); | |
console.log(error); | |
return false; | |
}); | |
}; | |
} | |
export default fetcherCreateReduxStandardAPIActionMiddleware |
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
import fetcherCreateReduxStandardAPIActionMiddleware from './fetcherCreateReduxStandardAPIActionMiddleware' | |
import { createFetch, method } from 'http-client' | |
export listOrders = | |
() => | |
(dispatch, getState) => | |
createFetch( | |
method('GET'), | |
).('http://api.food.io/foods/') | |
.then(() => ()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment