There's this situation where I have an observable that emits an ID. My goal is to fetch an element associated with that ID and save it into a new observable. The catch is, the new observable must be subscribed to in order to emit its value. Here's how the code currently looks:
selectedElement$ =
latestElementId$.pipe(
takeUntil(this.destroy$),
mergeMap(id => store$.select(selectElement(id))),
tap(element => elementForm?.patchValue(element))
);
selectedElement$
.pipe(takeUntil(this.destroy$))
.subscribe();
I can't shake off this feeling that there might be a more efficient way to handle this scenario, perhaps utilizing another operator that could eliminate the need for the last three lines. However, when I attempted to remove them, the code stopped functioning properly.