Last active
August 4, 2017 05:00
-
-
Save cartant/b45396a0888d03dfa39d9c21f8bdf24e to your computer and use it in GitHub Desktop.
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
@Component({ | |
changeDetection: ChangeDetectionStrategy.OnPush, | |
selector: "user-search-container", | |
template: ` | |
<user-search | |
[observer]="observer" | |
[users]="users | async"> | |
</user-search> | |
` | |
}) | |
export class UserSearchContainer { | |
public observer: PartialObserver<string>; | |
public users: Observable<User[]>; | |
private _subject: Subject<string>; | |
constructor(service: UserSearchService) { | |
this._subject = new Subject<string>(); | |
this.observer = this._subject; | |
this.users = this._subject | |
.debounceTime(1000) | |
.distinctUntilChanged() | |
.switchMap(username => this.service.searchUsers(username)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment