I have written a function that returns an observable that wraps the firestore onSnapshot
method.
function getObservable() {
return Observable.create(observer => {
firebase.firestore().collection('users').onSnapshot(
snapshot => observer.next(snapshot.docs),
);
});
})
}
I am able to use this function and get updated docs as follows
const observable = getObservable()
const subscription = observable.subscribe(users => console.log('users'));
If I now call the subscription.unsubscribe()
method, I will unsubscribe from the subscription. However, I will not subscribe from the onSnapshot
listener.
Is there any way such that when I unsubscribe from the observable, I will automatically unsubscribe from the onSnapshot
method.