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,
)
)
)),
),
)
)),
)
)