Any suggestions for handling change to a list in a ValueTree atomically?

I have a couple of lists of integers that I want to store in a ValueTree, but I want to perform a task, using an updated list, atomically, ie. not receive callbacks for each item changing. I want to do this because the values are then sent, as a single list, through another API.

Making them all properties results in a callback per property, making them children results in a callback per child. Making sure they are always updated in a specific order, and a doing the update on the last one doesn’t work because if the last value doesn’t actually change, then I don’t get the callback. I can’t store them as an Array<var> because I export the ValueTree as XML.

The solution I am leaning towards is simply to remove and re-add the ValueTree to the parent, using the single valueTreeChildAdded callback to do the update. Anyways, just thought I would survey the community to see if anyone else has done something like this, and settled on a solution. Thanks in advance.

You could store all of the properties in a single DynamicObject, then store the DynamicObject in the tree. That would just give you one callback.


Thanks Matt, but that solution doesn’t take into account the part about exporting the ValueTree as XML. :frowning:

True; you’d have to make your own XML exporter and importer. I’ve struggled with this one myself.


@cpr In addition to storing the values (int(s)) as properties, store a serialized version of the list in a special property (that you could potentially omit when dumping the tree to xml). This could be a comma separated list of int(s) or even some xml string (if you need the items to be named/organized).

@hhit, I had previously considered storing the list as a comma separated string property, but somehow I forgot about it. The list is associated with a preset type data structure, and thus doesn’t change with any high frequency, so I think this may be a cleaner solution than messing with removing/adding a child. Thanks for the suggestion.