Skip to content

Instantly share code, notes, and snippets.

@rullyalves
Last active August 23, 2019 14:37
Show Gist options
  • Select an option

  • Save rullyalves/e30cbaafb7307ab7f83eb938267d0a69 to your computer and use it in GitHub Desktop.

Select an option

Save rullyalves/e30cbaafb7307ab7f83eb938267d0a69 to your computer and use it in GitHub Desktop.
class SearchBloc {
Observable<SearchResult> result;
final _query = PublishSubject<String>();
Sink<String> get addQuery => _query.sink;
SearchBloc() {
final _api = GithubApi();
result = _query
// Accepting only differents querys
.distinct()
// Waiting to search when user stop changing query
.debounceTime(Duration(milliseconds: 350))
// Reset result if query changes and calling api
.switchMap(
(i) => Observable(_api.search(i).asStream())
// starts with null in new request
.startWith(null)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment