Sawtaytoes
10/16/2019 - 7:34 AM

fetchUserEpic - Standard

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