Cast Query Observable to FirebaseListObservable
If you create a query on a FirebaseListObservable the methods such as .push(), .remove(), and .update() are never attached.
// a non-queried list
cost regularList = af.database.list(`/items`);
// a queried list
const queriedList = af.database.list(`/items`, {
query: { limitToLast: 25 }
});
// works
regularList.push({ name 'item' });
// won't work
queriedList.push({ name: 'item' });
I believe this is because a query creates a regular Observable, and then a mergeMap is used to create a FirebaseListObservable.
Any ideas on how to solve this issue, @blesh?
@davideast you'd need to create a custom Observable that overrides lift to return it's own type.
Something like:
class FirebaseListObservable<T> extends Observable<T> {
/* stuff here */
lift<R>(operator: Operator<T, R>): FirebaseListObservable<R> {
const observable = new FirebaseListObservable<R>();
observable.source = this;
observable.operator = operator;
return observable;
}
}
This is because lift is used in every operator to create the operation/effect. Take map for example
Another thing to do is question whether or not is that you want a custom Observable type, or you want a class that has an observable as a property on it. It really depends on the ergonomics you're aiming for.
Is there a work around for this issue?
Thanks for the update @davideast.
Hey David, first congratulations for building this awesome library!! I just started to use it and is great! I see that this issue has been closed. This means it was fixed? If so, how come i still have the same problem when using push? I'm using "angularfire2": "^2.0.0-beta.3" and "firebase": "^3.2.1"
Or this problem is because i'm using angular rc4 and not rc3 ?
If this is not fixed yet and will not be fixed quickly - it's a good ideea to use 2 different observables linked to the same database source? I know it's repetitive but seems to work. For example:
this.getMessages = this.fb.database.list('messages', { // query here}); // used only for rendering + dynamic queering
this.saveMessages = this.fb.database.list('/messages') // no query,
this,saveMessages.push(data) // this works now - i can save the data.
Other than being repetitive is there a problem using this pattern until this issue is rely fixed? Thank's so much for your time:)
@AIon-Gbbe does this break | async for you?