Is there a way to simplify the process of automatically unsubscribing from Observables when a component is destroyed using takeUntil
? It becomes tedious having to repeat the same code in multiple components.
I am looking for a solution that allows me to access emitted values in the Typescript component without using the async
pipe.
Would appreciate any suggestions on streamlining the current implementation below:
export class Component implements OnDestroy {
_dstr = new Subject();
data$: Observable<any> = this.store.select(Selector.getData);
constructor(
private store: Store<State>,
) {
this.store.pipe(
select(Selector.getOtherData),
takeUntil(this._dstr),
).subscribe(data => {
console.log('here is my data!', data)
});
}
public ngOnDestroy(): void {
this._dstr.next();
this._dstr.complete();
}
}