Skip to content

Instantly share code, notes, and snippets.

@AntonGorelov
Created February 16, 2021 12:46
Show Gist options
  • Save AntonGorelov/458862dc8d903a8eff0839c5a72a5422 to your computer and use it in GitHub Desktop.
Save AntonGorelov/458862dc8d903a8eff0839c5a72a5422 to your computer and use it in GitHub Desktop.
private _initSelectedPeople(): void {
// this._targetStateService.getAllPeople()
// .pipe(takeUntil(this._destroyed$))
// .subscribe((allPeople: TargetModel[]) => {
//
// console.log(allPeople, 'allpeople');
//
// let ids = [];
// this._activatedRoute.queryParamMap
// .pipe(take(1))
// .subscribe((params: ParamMap) => {
// ids = params.getAll('people');
// });
//
// const selectedPeople = allPeople.filter((person: TargetModel) => {
// return ids
// .some((personId: string) => {
// return person.id === personId;
// });
// });
//
// this._targetStateService.setSelectedPeople(selectedPeople);
// });
combineLatest([this._targetStateService.getAllPeople(), this._getParams$()])
.pipe(takeUntil(this._destroyed$))
.subscribe((value: [TargetModel[], ParamMap]) => {
const allPeople = value[0];
const peopleIds = value[1].getAll('people');
console.log(allPeople, peopleIds);
const selectedPeople = allPeople.filter((person: TargetModel) => {
return peopleIds
.some((personId: string) => {
return person.id === personId;
});
});
this._targetStateService.setSelectedPeople(selectedPeople);
});
}
private _getParams$(): Observable<ParamMap> {
return this._activatedRoute.queryParamMap
.pipe(
take(1)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment