Convert on subscriptions to once for FirebaseResource

This commit is contained in:
Garrett Mills 2021-04-10 16:20:41 -05:00
parent 78287fcc2a
commit d79d0f38f4
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

View File

@ -33,7 +33,7 @@ export class FirebaseResource<T extends FirebaseResourceItem> extends Iterable<T
async getNextID(): Promise<number> { async getNextID(): Promise<number> {
return new Promise<number>((res, rej) => { return new Promise<number>((res, rej) => {
this.ref().orderByChild('seqID') this.ref().orderByChild('seqID')
.on('value', snapshot => { .once('value', snapshot => {
res((this.resolveObject(snapshot.val()).reverse()?.[0]?.seqID ?? -1) + 1) res((this.resolveObject(snapshot.val()).reverse()?.[0]?.seqID ?? -1) + 1)
}, rej) }, rej)
}) })
@ -44,7 +44,7 @@ export class FirebaseResource<T extends FirebaseResourceItem> extends Iterable<T
return new Promise<T | undefined>((res, rej) => { return new Promise<T | undefined>((res, rej) => {
this.ref().orderByChild('seqID') this.ref().orderByChild('seqID')
.startAt(i).endAt(i) .startAt(i).endAt(i)
.on('value', snapshot => res(this.resolveObject(snapshot.val())[0]), rej) .once('value', snapshot => res(this.resolveObject(snapshot.val())[0]), rej)
}) })
} }
@ -53,7 +53,7 @@ export class FirebaseResource<T extends FirebaseResourceItem> extends Iterable<T
return new Promise<Collection<T>>((res, rej) => { return new Promise<Collection<T>>((res, rej) => {
this.ref().orderByChild('seqID') this.ref().orderByChild('seqID')
.startAt(start).endAt(end) .startAt(start).endAt(end)
.on('value', snapshot => { .once('value', snapshot => {
res(new Collection<T>(this.resolveObject(snapshot.val()))) res(new Collection<T>(this.resolveObject(snapshot.val())))
}, rej) }, rej)
}) })
@ -63,7 +63,7 @@ export class FirebaseResource<T extends FirebaseResourceItem> extends Iterable<T
async count(): Promise<number> { async count(): Promise<number> {
return new Promise<number>((res, rej) => { return new Promise<number>((res, rej) => {
this.ref().orderByChild('seqID') this.ref().orderByChild('seqID')
.on('value', snapshot => { .once('value', snapshot => {
res(this.resolveObject(snapshot.val()).length) res(this.resolveObject(snapshot.val()).length)
}, rej) }, rej)
}) })
@ -105,7 +105,8 @@ export class FirebaseResource<T extends FirebaseResourceItem> extends Iterable<T
.orderByChild('seqID') .orderByChild('seqID')
.startAt(item.seqID) .startAt(item.seqID)
.limitToFirst(1) .limitToFirst(1)
.on('value', snapshot => { .once('value', snapshot => {
item.firebaseID = snapshot.key || ''
res() res()
}) })
}) })