Created
December 4, 2018 07:01
-
-
Save LayZeeDK/4e62905bfe8600ef5e5becabb957df40 to your computer and use it in GitHub Desktop.
Hero search: Broken, partial implementation in mixed component model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { Observable } from 'rxjs'; | |
import { debounceTime, distinctUntilChanged } from 'rxjs/operators'; | |
import { Hero } from '../hero'; | |
@Component({ | |
selector: 'app-hero-search', | |
templateUrl: './hero-search.component.html', | |
styleUrls: [ './hero-search.component.css' ] | |
}) | |
export class HeroSearchComponent implements OnInit { | |
heroes$: Observable<Hero[]>; | |
// Push a search term into the observable stream. | |
search(term: string): void {} | |
ngOnInit(): void { | |
this.heroes$ = this.searchTerms.pipe( | |
// wait 300ms after each keystroke before considering the term | |
debounceTime(300), | |
// ignore new term if same as previous term | |
distinctUntilChanged(), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment