1
Hello
I need help with a problem that is happening to me. I have a code to listen to changes in the firebase database. So, I have to subscribe to an observable that brings me the BD data. However, when I delete this object being monitored I need to unsubscribe, but before I delete the object. Otherwise an error of the type is triggered firebase error Missing or insufficient Permissions. I thought about the possibility of capturing only the error of this type (Firebase error insuficient permission). This would already be a solution for me, however, I do not know how to make the unsubscribe inside the catchError rxjs (I do not even know if it is possible). See that the two takeUntil has a Notifier that are different. The first use for when the user logs out and the second for when the user leaves the page. I can’t use them because there are many objects that use this same subscribe and if I apply this.appState.onDestroy.next() or this.onDestroy.next() when deleting an object i will disable the valueChanges of the other objects. How to proceed?
Code below:
import {Subject} from 'rxjs';
import {switchMap, takeUntil} from 'rxjs/operators';
import {AppStateService} from '../service/app-state.service';
export abstract class processor implements OnDestroy {
ShopSubject: Subject<string> = new Subject<string>();
onDestroy: Subject<void> = new Subject<void>();
data: any;
protected constructor(
protected appState: AppStateService
) {
this.ShopSubject
.pipe(switchMap(id => {
return this.shopService.docValueChanges(`shop/${id}`);
}))
.pipe(takeUntil(this.appState.onDestroy))
.pipe(takeUntil(this.onDestroy))
.subscribe(data => {
this.data= data;
});
}
ngOnDestroy(): void {
this.onDestroy.next();
}
}