Quantcast
Channel: Listen to items added on hundred of children in Firebase - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Listen to items added on hundred of children in Firebase

$
0
0

I have an iOS marketplace app, where I'm listening for changes on each item that is for sale on that marketplace. More precisely, I'm listen for whether children on that item change or gets removed.

Issue is that I want to listen for when children are added as well. The peculiar thing about listening for when a child is added on Firebase, is that you get all the siblings on that node when you first set up the listener.

The children on an item is not a lists of the same item, so I can't listen for children added after a certain timestamp. I was thinking about doing something like this and ignore those initial children. It just seems like such a big waste to, since I'm essentially fetching things from Firebase twice then. Once with FEventTypeValue and once with FEventTypeChildAdded.

The items I want to listen for are the items that are getting loaded in the feed. It would most likely be a couple of hundred of items, but could potentially be thousands of items.

How would you go about this? Should I just forget all about listening for added children or is there a decent solution for this?

Edit (added example code):

So this is how I fetch the data for a specific item on 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 for when a new child is added to that item:

ref.child('listings/-KB9ZqLZBEskoUihb-yR').on('child_added', function(snapshot) {  listing[snapshot.key()] = snapshot.val()});

Issue is that listening to items added on that node fetches all the child nodes again and that seems like a huge waste. How would you deal with this situation?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images