Last active
September 20, 2018 18:59
-
-
Save ajcrites/abef00d7eab83f735afcac13acdf7fd4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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