Nativescript-plugin-firebase: Creating Observables from Firestore Documents/Collections

Created on 5 Jan 2018  路  4Comments  路  Source: EddyVerbruggen/nativescript-plugin-firebase

I'm trying to determine the best route for creating observables from the recently added firestore features. It seems as if it would be possible, but maybe firestore isn't intended to be used with observables?

public getCurrentUserAssignments(): Observable<any> {
        return new Observable((observer) => {
            const query = this.assignmentsColRef
                .where("uid", "==", BackendService.currentUID);

            let _currentUserAssignments = query.get().then(querySnapshot => {
                this.ngZone.run(() => {
                    observer.next(querySnapshot.docSnapshots);
                });
            });
        });
    }

This is my current implementation.. it retrieves the user associated assignments once, but doesn't update after adding an addition user assignment to the collection. Is this possible with firestore?

enhancement

Most helpful comment

With 5.1.2 you can use the new collection.onSnapshot feature. There's a link to an Observables example in the readme as well.

Please give me some feedback on what you think of it as I don't use Observables much myself, but I'd love to broaden its support in this plugin.

All 4 comments

The WebApi shows it possible to call .onSnapshot(callback) on a collection (https://firebase.google.com/docs/firestore/query-data/listen), as far as I can tell this isn't possible yet with this plugin?

I'm hoping to be able to make this plugin compatible with https://github.com/angular/angularfire2 which uses observables.

I've added onSnapshot to a document, but not to a collection. Shouldn't be too hard though.

With 5.1.2 you can use the new collection.onSnapshot feature. There's a link to an Observables example in the readme as well.

Please give me some feedback on what you think of it as I don't use Observables much myself, but I'd love to broaden its support in this plugin.

You do awesome work Eddy!!! Really appreciate your efforts!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

romandragan picture romandragan  路  3Comments

vchimev picture vchimev  路  3Comments

SBD580 picture SBD580  路  3Comments

bunower picture bunower  路  3Comments

Aceman18 picture Aceman18  路  3Comments