Skip to content

Instantly share code, notes, and snippets.

@philippbosch
Created April 12, 2013 10:24
Show Gist options
  • Save philippbosch/5371087 to your computer and use it in GitHub Desktop.
Save philippbosch/5371087 to your computer and use it in GitHub Desktop.
Firebase example
<div id="currentNumber"> </div>
<button id="increment">+</button>
<button id="reset">Reset</button>
<script src="https://cdn.firebase.com/v0/firebase.js"></script>
<script>
var currentNumber = document.getElementById('currentNumber');
var incrementButton = document.getElementById('increment');
var resetButton = document.getElementById('reset');
var number = new Firebase("https://iuav-ixdlab-bottles.firebaseio.com/number");
number.on('value', function(snapshot) {
currentNumber.innerHTML = snapshot.val();
});
incrementButton.addEventListener('touchstart', function() {
number.transaction(function(current_value) {
return current_value + 1;
});
});
resetButton.addEventListener('touchstart', function() {
number.set(0);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment