Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 8dbf622

Browse files
Incorrect ordering while using singleEvent as true #405
1 parent 80d4291 commit 8dbf622

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

demo/app/main-view-model.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,10 +1556,11 @@ export class HelloWorldModel extends Observable {
15561556
limit: {
15571557
type: firebase.QueryLimitType.LAST,
15581558
value: 2
1559-
}
1559+
},
1560+
singleEvent: true
15601561
}
15611562
).then(
1562-
result => console.log("firebase.doQueryBulgarianCompanies done; added a listener"),
1563+
result => console.log("firebase.doQueryBulgarianCompanies done; added a listener, result: " + JSON.stringify(result)),
15631564
errorMessage => {
15641565
alert({
15651566
title: "Query error",
@@ -1595,7 +1596,8 @@ export class HelloWorldModel extends Observable {
15951596
{
15961597
singleEvent: true,
15971598
orderBy: {
1598-
type: firebase.QueryOrderByType.KEY
1599+
type: firebase.QueryOrderByType.CHILD,
1600+
value: "first"
15991601
}
16001602
}
16011603
).then(

src/firebase.android.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,7 @@ firebase.query = (updateCallback, path, options) => {
16811681
if (options.singleEvent) {
16821682
const listener = new com.google.firebase.database.ValueEventListener({
16831683
onDataChange: snapshot => {
1684-
const data = firebase.getCallbackData('ValueChanged', snapshot);
1684+
const data = firebase.getCallbackData("ValueChanged", snapshot);
16851685
if (updateCallback) updateCallback(data);
16861686
// resolve promise with data in case of single event, see https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/126
16871687
resolve(data);

src/firebase.ios.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ firebase.query = (updateCallback, path, options) => {
13591359
return new Promise((resolve, reject) => {
13601360
try {
13611361
const where = path === undefined ? FIRDatabase.database().reference() : FIRDatabase.database().reference().childByAppendingPath(path);
1362-
let query;
1362+
let query: FIRDatabaseQuery;
13631363

13641364
// orderBy
13651365
if (options.orderBy.type === firebase.QueryOrderByType.KEY) {
@@ -1437,9 +1437,19 @@ firebase.query = (updateCallback, path, options) => {
14371437

14381438
if (options.singleEvent) {
14391439
query.observeSingleEventOfTypeWithBlock(FIRDataEventType.Value, snapshot => {
1440-
if (updateCallback) updateCallback(firebase.getCallbackData('ValueChanged', snapshot));
1440+
const result = {
1441+
type: "ValueChanged",
1442+
key: snapshot.key,
1443+
value: {}
1444+
};
1445+
for (let i = 0; i < snapshot.children.allObjects.count; i++) {
1446+
const snap: FIRDataSnapshot = snapshot.children.allObjects.objectAtIndex(i);
1447+
result.value[snap.key] = firebaseUtils.toJsObject(snap.value);
1448+
}
1449+
1450+
if (updateCallback) updateCallback(result);
14411451
// resolve promise with data in case of single event, see https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/126
1442-
resolve(firebase.getCallbackData('ValueChanged', snapshot));
1452+
resolve(result);
14431453
});
14441454
} else {
14451455
resolve({

0 commit comments

Comments
 (0)