mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-06 21:50:05 +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:
68
src/stores/nodeDefStore.ts
Normal file
68
src/stores/nodeDefStore.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { ComfyNodeDef } from "@/types/apiTypes";
|
||||
import { defineStore } from "pinia";
|
||||
|
||||
export const SYSTEM_NODE_DEFS: ComfyNodeDef[] = [
|
||||
{
|
||||
name: "PrimitiveNode",
|
||||
display_name: "Primitive",
|
||||
category: "utils",
|
||||
input: { required: {}, optional: {} },
|
||||
output: ["*"],
|
||||
output_name: ["connect to widget input"],
|
||||
output_is_list: [false],
|
||||
python_module: "nodes",
|
||||
description: "Primitive values like numbers, strings, and booleans.",
|
||||
},
|
||||
{
|
||||
name: "Reroute",
|
||||
display_name: "Reroute",
|
||||
category: "utils",
|
||||
input: { required: { "": ["*"] }, optional: {} },
|
||||
output: ["*"],
|
||||
output_name: [""],
|
||||
output_is_list: [false],
|
||||
python_module: "nodes",
|
||||
description: "Reroute the connection to another node.",
|
||||
},
|
||||
{
|
||||
name: "Note",
|
||||
display_name: "Note",
|
||||
category: "utils",
|
||||
input: { required: {}, optional: {} },
|
||||
output: [],
|
||||
output_name: [],
|
||||
output_is_list: [],
|
||||
python_module: "nodes",
|
||||
description: "Node that add notes to your project",
|
||||
},
|
||||
];
|
||||
|
||||
const SYSTEM_NODE_DEFS_BY_NAME = SYSTEM_NODE_DEFS.reduce((acc, nodeDef) => {
|
||||
acc[nodeDef.name] = nodeDef;
|
||||
return acc;
|
||||
}, {}) as Record<string, ComfyNodeDef>;
|
||||
|
||||
interface State {
|
||||
nodeDefsByName: Record<string, ComfyNodeDef>;
|
||||
}
|
||||
|
||||
export const useNodeDefStore = defineStore("nodeDef", {
|
||||
state: (): State => ({
|
||||
nodeDefsByName: SYSTEM_NODE_DEFS_BY_NAME,
|
||||
}),
|
||||
getters: {
|
||||
nodeDefs(state) {
|
||||
return Object.values(state.nodeDefsByName);
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
addNodeDef(nodeDef: ComfyNodeDef) {
|
||||
this.nodeDefsByName[nodeDef.name] = nodeDef;
|
||||
},
|
||||
addNodeDefs(nodeDefs: ComfyNodeDef[]) {
|
||||
for (const nodeDef of nodeDefs) {
|
||||
this.addNodeDef(nodeDef);
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
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