Created
February 16, 2021 13:30
-
-
Save AntonGorelov/db3d4e402991dbe01091472b6f609ebd 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
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