I am trying to work out how to use Realtime listeners efficiently.
Currently, I have set up a single listener in my loading screen. I have two issues.
- The listener isn’t working across different screens.
- Any change requires a snapshot of my entire users database.
Ideally, I would like to set up multiple listeners so that I only take a snapshot of the node that has changed. I can see my data fees increase significantly doing it the way I currently have it. Any suggestions?
I was just working throught a similar issue. A few observations and strategies for you (and those who find this thread in the future):
- Having multiple listeners for the Realtime DB Component on different screens results in only one of the Change Events Triggering
- Creating Mulitple Realtime DB Components (one for each screen) pointing to the same firebase database allows mulitple screens to update whenever data changes
Mulitple asynchronous event can be confusing. So to illustrate the point, here is a sample application:
If you add your firebase Web API key and database to this sample application, you can test it to see how it work. Here are a few highlights:
I have two separate screens (cheese and crakers). Each needs to update if either the cheese or cracker branch changes (respectively). I created 2 Realtime DB components, one for cheese and one for crackers. I created 2 listeners per realtime DB. With this system I can have any number of listeners, as long as each Realtime DB has only one listener (on one screen).
The Cheese Screen and Listener
The Cracker Screen and Listener
Thank you @drted,
This definitely gives me something new to play with and looks to be a promising work-around. I would never have thought of using different db blocks for the same Firebase db. It seems to be working but I need to test if the listener is now being triggered twice. (I have set the same listener node for both of my screens on each individual db listener block in their respective screens.
Thanks again. It has at least given me new breath with what I can try.
PS: I had just finished merging two of my screens to overcome this problem and now I have a screen with over 2000 blocks. It is slow to respond in the UI and selecting elements from the list is a little like “where’s wally”