Skip to content

Instantly share code, notes, and snippets.

@AntonGorelov
Created February 16, 2021 13:30
Show Gist options
  • Save AntonGorelov/db3d4e402991dbe01091472b6f609ebd to your computer and use it in GitHub Desktop.
Save AntonGorelov/db3d4e402991dbe01091472b6f609ebd 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(
// map(([allPeople, peopleIds]: [TargetModel[], Set<string>]) => {
// console.log([allPeople, peopleIds]);
// return allPeople.filter((person: TargetModel) => {
// return peopleIds.has(person.id);
// });
// }),
// tap(() => console.log()),
// takeUntil(this._destroyed$),
// )
// .subscribe((selectedPeople: TargetModel[]) => {
// this._targetStateService.setSelectedPeople(selectedPeople);
// });
let allPeoples = [];
this._targetStateService.getAllPeople()
.pipe(
switchMap((allPeople: TargetModel[]) => {
allPeoples = allPeople;
return this._getParams$();
}),
map((peopleIds) => {
return allPeoples.filter((person: TargetModel) => {
return peopleIds.has(person.id);
});
}),
takeUntil(this._destroyed$),
)
.subscribe((selectedPeople: TargetModel[]) => {
this._targetStateService.setSelectedPeople(selectedPeople);
});
}
private _getParams$() {
return this._activatedRoute.queryParamMap
.pipe(
take(1),
map((p: ParamMap) => new Set(p.getAll('people'))),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment