Reputation: 2035
This is a pretty basic question, so I apologize in advance. But I have been struggling with this all night. I have a simple firebase database query... which I know works.. I use child_added so itll return a few times for each different node off of the spot I am querying.
I am then trying to compliment a callback after it is completely done calling. Right now it will return about 10 different values, so my goal is to then use a promise or some sort of callback to run code after the database reference is finished.
var getIsStarred = getFirebase().database().ref('feed/value').on('child_added').then(function(snapshot) {
console.log("JX10: ok")
});
Promise.(getIsStarred).then(function(results) {
console.log("JX10: end promise thing okay sick")
});
Thanks in advance for help!
Upvotes: 1
Views: 1446
Reputation: 600131
It sounds like you're trying to run an action after all children have been loaded. You'd do that with a once('value'
handler:
var getIsStarred = getFirebase().database().ref('feed/value').once('value').then(function(snapshot) {
console.log("the initial items have been loaded")
});
Upvotes: 2
Reputation: 33209
Firebase's on()
function docs are here: https://firebase.google.com/docs/reference/js/firebase.database.Reference#on
As you can see, it wants a callback, and also returns the callback so that it can be used as a parameter to an off()
call if desired. It doesn't look like a promise is returned anywhere.
Upvotes: 2