[Solved] Working with cloud lists

I’m wondering if anyone can answer my question related to using lists with the cloud variables.

I have begun saving objects to lists firebase instead of airtable. it works quite nice.

i am running into issues when i delete nodes from that list. this breaks ‘list actions’

in brief. I had tried to delete node 0 from the data ‘bucket’ above and it broke the following code. using debugging i could identify that the ‘break’ occurred on the very first check in the loop

here is a shot of the blocks from start to freeze

I assign the cloud bucket to a local variable
Screen Shot 2020-12-19 at 6.28.12 AM
I then call the function “fetch_chart_1” which immediately calls ‘fetchchartdata’

Screen Shot 2020-12-19 at 6.28.17 AM

‘fetch chart data’ uses the cloud bucket as the data source now for the loop and the app pauses after the loop starts but before the first check is completeScreen Shot 2020-12-19 at 6.28.22 AM

the weird thing is, when i delete a node, the above code breaks. if i enter literally anything and replace the deleted node, everything works fine

1 Like

@jared,

Glad to see you have come into the light (Firebase) and rejected the darkness (data sources). :crazy_face:

The way Thunkable and Firebase interact on lists is the problem. Firebase assigns number to each item in the list. From my limited reading, lists (aka Arrays) are sequence dependent. This seems like the rationale for Firebase assigning numbers.
image

(apparently) Thunkable assumes that the array/list in Firebase will be a zero based listed with no gaps. If there are gaps, Thunakble fails. You can test this out by trying to retrieve your “data” list in a few scenarios. Using the Realtime database website UI.

  1. base case (works correctly in thunkable)
  2. Delete the last entry (works correctly in thunkable)
  3. Delete any other entry (thunkable fails)
  4. Add back the deleted number with some goofy value (works correctly in thunkable)

SOLUTION
Finally, getting back to to your problem, here are the solutions I have used, depending on the situation:

  • If the sequence is IMPORTANT (e.g. logs, chat threads, etc), load the list from firebase into thunkable. Delete the items using the thunkable list blocks, then save the entire list back to firebase
  • If the sequence is UNIMPORTANT (e.g. members of a group, shopping cart items, etc.) use JSON Properties instead of a list. To make sure the name of the property is unique, i use the the Firebase UserID (returned from the sign in block) and the Seconds Since 1970 block (with the decimal removed)

    In the example below “Conversations” would normally be a list, but since the order doesn’t matter, there are just a bunch of properties.
    image

To loop through the elements in the “list” you can use something like this


Notice that the list contains the Property NAME, not the actual value. It took me a while to get used to this, but now it is second nature.

Happy Thunking!

3 Likes

The only practical solution I arrived to after number of attempts is the [get object properties of] and then use this list to loop through the contents of other object properties.

I needed it for a reward card system which logs purchase transactions and some transactions are not entitled for the rewards and had to be removed which resulted in the loop breaking out and could not find any other way to solve the issue although I don’t know what would be the maximum number of properties the object block could return.

1 Like

@muneer,
Initially i was worreid about the number properties as well. From my limited reading, JSON arrays were a later addition. Before arrays, sequence-dependent list were just properties with clever names:

  • ListItem001
  • ListItem002
  • ListItem003
  • ListItemN

I now have firebase objects with hundreds of properties.

From what I can tell, firebase just treats arrays like a special case of properties. A property node and list item X display in identical ways. Firebase doesn’t care if you delete list item 3. It keeps working just fine. You can even test this by retrieving a single list item by referencing the node number.

You can even use this technique to pluck out properties from an object within the list

4 Likes

Thank you @drted, this is comforting. My app is now live with the client and I keep watching the Firebase statistics. :crossed_fingers: it is working fine till now.

2 Likes