Skip to content

Instantly share code, notes, and snippets.

@tomwis
Created October 22, 2017 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomwis/6d9690c5152f4849eaebcc94ff6f6bb8 to your computer and use it in GitHub Desktop.
Save tomwis/6d9690c5152f4849eaebcc94ff6f6bb8 to your computer and use it in GitHub Desktop.
var canSearch = this.WhenAnyValue(vm => vm.SearchTerm)
.Where(x => !string.IsNullOrWhiteSpace(x) && x.Length >= 3)
.Publish()
.RefCount();
SearchCmd = ReactiveCommand.CreateFromObservable<string, IEnumerable<string>>(term => Observable.StartAsync(_ => _movieService.GetMovies(term)).TakeUntil(canSearch));
SearchCmd.Subscribe(results =>
{
Results.Clear();
Results.AddRange(results);
});
canSearch
.Throttle(TimeSpan.FromMilliseconds(500))
.InvokeCommand(SearchCmd);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment