Last active
October 17, 2019 00:12
-
-
Save Sawtaytoes/fb1ab870b741d24f567975391cdb1031 to your computer and use it in GitHub Desktop.
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 fetchUserEpic = ( | |
action$, | |
state$, | |
{ dispatch }, | |
) => ( | |
action$ | |
.pipe( | |
ofType(FETCH_USER), | |
tap(() => { | |
dispatch( | |
setLoading( | |
'login', | |
) | |
) | |
}), | |
switchMap(({ | |
password, | |
username, | |
}) => ( | |
ajax | |
.getJSON( | |
'https://api.example.com/login' | |
) | |
.pipe( | |
catchError(( | |
error, | |
) => { | |
dispatch( | |
fetchUserFailed( | |
error, | |
) | |
) | |
return EMPTY | |
}), | |
) | |
)), | |
tap(({ | |
authToken, | |
}) => { | |
dispatch( | |
fetchUserSucceeded( | |
authToken, | |
) | |
) | |
dispatch( | |
setLoaded( | |
'login', | |
) | |
) | |
}), | |
ignoreElements(), | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment