Sawtaytoes
10/16/2019 - 7:33 AM

fetchUserEpic - Vertical

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