Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. __weak LTSearchResultsController *weakSelf = self;
  2.    
  3.     RACSignal *throttledSearchQuerySignal = [[[RACObserve(self.viewModel, query) distinctUntilChanged] doNext:^(id x) {
  4.         __strong LTSearchResultsController *strongSelf = weakSelf;
  5.         [strongSelf setSearchResults:nil];
  6.         [strongSelf.searchResultsTable reloadData];
  7.         [strongSelf.nothingFoundView setHidden:YES];
  8.     }] throttle:1.0f];
  9.    
  10.     [[[[throttledSearchQuerySignal
  11.          filter:^BOOL(NSString *text) {
  12.              return [text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]].length > 2;
  13.          }]
  14.        map:^id(id value) {
  15.            __strong LTSearchResultsController *strongSelf = weakSelf;
  16.            
  17.            [strongSelf.activityIndicator setHidden:NO];
  18.            [strongSelf.activityIndicator startAnimating];
  19.            return [strongSelf.viewModel searchSignalWithQuery:(NSString *)value];
  20.        }] switchToLatest]
  21.      subscribeNext:^(NSArray *searchResults) {
  22.  
  23.          __strong LTSearchResultsController *strongSelf = weakSelf;
  24.          
  25.          [strongSelf.activityIndicator stopAnimating];
  26.          [strongSelf.activityIndicator setHidden:YES];
  27.          
  28.          if (searchResults.count > 0)
  29.          {
  30.              strongSelf.searchResults = searchResults;
  31.              [strongSelf.searchResultsTable reloadData];
  32.          }
  33.          else
  34.          {
  35.              [strongSelf.nothingFoundView setHidden:NO];
  36.              [strongSelf.nothingFoundQueryLabel setText:strongSelf.viewModel.query];
  37.          }
  38.          
  39.      } error:^(NSError *error) {
  40.          __strong LTSearchResultsController *strongSelf = weakSelf;
  41.          [strongSelf.activityIndicator stopAnimating];
  42.          [strongSelf.activityIndicator setHidden:NO];
  43.      }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement