Skip to content

Instantly share code, notes, and snippets.

@vinhlee95
Created September 24, 2019 09:02
Show Gist options
  • Save vinhlee95/287d5d6c4f51b8b35d869ef90e9242fe to your computer and use it in GitHub Desktop.
Save vinhlee95/287d5d6c4f51b8b35d869ef90e9242fe to your computer and use it in GitHub Desktop.
Describe how RxJS handles a complicated data stream
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