Firebase child_added for new items only

前端 未结 5 1171
北恋
北恋 2020-12-15 18:46

I am using Firebase and Node with Redux. I am loading all objects from a key as follows.

firebaseDb.child(\'invites\').on(\'child_added\', snapshot => {
}         


        
5条回答
  •  天涯浪人
    2020-12-15 19:11

    I solved this by ignoring child_added all together, and using just child_changed. The way I did this was to perform an update() on any items i needed to handle after pushing them to the database. This solution will depend on your needs, but one example is to update a timestamp key whenever you want the event triggered. For example:

    var newObj = { ... }
    // push the new item with no events
    fb.push(newObj)
    // update a timestamp key on the item to trigger child_changed
    fb.update({ updated: yourTimeStamp })
    

提交回复
热议问题