Last active
August 23, 2019 14:37
-
-
Save rullyalves/e30cbaafb7307ab7f83eb938267d0a69 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
| 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