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
I then call the function “fetch_chart_1” which immediately calls ‘fetchchartdata’
‘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 complete
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
Glad to see you have come into the light (Firebase) and rejected the darkness (data sources).
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.
(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.
base case (works correctly in thunkable)
Delete the last entry (works correctly in thunkable)
Delete any other entry (thunkable fails)
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)
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.
@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.