Detecting changes in Firebase - suggestions?

All,

I’ve got grocery lists in Firebase. Eventually the lists will be shared, meaning multiple users might be making changes to the same list at once. (Different lists are no issue, but I’m thinking about my husband and I simultaneously assembling our grocery list.)

I’m using cloned blocks to display the list, so there’s not an automatic refresh like with dataviewer and listviewer. I see two options:

  1. Every so often, recreate the whole set of cloned rows from fresh data. (That could be on a timer, or could be user triggered.) That’s simple and uses the code I already wrote for setting up the page to begin with. The list loading time is not too bad for first getting to the page, but I’m thinking it’s just slow enough to be annoying for a user actively working on the list. [Actually, I could trigger it with a listener - that’d be better.]

  2. Do something clever. I thought I’d use a listener, but it looks like the listener returns the key it’s listening to and the FULL data under that key, not just the changed values (bummer), so I’d need to add a whole lot of listeners. Like 50 of them, if I’m watching each current item for changes.? I guess I’ll have to try that and see if there’s a performance hit. But then I also need to know if a new item has been added to the list, so I’m back to having to watch the whole list anyway. So maybe the listener just watches the list for changes and then I iterate through my cloned components to figure out what to change.

Thoughts? Input? Better option #3 that I’m not thinking of?

1 Like

You don’t have much choice but settle to use the cloud variable initialize or change. I had a similar challenge and end up creating an app variable object holding the latest “grocery” list and every time the listener is triggered I first copy the object to another app variable object then run through the object comparing items to detect the change which prove to be much quicker than trying to rebuild the list in the screen.

Thanks for your answer, @muneer! I know how to do this with a listener, but I don’t know how to detect that a cloud variable has changed without creating a listener. This block only offers app variables.
image Can you tell me how to detect a cloud variable changing in a cloud variable way, instead of declaring a listener?

1 Like

I do it this way

Of course the drawback is that you cannot listen to dynamically created cloud names.

1 Like

Ah, now I see. I don’t have any of my cloud variables actually declared, so I wasn’t seeing the option.

My data bins are changing, so I need a dynamic option. But I can add listeners dynamically, so I’ll do it that way!

1 Like