I have an application for the iOS platform where I listen to changes for every item that is sold in this market. More precisely, I listen to whether the children have changed on this subject or have left.
The problem is that I want to listen when children are added. The feature of listening when a child is added to Firebase is that you get all the siblings on this node when you first set up the listener.
Children on an item are not lists of the same item, so I cannot listen to children added after a specific timestamp. I thought of doing something like this and ignoring these initial children. It just seems such a big mess, because I, in fact, collect things from Firebase twice. Once with FEventTypeValue and once with FEventTypeChildAdded .
The elements I want to listen to are the elements that are loaded into the feed. Most likely, it will be a couple of hundreds of items, but there could potentially be thousands of items.
How would you do that? Should I just forget everything about listening to added children or is there a decent solution for this?
Edit (added sample code):
So this is how I take data for a specific item in Firebase.
var ref = new Firebase('https://<your-Firebase>.firebaseio.com'); ref.child('listings/-KB9ZqLZBEskoUihb-yR').once('value', function(snapshot) { listing = snapshot.val(); });
And here I want to listen when a new child is added to this element:
ref.child('listings/-KB9ZqLZBEskoUihb-yR').on('child_added', function(snapshot) { listing[snapshot.key()] = snapshot.val() });
The problem is that listening to the elements added to this node again retrieves all the child nodes, and this seems like a huge waste. How would you handle this situation?