Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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