Last active
June 7, 2016 06:19
-
-
Save lulalachen/e5c82976cf932d15fa72 to your computer and use it in GitHub Desktop.
Redux Action Inprovemnet
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 { genAuthHeaderFromState } from '../api'; | |
import { default as apiFetcher } from '../api/apiFetcher'; | |
// redux-api-middleware | |
export const orderList = () => ({ | |
[CALL_API]: ({ | |
endpoint: 'http://food.com/order/list/', | |
method: 'GET', | |
headers: genAuthHeadersFromState, | |
}) | |
}) | |
// http-client on native fetcher | |
export const orderNoodle = | |
(dispatch, getState) => | |
apiFetcher | |
.get('/order/noodle/', { | |
header: genAuthHeaderFromState(getState()), | |
}) | |
.then(data => dispatch(data)); | |
export const orderMeals = | |
(dispatch, getState) => | |
apiFetcher | |
.post('/order/noodle/', { | |
header: genAuthHeaderFromState(getState()), | |
body: { | |
'main_course': 'beef steak', | |
'side': 'vegi', | |
'soup': 'tomato soup', | |
} | |
}) | |
.then(data => dispatch(data)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
return 都可以省