Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Last active September 20, 2018 18:59
Show Gist options
  • Save ajcrites/abef00d7eab83f735afcac13acdf7fd4 to your computer and use it in GitHub Desktop.
Save ajcrites/abef00d7eab83f735afcac13acdf7fd4 to your computer and use it in GitHub Desktop.
/**
* Handling of time, network requests, and asynchronous
* logic more generally cannot be done by reducers.
*/
export const profileEpic = action => action.pipe(
ofType(SEARCH_PROFILE),
// Only allow one search every 300ms
debounceTime(300),
// Cancel duplicate searches using `switchMap`
switchMap(term => getProfileByTerm(term).pipe(
map(({ body }) => new SearchProfileSuccessAction(body)),
// Async error handling. For epics this should probably be
// done to handle service errors. If errors propagate to
// the epic, the epic will be canceled and stop listening
catchError(() => of(new SearchProfileFailureAction()),
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment