Last active
January 12, 2017 11:41
-
-
Save frederikprijck/f7a09f000f371260c372c5bedeedf0fb to your computer and use it in GitHub Desktop.
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
class SurveyListController { | |
surveys: ISurvey[]; | |
search$: Subject<string> = new Subject<string>(); | |
// subject used to clean up the observable subscriptions. | |
private onDestroy$: Subject<any> = new Subject<any>(); | |
/** | |
* hook in-to the Angular onInit event | |
*/ | |
$onInit() { | |
search$ | |
.map(searchValue => { searchValue }) | |
.startWith({ searchValue: ''}) | |
.switchMap(params => this.search(params.searchValue)) | |
// temp workaround for: https://github.com/ReactiveX/rxjs/issues/2160 | |
.takeUntil(this.onDestroy$) | |
.subscribe(result => { | |
this.surveys = result.items; | |
}); | |
} | |
/** | |
* hook in-to the Angular onDestroy event | |
*/ | |
$onDestroy() { | |
// completing onDestroy cleans up the subscription's using onDestroy$ as takeUntil | |
this.onDestroy$.complete(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment