Created
September 24, 2019 09:02
-
-
Save vinhlee95/287d5d6c4f51b8b35d869ef90e9242fe to your computer and use it in GitHub Desktop.
Describe how RxJS handles a complicated data stream
This file contains 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
keyPressSources.pipe( | |
// Input handlers to take input value for searching | |
switchMap(value => { | |
return from(fetchCakesByName(value)).pipe( | |
// Only make an API request for searching after 0.5s since user stopped pressing a key | |
debounce(0.5), | |
// Retry 3 times if an API request fails | |
retry(3), | |
// Cancel the search when press Esc or clear input | |
takeUntil(value => value === 'Esc' || value === ''), | |
// Handling errors by showing an error alerts | |
catchError(error => alert('Error in getting cakes')) | |
) | |
}), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment