Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __weak LTSearchResultsController *weakSelf = self;
- RACSignal *throttledSearchQuerySignal = [[[RACObserve(self.viewModel, query) distinctUntilChanged] doNext:^(id x) {
- __strong LTSearchResultsController *strongSelf = weakSelf;
- [strongSelf setSearchResults:nil];
- [strongSelf.searchResultsTable reloadData];
- [strongSelf.nothingFoundView setHidden:YES];
- }] throttle:1.0f];
- [[[[throttledSearchQuerySignal
- filter:^BOOL(NSString *text) {
- return [text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]].length > 2;
- }]
- map:^id(id value) {
- __strong LTSearchResultsController *strongSelf = weakSelf;
- [strongSelf.activityIndicator setHidden:NO];
- [strongSelf.activityIndicator startAnimating];
- return [strongSelf.viewModel searchSignalWithQuery:(NSString *)value];
- }] switchToLatest]
- subscribeNext:^(NSArray *searchResults) {
- __strong LTSearchResultsController *strongSelf = weakSelf;
- [strongSelf.activityIndicator stopAnimating];
- [strongSelf.activityIndicator setHidden:YES];
- if (searchResults.count > 0)
- {
- strongSelf.searchResults = searchResults;
- [strongSelf.searchResultsTable reloadData];
- }
- else
- {
- [strongSelf.nothingFoundView setHidden:NO];
- [strongSelf.nothingFoundQueryLabel setText:strongSelf.viewModel.query];
- }
- } error:^(NSError *error) {
- __strong LTSearchResultsController *strongSelf = weakSelf;
- [strongSelf.activityIndicator stopAnimating];
- [strongSelf.activityIndicator setHidden:NO];
- }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement