www.firebase.
com @Firebase Jav
asc
rip
Firebase API Quick Reference t
Including Firebase
<script type=‘text/javascript’ src=‘https://cdn.firebase.com/js/client/1.0.11/
firebase.js'></script>
Firebase References
new Firebase(): var ref = new Firebase(‘url’); //Firebase from given URL
parent(): var parentRef = ref.parent(); //Parent of current reference
child(): var childRef = ref.child(‘child’); //Specific child of reference
root(): var rootRef = ref.root(); //Root of the firebase (base URL)
Reading Data Callback types
once(): ref.once(‘type’, dataCallback); //Read data once value
on(): ref.on(‘type’, dataCallback); //Callback on change child_added
child_changed
off(): ref.off([‘type’], [dataCallback]); //Remove
child_removed
off() can remove named callback, all callbacks of type, or all callbacks child_moved
Data Snapshots
callback: var dataCallback = function(dataSnapshot){/*handle here*/} //Stub
child(): var childSnapshot = dataSnapshot.child(‘child’); //Get child’s data
val(): var data = dataSnapshot.val(); //Get snapshot data as JSON
ref(): var refURL = dataSnapshot.ref(); //Return base URL of firebase instance
forEach(dataCallback), hasChild(‘child’), hasChildren(), name(), numChildren(),
getPriority(), exportVal() //Other available methods on snapshots
Writing Data
set(): ref.set({key:‘value’}) //Sets the entire reference (overwrites data)
setWithPriority(): ref.setWithPriority({key:‘value’}, priority) //Use to order
push(): ref.push([{key:‘value’}]) //Adds new GUID with optional key/value pair
update(): ref.update({key:‘value’}) //Changes value for key at given ref
remove(): ref.remove() //Removes data at given reference
Above functions have optional [onComplete] callbacks; success returns null, failure returns Error
Priority, Queries, and Limit
setPriority(): ref.setPriority(priority) //Floating point number or string
limit(): var refQuery = ref.limit(n) //Gets most recent n children by priority
startAt(): var startQuery = ref.startAt(priority) //Values with higher priority
endAt(): var endQuery = ref.endAt(priority) //Values with lower priority
limit(),startAt(), and endAt() can be combined and used to create queries when using priority
Full API available at: https://www.firebase.com/docs/javascript/firebase