I am trying to create an rxjs observable on the Query#onSnapshot method. This is my code:
let observable = Rx.Observable.create(db.collection('conversations')
.where('members.' + auth.currentUser.uid, '==', true).onSnapshot)
observable.subscribe({next(value){console.log('value', value)}})
The error I receive is this:
TypeError: this.onSnapshotInternal is not a function
It seems that the onSnapshot method is set to be duck-typed as an observable. Firestore doesn't have enough documentation yet for me to figure this out.
When you pass onSnapshot
to Rx.Observable.create
, you are passing it unbound to a query. That is, you are just passing the Query.prototype.onSnapshot
function.
You could either use bind
, like this:
const query = db
.collection('conversations')
.where('members.' + auth.currentUser.uid, '==', true);
let observable = Rx.Observable.create(query.onSnapshot.bind(query));
observable.subscribe({
next(value) { console.log('value', value); }
});
Or could use an arrow function, like this:
let observable = Rx.Observable.create(observer => db
.collection('conversations')
.where('members.' + auth.currentUser.uid, '==', true)
.onSnapshot(observer)
);
observable.subscribe({
next(value) { console.log('value', value); }
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With