Skip to content

Instantly share code, notes, and snippets.

@jlaine
Created May 7, 2018 12:53
Show Gist options
  • Save jlaine/c77fde880d938839b09eb62f179d7eab to your computer and use it in GitHub Desktop.
Save jlaine/c77fde880d938839b09eb62f179d7eab to your computer and use it in GitHub Desktop.
@Component({
selector: 'app-pony-list',
templateUrl: './pony-list.component.html',
styleUrls: ['./pony-list.component.css']
})
export class PonyListComponent {
filterForm: FormGroup;
page: Observable<Page<Pony>>
pageUrl = new Subject<string>();
constructor(
private ponyService: PonyService
) {
this.filterForm = new FormGroup({
is_available: new FormControl(),
search: new FormControl()
});
this.page = this.filterForm.valueChanges.pipe(
debounceTime(200),
startWith(this.filterForm.value),
merge(this.pageUrl),
switchMap(urlOrFilter => this.ponyService.list(urlOrFilter)),
share()
);
}
onPageChanged(url: string) {
this.pageUrl.next(url);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment