Sawtaytoes
12/12/2019 - 5:14 AM

The Old Way

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