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

Commit

Permalink
#126 getValue
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Sep 8, 2016
1 parent 98fa3c3 commit c5f657d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion docs/DATABASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ Let's say we have the structure as defined at `setValue`, then use this query to
"/companies",
{
// set this to true if you want to check if the value exists or just want the event to fire once
// default false, so it listens continuously
// default false, so it listens continuously.
// Only when true this function will return the date in the promise as well!
singleEvent: true,
// order by company.country
orderBy: {
Expand Down
8 changes: 7 additions & 1 deletion firebase.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -982,18 +982,24 @@ firebase.query = function (updateCallback, path, options) {
var listener = new com.google.firebase.database.ValueEventListener({
onDataChange: function (snapshot) {
updateCallback(firebase.getCallbackData('ValueChanged', snapshot));
// resolve promise with data in case of single event, see https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/126
resolve(firebase.getCallbackData('ValueChanged', snapshot));
},
onCancelled: function (databaseError) {
updateCallback({
error: databaseError.getMessage()
});
// see comment at 'onDataChange'
resolve({
error: databaseError.getMessage()
});
}
});
query.addListenerForSingleValueEvent(listener);
} else {
firebase._addObservers(query, updateCallback);
resolve();
}
resolve();
} catch (ex) {
console.log("Error in firebase.query: " + ex);
reject(ex);
Expand Down
4 changes: 3 additions & 1 deletion firebase.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -1024,11 +1024,13 @@ firebase.query = function (updateCallback, path, options) {
if (options.singleEvent) {
query.observeSingleEventOfTypeWithBlock(FIRDataEventType.FIRDataEventTypeValue, function (snapshot) {
updateCallback(firebase.getCallbackData('ValueChanged', snapshot));
// resolve promise with data in case of single event, see https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/126
resolve(firebase.getCallbackData('ValueChanged', snapshot));
});
} else {
firebase._addObservers(query, updateCallback);
}
resolve();
}
} catch (ex) {
console.log("Error in firebase.query: " + ex);
reject(ex);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-plugin-firebase",
"version": "3.6.1",
"version": "3.6.2-dev",
"description" : "Fire. Base. Firebase!",
"main" : "firebase.js",
"nativescript": {
Expand Down

0 comments on commit c5f657d

Please sign in to comment.