Skip to content

Instantly share code, notes, and snippets.

@Sawtaytoes
Last active October 17, 2019 00:12
Show Gist options
  • Save Sawtaytoes/fb1ab870b741d24f567975391cdb1031 to your computer and use it in GitHub Desktop.
Save Sawtaytoes/fb1ab870b741d24f567975391cdb1031 to your computer and use it in GitHub Desktop.
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