Home > database >  When does QuerySnapshot notify its listener?
When does QuerySnapshot notify its listener?

Time:04-25

I didn't see in any document that tell me when does QuerySnapshot emit new snapshot, when any document in this query change? when any data in collection change? or what?

CodePudding user response:

If you're using a snapshot listener:

  1. It emits an event right away when you first attach that listener with a snapshot of the current data that it is listening to.
  2. It then emits another snapshot whenever there is a change to any of the data it listens to.

In your callback, you can always seen the current snapshot of all data by accessing the QuerySnapshot.docs property. If you want to only check the changes, you can the use the QuerySnapshot.docChanges property instead.

  • Related