This file contains hidden or 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
// The classic AJAX call - dispatch before the request, and after it comes back | |
function myThunkActionCreator(someValue) { | |
return (dispatch, getState) => { | |
dispatch({type : "REQUEST_STARTED"}); | |
myAjaxLib.post("/someEndpoint", {data : someValue}) | |
.then(response => dispatch({type : "REQUEST_SUCCEEDED", payload : response}) | |
.catch(error => dispatch({type : "REQUEST_FAILED", error : error}); | |
}; | |
} |
This file contains hidden or 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
/** | |
* README FIRST:::::::::::::::::: | |
* | |
* This isn't meant to necessarily be an example of "best practices" | |
* but rather to generally show how you might convert the redux-thunk examples | |
* here: https://gist.github.com/markerikson/ea4d0a6ce56ee479fe8b356e099f857e | |
* | |
* The redux-thunk examples used generic placeholder names, so it's possible | |
* I misunderstood the usecase/intent. | |
* |
This file contains hidden or 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 oauthUserEpic = (action$) => | |
action$ | |
.ofType(OAUTH_USER) | |
.concatMap(({ token }) => | |
get({ | |
endpoint: 'user', | |
params: { access_token: token } | |
}) // assuming get() returns an Observable | |
.map((user) => | |
addUser( |