Created
July 5, 2017 22:06
-
-
Save dreadjr/784b8e9a5621d1edc33f5a45eb21faa7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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