Skip to content

Instantly share code, notes, and snippets.

@dreadjr
Created July 5, 2017 22:06
Show Gist options
  • Save dreadjr/784b8e9a5621d1edc33f5a45eb21faa7 to your computer and use it in GitHub Desktop.
Save dreadjr/784b8e9a5621d1edc33f5a45eb21faa7 to your computer and use it in GitHub Desktop.
var saveUser = function(user, cb) {
var ref = new Firebase("https://<your-firebase>.firebaseio.com");
var usersRef = ref.child('users');
usersRef.child('count').once('value', function(snap) {
var priority = snap.val() ? snap.val() : 0;
usersRef.child(user.uid).setWithPriority(user, priority, function() {
// on complete, update user count
usersRef.child('count').transaction(function (current_value) { return (current_value || 0) + 1; });
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment