Created
January 30, 2014 17:17
-
-
Save andrunix/8713747 to your computer and use it in GitHub Desktop.
Firebase findAll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
findAll: function() { | |
var sports = {}; | |
var sportsRef = new Firebase(FBURL + '/sports'); | |
sportsRef.once('value', function(snapshot) { | |
sports = snapshot.val(); | |
}); | |
return sports; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I should have noted that the callback based approach is often better handled without anonymous functions:
Also - my first example using promises was not covering the error side of things. You can
deferred.reject
instead of resolve if you have an issue (or if it times out, for ex). Highly recommend covering both the success (resolve) and failure (reject) side of a promise so that you don't end up in a limbo-edge-case state.