Skip to content

Instantly share code, notes, and snippets.

@lulalachen
Last active June 7, 2016 06:19
Show Gist options
  • Save lulalachen/e5c82976cf932d15fa72 to your computer and use it in GitHub Desktop.
Save lulalachen/e5c82976cf932d15fa72 to your computer and use it in GitHub Desktop.
Redux Action Inprovemnet
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));
@wuct
Copy link

wuct commented Mar 10, 2016

return 都可以省

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment