mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-02 11:40:00 +00:00
[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:
41
src/stores/settingStore.ts
Normal file
41
src/stores/settingStore.ts
Normal 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)
|
||||
);
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user