Firebase Stub: query parameters not kept between ref calls

This commit is contained in:
gianantoniopini
2021-01-14 09:38:46 +01:00
parent b6a0527fbe
commit 36036cc411
3 changed files with 42 additions and 4 deletions

View File

@ -78,6 +78,7 @@ class Database {
const newRef = new Reference(referencePath, () => this._data);
const existingRef = this._references[newRef.path];
if (existingRef) {
existingRef.initializeQueryParameters();
return existingRef;
}

View File

@ -29,8 +29,7 @@ class Reference {
this._getDatabaseData = getDatabaseData;
this._orderByChildPath = '';
this._equalToValue = '';
this.initializeQueryParameters();
}
get path() {
@ -41,6 +40,14 @@ class Reference {
return this._uuid;
}
get orderByChildPath() {
return this._orderByChildPath;
}
get equalToValue() {
return this._equalToValue;
}
getData() {
const databaseData = this._getDatabaseData();
@ -59,10 +66,10 @@ class Reference {
) {
data = this.path in databaseData ? databaseData[this.path] : null;
if (data && this._orderByChildPath && this._equalToValue) {
if (data && this.orderByChildPath && this.equalToValue) {
return Object.fromEntries(
Object.entries(data).filter(
([, value]) => value[this._orderByChildPath] === this._equalToValue,
([, value]) => value[this.orderByChildPath] === this.equalToValue,
),
);
}
@ -92,6 +99,11 @@ class Reference {
return null;
}
initializeQueryParameters() {
this._orderByChildPath = '';
this._equalToValue = '';
}
off() {
return this !== null;
}