Last active
April 17, 2017 21:16
-
-
Save andrewzey/d9c18321a4b3a9f7af375ac69534bb39 to your computer and use it in GitHub Desktop.
Redux Thunk with FSA Actions
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
// Without depending on forks of redux-thunk, here's | |
// how we would handle FSA actions created with redux-actions | |
// using redux-thunk middleware: | |
import { createAction } from 'redux-actions'; | |
const loginRequest = username => dispatch => { | |
dispatch(createAction('LOGIN_REQUEST')()); | |
return request('/login', { username }) | |
.then(resp => dispatch(loginSucess(resp))) | |
.catch(err => dispatch(loginFailure(err))); | |
}; | |
const loginSuccess = createAction('LOGIN_SUCCESS', resp => resp.body); | |
const loginFailure = createAction('LOGIN_FAILURE', err => err); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment