-
-
Save wuct/38d16d7a95fdd00aa3dd 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, genTokenFromState } from '../api'; | |
import { default as apiStack } from '../api/apiStack'; | |
import { createFetch, auth, body, method } from 'http-client'; | |
// 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) => | |
createFetch( | |
apiStack, | |
auth(genTokenFromState(getState())) | |
)('/order/noodle/') | |
.then(data => dispatch(data)) | |
export const orderMeals = (dispatch, getState) => | |
createFetch( | |
apiStack, | |
auth(genTokenFromState(getState())), | |
method('POST'), | |
body(JSON.stringify(data), 'application/json') | |
)('/order/noodle/') | |
.then(data => dispatch(data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment