Kevin Jump
04/05/2024, 12:59 PMts
this.#data.update({name: nameValue})
and that would update the name property.
however if my object has nested stuff. eg.
ts
export type myCustomThings = {
id : string;
name: string;
options: myCustomOptions
}
export type myCustomOptions = {
enabled: boolean,
useColors: boolean
}
then is there a nice way to update these child options individually, without you know having to read them all in and work it out myself 🙂
e.g
ts
this.#data.update({options : { useColors: false }});
doesn't work, because it replaces the whole 'options' method. So i obviously need to nest somehow ?Markus Johansson
04/05/2024, 1:31 PMKevin Jump
04/05/2024, 1:36 PMts
setSyncOption(alias: string, option: SyncSendOption) {
var settings = this.#data.getValue()?.sendSettings;
if (!settings) return;
const cloneSettings = structuredClone(settings);
cloneSettings[alias as keyof SyncSendOptions] = option;
this.#data.update({sendSettings : cloneSettings});
}
Kevin Jump
04/05/2024, 1:43 PMts
var mergedSettings = { ...settings, ...{ [alias] : option}};
this.#data.update({sendSettings: mergedSettings});
I just worry i will come back to this line of code in 12 months and not have a clue how it works 🙂Markus Johansson
04/05/2024, 2:18 PMMarkus Johansson
04/05/2024, 2:19 PMKevin Jump
04/05/2024, 2:20 PM[...^1]
or something actually means everytime is see it !Markus Johansson
04/05/2024, 2:21 PM