Extend the binding API to support structured persistent storage #2978
Replies: 4 comments 7 replies
-
|
Thanks, @Aues6uen11Z! Creating nested structures like ui.number().bind_value(robot, ('motors', 'left_axis', 'max_speed'))sounds very convenient. I wonder if an API like this would be even more handy: ui.number().bind_value(robot, 'motors.left_axis.max_speed')But this would cause conflicts with dictionary keys containing dots... Or could we use ui.number().bind_value(robot, 'motors', 'left_axis', 'max_speed') |
Beta Was this translation helpful? Give feedback.
-
|
Hey BR |
Beta Was this translation helpful? Give feedback.
-
|
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
As discussed in #2923, the existing methods find it difficult to create a multi-layered JSON structure in persistent storage (such as app.storage.general), which makes subsequent retrieval and access challenging. Directly using libraries like addict to improve
PersistDictmight bring some potential problems.Therefore, my idea is to improve the binding API by automatically creating non-existent keys when binding dictionary data. This way, we can achieve the goal without affecting the existing binding usage. Specifically, I added the
_convert_targetmethod as shown below.Then we can use it like this:
This method is indeed a bit quirky because the original
target_nameofbind_valuewas all of typestr, and nowtupletype has been specially added for dict, which seems inconsistent. I wonder if there is a better implementation method?Beta Was this translation helpful? Give feedback.
All reactions