Last active
September 30, 2021 04:39
-
-
Save ardydedase/f01ffabf8b3dae6b73277128ec5eecbd to your computer and use it in GitHub Desktop.
takeUntiNgOnInit.ts
This file contains 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
ngOnInit() { | |
this.results$ = this.searchSubject$.pipe( | |
debounceTime(200), | |
distinctUntilChanged(), | |
switchMap((searchString) => { | |
if ((searchString as any).replace(/\s/g, '')) { | |
switch (this.searchType) { | |
case SearchType.REPOS: | |
return this.githubService.searchRepos(searchString); | |
case SearchType.USERS: | |
return this.githubService.searchUsers(searchString); | |
default: | |
break; | |
} | |
} | |
}) | |
); | |
this.searchReposFormControl.valueChanges | |
.pipe(takeUntil(this.destroyed$)) | |
.subscribe((searchString) => { | |
if (searchString) { | |
this.searchType = SearchType.REPOS; | |
this.searchSubject$.next(searchString); | |
} | |
}); | |
this.searchUsersFormControl.valueChanges | |
.pipe(takeUntil(this.destroyed$)) | |
.subscribe((searchString) => { | |
if (searchString) { | |
this.searchType = SearchType.USERS; | |
this.searchSubject$.next(searchString); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment