Skip to content

Instantly share code, notes, and snippets.

@Sawtaytoes
Created December 12, 2019 05:14
Show Gist options
  • Save Sawtaytoes/d2a10f16e4e19ba3c02606d2f3b187c3 to your computer and use it in GitHub Desktop.
Save Sawtaytoes/d2a10f16e4e19ba3c02606d2f3b187c3 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',
{
password,
username,
},
)
.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