Refactor config to JSON data class pattern

Refactor the Config and ConfigGroup classes to match the JSON data class
pattern with toJSON, toRemote and fromJSON methods replacing the load,
init, and serialize methods.  Since fromJSON requires extra information
the messages structures passes around the plain JSON representation of
the configs instead of serialising instances of the config classes
automatically.
This commit is contained in:
Hornwitser committed 2024-01-06 19:53:32 +01:00
1 parent 27af142a87
commit 001db4befe
24 files changed
+269 -334

No files matched your search

@@ -48,8 +48,7 @@ export default function BaseConfigTree(props: BaseConfigTreeProps) {
async function updateConfig() {
let serializedConfig = await props.retrieveConfig();
let newConfig = new props.ConfigClass("control");
newConfig.load(serializedConfig);
const newConfig = props.ConfigClass.fromJSON(serializedConfig, "control");
setConfig(newConfig);
return newConfig;
}
@@ -197,12 +196,11 @@ export default function BaseConfigTree(props: BaseConfigTreeProps) {
</Form.Item>
<Button
size="small"
onClick={async () => {
onClick={() => {
let propName = form.getFieldValue(`${newPropPath}.name`);
let propValue = form.getFieldValue(`${newPropPath}.value`);
if (!Object.prototype.hasOwnProperty.call(value, propName)) {
let newConfig = new props.ConfigClass("control");
await newConfig.load(config!.serialize());
let newConfig = props.ConfigClass.fromJSON(config!.toJSON(), "control");
newConfig.setProp(fieldName, propName, null);
setConfig(newConfig);
}