Notes
function writeUserData(userId, name, email, imageUrl) {
firebase
.database()
.ref('users/' + userId)
.set({
username: name,
email: email,
profile_picture: imageUrl,
});
}
Value events fire with the entire data payload for any and all changes
Listen to ongoing events
var starCountRef = firebase.database().ref('posts/' + postId + '/starCount');
starCountRef.on('value', function(snapshot) {
updateStarCount(postElement, snapshot.val());
});
Listen to a single event and stop listening
var userId = firebase.auth().currentUser.uid;
return firebase
.database()
.ref('/users/' + userId)
.once('value')
.then(function(snapshot) {
var username = (snapshot.val() && snapshot.val().username) || 'Anonymous';
// ...
});
function writeNewPost(uid, username, picture, title, body) {
// A post entry.
var postData = {
author: username,
uid: uid,
body: body,
title: title,
starCount: 0,
authorPic: picture,
};