I have a situation where I have two observable pipes and I need to run them one after the other in order to compare their emitted values. The code snippet I attempted is provided below. Ideally, when the first observable emits a value, it should then fetch the second observable's value and compare it with the first one. I believe there might be room for improvement in this code and would appreciate any expert help in refactoring it more efficiently.
this.selectedUnitDetailModel$.pipe(shareReplayUntil(this.destroySub)).subscribe(
(res: UnitDetail) =>{
if(res.unitTwo){
this.appStore.select(selectUnit).
pipe(shareReplayUntil(this.destroySub)).subscribe(
(unitId: string) => {
if(unitId === res.unitTwo){
this.sameUnit = true;
}else{
this.sameUnit = false;
}
});
}
}
);