Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lulalachen/d59327c6f6977b70a43de5c4482d4e39 to your computer and use it in GitHub Desktop.
Save lulalachen/d59327c6f6977b70a43de5c4482d4e39 to your computer and use it in GitHub Desktop.
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
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