Skip to content

Instantly share code, notes, and snippets.

@anantn
Last active March 4, 2016 00:04
Show Gist options
  • Save anantn/4325052 to your computer and use it in GitHub Desktop.
Save anantn/4325052 to your computer and use it in GitHub Desktop.

Revisions

  1. anantn revised this gist Feb 13, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion firebase_first_item.js
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ function makeList(ref) {
    }

    function getFirstFromList(ref, cb) {
    ref.startAt().limit(1).on("child_added", function(snapshot) {
    ref.startAt().limit(1).once("child_added", function(snapshot) {
    cb(snapshot.val());
    });
    }
  2. anantn created this gist Dec 18, 2012.
    21 changes: 21 additions & 0 deletions firebase_first_item.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    function makeList(ref) {
    var fruits = ["banana", "apple", "grape", "orange"];
    for (var i = 0; i < fruits.length; i++) {
    ref.push(fruits[i]);
    }
    }

    function getFirstFromList(ref, cb) {
    ref.startAt().limit(1).on("child_added", function(snapshot) {
    cb(snapshot.val());
    });
    }

    // Running this should popup an alert with "banana".
    function go() {
    var testRef = new Firebase("https://example.firebaseIO-demo.com/");
    makeList(testRef);
    getFirstFromList(testRef, function(val) {
    alert(val);
    });
    }