[Major Refactor] Use pinia store to manage setting & nodeDef (#202)

* Node def store and settings tore

* Fix initial values

* Remove legacy setting listen

* Fix searchbox test
This commit is contained in:
Chenlei Hu
2024-07-24 11:49:09 -04:00
committed by GitHub
parent 84d8c5fc16
commit b73fe80761
10 changed files with 186 additions and 84 deletions

View File

@@ -0,0 +1,41 @@
/**
* TODO: Migrate scripts/ui/settings.ts here
*
* Currently the reactive settings act as a proxy of the legacy settings.
* Every time a setting is changed, the settingStore dispatch the change to the
* legacy settings. Every time the legacy settings are changed, the legacy
* settings directly updates the settingStore.settingValues.
*/
import { app } from "@/scripts/app";
import { ComfySettingsDialog } from "@/scripts/ui/settings";
import { defineStore } from "pinia";
interface State {
settingValues: Record<string, any>;
}
export const useSettingStore = defineStore("setting", {
state: (): State => ({
settingValues: {},
}),
actions: {
addSettings(settings: ComfySettingsDialog) {
for (const id in settings.settingsLookup) {
const value = settings.getSettingValue(id);
this.settingValues[id] = value;
}
},
set(key: string, value: any) {
this.settingValues[key] = value;
app.ui.settings.setSettingValue(key, value);
},
get(key: string) {
return (
this.settingValues[key] ?? app.ui.settings.getSettingDefaultValue(key)
);
},
},
});