Add checkInputandOutput function to flowStore.ts

This commit is contained in:
anovazzi1 2024-01-18 18:18:54 -03:00
commit 9c0d794dd1

View file

@ -20,6 +20,8 @@ import {
cleanEdges,
getHandleId,
getNodeId,
isInputNode,
isOutputNode,
scapeJSONParse,
scapedJSONStringfy,
} from "../utils/reactflowUtils";
@ -153,6 +155,21 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
})
);
},
checkInputandOutput: () => {
let has_input = false;
let has_output = false;
const nodes = get().nodes;
nodes.forEach((node) => {
const nodeData: NodeDataType = node.data as NodeDataType;
if (isInputNode(nodeData)) {
has_input = true;
}
if (isOutputNode(nodeData)) {
has_output = true;
}
});
return has_input && has_output;
},
getNode: (id: string) => {
return get().nodes.find((node) => node.id === id);
},