Angular: 4.3.6
Firebase: 4.5.0
AngularFire: 5.0.0-rc.1
Other (e.g. Ionic/Cordova, Node, browser, operating system):
https://stackblitz.com/edit/angularfire-db-api-fbad9p
Steps to set up and reproduce
Select filters which would reduce to empty set (e.g, large + blue).
Empty set would be returned from valueChanges()
valueChanges() is not updated
Same would be nice for snapshotChanges() as well.
It was released in 5.0.0-rc.2?
Because seems like empty sets still not being returned from valueChanges()
I have the following code
public userExists(email: string): Observable<boolean> {
return this.afDb.list('/clients', ref =>
ref.orderByChild('email').equalTo(email))
.valueChanges()
.map((users: User[]) => users.length > 0);
}
When my query should return an empty array, the map / observables is not fired.
hmmm, is this the realtime db? i've mostly been focused on the firestore side
If so, can you open a new issue?
@jamesdaniels yeah, it is. I've opened the issue #1220
thanks
Should snapshotChanges also work? When I hit conditions that produce zero results, the list is not cleared, but displays the old results. This is due to the .snapshotChanges() never being called.
I can fix it by having .snapshotChanges().startWith([]).map(snapshots => {, but then there's a double call everytime there's data.
I have code like this:
return this.firestore.collection<Invoice>('invoices/9/invoices', ref => {
const direction = sort.direction == 'asc' ? 'asc' : 'desc'
let q: firebase.firestore.Query = ref.orderBy(sort.active, direction)
if (state && state != InvoiceState.all) {
q = q.where('state', '==', state)
}
if (page.pageIndex > 0 && page.pageIndex - 1 in this.lastVisible) {
return q.startAfter(this.lastVisible[page.pageIndex - 1]).limit(limitSize)
} else {
return q.limit(limitSize)
}
}).snapshotChanges().startWith([]).map(snapshots => {
if (snapshots.length == limitSize) {
this.rowCountSubject.next(Number.MAX_SAFE_INTEGER)
snapshots.pop()
} else {
this.rowCountSubject.next(this.lastPageSize * page.pageIndex + snapshots.length)
}
if (snapshots.length > 0) {
this.lastVisible[page.pageIndex] = snapshots[snapshots.length-1].payload.doc
}
const invoices: Invoice[] = []
for (const snapshot of snapshots) {
const $key = snapshot.payload.doc.id
const data = { $key, ...snapshot.payload.doc.data() } as Invoice
invoices.push(data)
}
return invoices
}).map(invoices => {
const data = this.filterAndMap(invoices)
return data
})
@jamesdaniels dropping you a message cause this issue is already closed. See previous comment.
Most helpful comment
It was released in 5.0.0-rc.2?
Because seems like empty sets still not being returned from valueChanges()
I have the following code
When my query should return an empty array, the map / observables is not fired.