Currently, settings ought to be saved any time anything changes in the ThingSettings dictionary. However, they are not (#108) - currently they only get saved when they are explicitly synced.
A sensible way forward might be a shallow auto-saving structure: if any item in ThingSettings is set, or if it's explicitly requested, we update settings.json. This has a few advantages:
- It is rather easier to make it work, and test that it works
- We don't have to wrap everything in home-made reactive types
- It's clear when settings are saved
The major drawback (and I think we should go ahead anyway) is that most Python objects are mutable, so it's possible to change the settings without that change being detected. For example, if a dictionary is stored in settings, it can be changed without ThingSettings re-syncing it to disk:
self.thing_settings["settingname"]["keyname"] = "value"
This is only reading self.thing_settings["settingname"] so nothing is triggered in thing_settings. That's not a unique issue to us though - I think it is reasonable just to be clear that the line above would require a call to thing_settings.sync() or similar.
Currently, settings ought to be saved any time anything changes in the
ThingSettingsdictionary. However, they are not (#108) - currently they only get saved when they are explicitly synced.A sensible way forward might be a shallow auto-saving structure: if any item in
ThingSettingsis set, or if it's explicitly requested, we updatesettings.json. This has a few advantages:The major drawback (and I think we should go ahead anyway) is that most Python objects are mutable, so it's possible to change the settings without that change being detected. For example, if a dictionary is stored in settings, it can be changed without
ThingSettingsre-syncing it to disk:This is only reading
self.thing_settings["settingname"]so nothing is triggered inthing_settings. That's not a unique issue to us though - I think it is reasonable just to be clear that the line above would require a call tothing_settings.sync()or similar.