Skip to content

Instantly share code, notes, and snippets.

@Sawtaytoes
Created October 16, 2019 07:34
Show Gist options
  • Save Sawtaytoes/69334a25c9607fd97b3519d127cd8dc7 to your computer and use it in GitHub Desktop.
Save Sawtaytoes/69334a25c9607fd97b3519d127cd8dc7 to your computer and use it in GitHub Desktop.
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))),
),
)
)),
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment