EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 442 forks source link

Cannot get Latest Data with query After Push If I use limit firebase.QueryLimitType.FIRST #1522

Open sanghyun5958 opened 4 years ago

sanghyun5958 commented 4 years ago

Thank you for reading my question. I'm using Realtime Database with Angular Nativescript.

I couldn't get refreshed data if I write it below on my query after pushing the data. limit: { type: firebase.QueryLimitType.FIRST, value: 18 }

Please give me some tips.. thank you

 push(carModel: Actor): Promise<any> {
        carModel.createTs = new Date().getTime() * -1;
        const updateModel = ActorService.cloneUpdateModel(carModel);
        return firebase.push("/actors", updateModel);
    }
ngOnInit(): void {
        this._changeDetectionRef.detectChanges();

        if (!this._dataSubscription) {
            setTimeout(() => {
                this._isLoading = true;
                this._dataSubscription = this._carService.loadQuery().subscribe((actors: Array<Actor>) => {
                    if (actors.length) {

                        this._actors = new ObservableArray(actors);
                        this.lastTs = this._actors["_array"][this._actors.length - 1].createTs;

                        this._isLoading = false;
                    }
                });
            }, 500);
        }
    }
loadQuery( ): Observable<any> {
        return new Observable((observer: any) => {
            const path = "actors";

            const onQueryEvent = (snapshot: any) => {
                this._ngZone.run(() => {
                    const results = this.handleSnapshot(snapshot.value);
                    observer.next(results);
                });
            };

            firebase.query(onQueryEvent, `/${path}`, {
                singleEvent: true,
                orderBy: {
                    type: firebase.QueryOrderByType.CHILD,
                    value: "createTs" // actordatory when type is 'child'
                },
                limit: {
                    type: firebase.QueryLimitType.FIRST,
                    value: 18
                }
            });
        }).pipe(catchError(this.handleErrors));
    }
EddyVerbruggen commented 4 years ago

Do you know if this is caused by the plugin, or is it "regular" Firebase behavior? If you suspect the latter then please ask this on SO as well and tag your Q with "firebase".