const fetchUserEpic = action$ => (
action$.pipe(
ofType(FETCH_USER),
switchMap(({ username, password }) => (
merge(
of(setLoading('login')),
ajax.getJSON('https://api.example.com/login').pipe(
switchMap(({ authToken }) => of(
fetchUserSucceeded(authToken),
setLoaded('login'),
)),
catchError(error => of(fetchUserFailed(error))),
),
)
)),
)
)