Skip to content

Instantly share code, notes, and snippets.

@Sawtaytoes
Created December 12, 2019 05:14
Show Gist options
  • Save Sawtaytoes/68a3dd4ea1072e3a739c80c424eb730c to your computer and use it in GitHub Desktop.
Save Sawtaytoes/68a3dd4ea1072e3a739c80c424eb730c to your computer and use it in GitHub Desktop.
const fetchUserEpic = (
action$,
) => (
action$
.pipe(
ofType(FETCH_USER),
switchMap(({
password,
username,
}) => (
merge(
of(
setLoading(
'login',
)
),
ajax
.getJSON(
'https://api.example.com/login',
{
password,
username,
},
)
.pipe(
switchMap(({
authToken,
}) => (
of(
(
fetchUserSucceeded(
authToken
)
),
(
setLoaded(
'login',
)
),
)
)),
catchError((
error,
) => (
of(
fetchUserFailed(
error,
)
)
)),
),
)
)),
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment