changed useFlow declaration from destructuring to selector to improve performance
This commit is contained in:
parent
68e5454b11
commit
503e7766ba
12 changed files with 49 additions and 27 deletions
|
|
@ -72,7 +72,10 @@ export default function ParameterComponent({
|
|||
const updateNodeInternals = useUpdateNodeInternals();
|
||||
const [position, setPosition] = useState(0);
|
||||
const { tabId, flows } = useContext(FlowsContext);
|
||||
const { nodes, edges, setNode } = useFlow();
|
||||
const nodes = useFlow((state) => state.nodes);
|
||||
const edges = useFlow((state) => state.edges);
|
||||
const setNode = useFlow((state) => state.setNode);
|
||||
|
||||
|
||||
const flow = flows.find((flow) => flow.id === tabId)?.data?.nodes ?? null;
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@ export default function GenericNode({
|
|||
yPos: number;
|
||||
}): JSX.Element {
|
||||
const { types } = useContext(typesContext);
|
||||
const { deleteNode, setNode } = useFlow();
|
||||
const deleteNode = useFlow((state) => state.deleteNode);
|
||||
const setNode = useFlow((state) => state.setNode);
|
||||
const name = nodeIconsLucide[data.type] ? data.type : types[data.type];
|
||||
const [inputName, setInputName] = useState(false);
|
||||
const [nodeName, setNodeName] = useState(data.node!.display_name);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ export default function BuildTrigger({
|
|||
}): JSX.Element {
|
||||
const { updateSSEData, isBuilding, setIsBuilding, sseData } = useSSE();
|
||||
const { setTabsState, saveFlow } = useContext(FlowsContext);
|
||||
const { nodes, edges } = useFlow();
|
||||
const nodes = useFlow((state) => state.nodes);
|
||||
const edges = useFlow((state) => state.edges);
|
||||
const { setErrorData, setSuccessData } = useContext(alertContext);
|
||||
const [isIconTouched, setIsIconTouched] = useState(false);
|
||||
const eventClick = isBuilding ? "pointer-events-none" : "";
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ import useFlow from "../../stores/flowManagerStore";
|
|||
export default function Chat({ flow }: ChatType): JSX.Element {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [canOpen, setCanOpen] = useState(false);
|
||||
const { isBuilt, setIsBuilt, isPending } = useFlow();
|
||||
const isBuilt = useFlow((state) => state.isBuilt);
|
||||
const setIsBuilt = useFlow((state) => state.setIsBuilt);
|
||||
const isPending = useFlow((state) => state.isPending);
|
||||
const { tabsState } =
|
||||
useContext(FlowsContext);
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,8 @@ export default function CodeTabsComponent({
|
|||
const [openAccordion, setOpenAccordion] = useState<string[]>([]);
|
||||
const {dark} = useDarkStore();
|
||||
|
||||
const { setNodes } = useFlow();
|
||||
const setNodes = useFlow((state) => state.setNodes);
|
||||
|
||||
const [errorDuplicateKey, setErrorDuplicateKey] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
|||
|
|
@ -104,7 +104,11 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
|||
const { setData } = useContext(typesContext);
|
||||
const [tabsState, setTabsState] = useState<FlowsState>({});
|
||||
|
||||
const {nodes, edges, paste, setPending, reactFlowInstance} = useFlow();
|
||||
const nodes = useFlow((state) => state.nodes);
|
||||
const edges = useFlow((state) => state.edges);
|
||||
const reactFlowInstance = useFlow((state) => state.reactFlowInstance);
|
||||
const setPending = useFlow((state) => state.setPending);
|
||||
const paste = useFlow((state) => state.paste);
|
||||
|
||||
function refreshFlows() {
|
||||
setIsLoading(true);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,10 @@ export function UndoRedoProvider({ children }) {
|
|||
const { tabId, flows } =
|
||||
useContext(FlowsContext);
|
||||
|
||||
const {setNodes, setEdges, nodes, edges} = useFlow();
|
||||
const setNodes = useFlow((state) => state.setNodes);
|
||||
const setEdges = useFlow((state) => state.setEdges);
|
||||
const nodes = useFlow((state) => state.nodes);
|
||||
const edges = useFlow((state) => state.edges);
|
||||
|
||||
const [past, setPast] = useState<HistoryItem[][]>(flows.map(() => []));
|
||||
const [future, setFuture] = useState<HistoryItem[][]>(flows.map(() => []));
|
||||
|
|
|
|||
|
|
@ -57,7 +57,10 @@ const EditNodeModal = forwardRef(
|
|||
) => {
|
||||
const [myData, setMyData] = useState(data);
|
||||
|
||||
const { setPending, edges, setNode } = useFlow();
|
||||
const setPending = useFlow((state) => state.setPending);
|
||||
const edges = useFlow((state) => state.edges);
|
||||
const setNode = useFlow((state) => state.setNode);
|
||||
|
||||
const { setModalContextOpen } = useContext(alertContext);
|
||||
|
||||
function changeAdvanced(n) {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ export default function FormModal({
|
|||
flow: FlowType;
|
||||
}): JSX.Element {
|
||||
const { tabsState, setTabsState } = useContext(FlowsContext);
|
||||
const { nodes, edges } = useFlow();
|
||||
const nodes = useFlow((state) => state.nodes);
|
||||
const edges = useFlow((state) => state.edges);
|
||||
const [chatValue, setChatValue] = useState(() => {
|
||||
try {
|
||||
const { formKeysData } = tabsState[flow.id];
|
||||
|
|
|
|||
|
|
@ -63,22 +63,20 @@ export default function Page({
|
|||
|
||||
const { takeSnapshot } = useContext(undoRedoContext);
|
||||
|
||||
const {
|
||||
reactFlowInstance,
|
||||
setReactFlowInstance,
|
||||
nodes,
|
||||
edges,
|
||||
onNodesChange,
|
||||
onEdgesChange,
|
||||
onConnect,
|
||||
setNodes,
|
||||
setEdges,
|
||||
deleteNode,
|
||||
deleteEdge,
|
||||
setPending,
|
||||
isPending,
|
||||
paste,
|
||||
} = useFlow();
|
||||
const reactFlowInstance = useFlow((state) => state.reactFlowInstance);
|
||||
const setReactFlowInstance = useFlow((state) => state.setReactFlowInstance);
|
||||
const nodes = useFlow((state) => state.nodes);
|
||||
const edges = useFlow((state) => state.edges);
|
||||
const onNodesChange = useFlow((state) => state.onNodesChange);
|
||||
const onEdgesChange = useFlow((state) => state.onEdgesChange);
|
||||
const onConnect = useFlow((state) => state.onConnect);
|
||||
const setNodes = useFlow((state) => state.setNodes);
|
||||
const setEdges = useFlow((state) => state.setEdges);
|
||||
const deleteNode = useFlow((state) => state.deleteNode);
|
||||
const deleteEdge = useFlow((state) => state.deleteEdge);
|
||||
const setPending = useFlow((state) => state.setPending);
|
||||
const isPending = useFlow((state) => state.isPending);
|
||||
const paste = useFlow((state) => state.paste);
|
||||
|
||||
const position = useRef({ x: 0, y: 0 });
|
||||
const [lastSelection, setLastSelection] =
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ export default function ExtraSidebar(): JSX.Element {
|
|||
const hasApiKey = useStoreStore((state) => state.hasApiKey);
|
||||
const validApiKey = useStoreStore((state) => state.validApiKey);
|
||||
|
||||
const { isBuilt, isPending } = useFlow();
|
||||
const isBuilt = useFlow((state) => state.isBuilt);
|
||||
const isPending = useFlow((state) => state.isPending);
|
||||
const { setErrorData } = useContext(alertContext);
|
||||
const [dataFilter, setFilterData] = useState(data);
|
||||
const [search, setSearch] = useState("");
|
||||
|
|
|
|||
|
|
@ -66,7 +66,11 @@ export default function NodeToolbarComponent({
|
|||
const isMinimal = canMinimize();
|
||||
const isGroup = data.node?.flow ? true : false;
|
||||
|
||||
const { paste, nodes, edges, setNodes, setEdges } = useFlow();
|
||||
const paste = useFlow((state) => state.paste);
|
||||
const nodes = useFlow((state) => state.nodes);
|
||||
const edges = useFlow((state) => state.edges);
|
||||
const setNodes = useFlow((state) => state.setNodes);
|
||||
const setEdges = useFlow((state) => state.setEdges);
|
||||
|
||||
const { saveComponent, flows, version } = useContext(FlowsContext);
|
||||
const { takeSnapshot } = useContext(undoRedoContext);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue