is there a way to watch for grandchild_added event with firebase?
I've set up a observer for child_added using the node.js javascript library but it won't trigger for when a child of a child is added.
I'm setting member presence info and would like to know when users enter a room.
i.e.
members/room/uname
In many cases using child_changed will be very cumbersome. It's a better approach to listen for child events itself.
Register a listener for the root, and register a listener for every child.
Here is the code in javascript to demonstrate this:
var Firebase = require("firebase");
var firebaseParentUrl = config.firebase.url
var firebaseChildUrl = config.firebase.url + "/child"
var parent = new Firebase(firebaseParentUrl, config.firebase.secret);
theParent.on("child_added", function (snapshot) {
var id = snapshot.key()
var theChild = new Firebase(firebaseChildUrl + id, config.firebase.secret)
theChild.on("child_added", function (snapshot) {
var grandChild = snapshot.val()
//now do something with grandChild
})
})
Listen for child_changed. Adding a grandchild counts as changing a child.
This might not be as granular as you like, unfortunately, but this was the only thing that worked for me. (Probably listening for 'value' works too, but this is even less granular.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With