Используйте методы on () или once () для firebase.database.Reference
для наблюдения за событиями, как подробно описано здесь: https://firebase.google.com/docs/database/web/read-and-write#listen_for_value_events
Например, вы можете сделать:
var starCountRef = firebase.database().ref('posts/' + postId + '/starCount');
starCountRef.on('value', function(snapshot) {
yourFunction(); //<- call your function here
});
или
var starCountRef = firebase.database().ref('posts/' + postId);
starCountRef.on('value', function(snapshot) {
yourFunction(snapshot.val().postAuthor); //<- example, we pass the author of the Post to the function
});
Если вы хотите передать значение из снимка в качестве параметра вашей функции