Last active
December 21, 2016 07:40
-
-
Save msenel/8b01bfca1490a490e2cc06a3bcb865ee to your computer and use it in GitHub Desktop.
Firebase SDK javascript read examples
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
var channel = {} | |
// https://firebase.google.com/docs/reference/js/firebase.database.Reference | |
// A Reference represents a specific location in your Database and can be used for reading or writing data to that Database location. | |
// Get a reference to the database service | |
var database = firebase.database(); | |
//Get a reference to the channels node | |
var channelsRef = database.ref('/channels'); | |
//Handle a new value: | |
channelsRef.on('value', function(dataSnapshot) { | |
console.log('Something changed on channels node'); | |
}); | |
//Handle a new child: | |
channelsRef.on('child_added', function(childSnapshot, prevChildKey) { | |
console.log('New child added on channels node'); | |
}); | |
//Handle child removal: | |
channelsRef.on('child_removed', function(oldChildSnapshot) { | |
console.log('Child removed on channels node'); | |
}); | |
//Handle child data changes: | |
channelsRef.on('child_changed', function(childSnapshot, prevChildKey) { | |
console.log('Child data changed on channels node'); | |
}); | |
//Handle child ordering changes: | |
channelsRef.on('child_moved', function(childSnapshot, prevChildKey) { | |
console.log('Child node ordering changed on channels node'); | |
}); | |
//Value events synchronize the entire value | |
channelsRef.on('value', logChannels); | |
function logChannels (snapshot) { | |
console.log('Data changed on channels node', snapshot.val()); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment