mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
perf(ui): ignore all no-op node and edge changes
This commit is contained in:
parent
9ed5698aa8
commit
059c5586a4
@ -143,16 +143,24 @@ const AddNodePopover = () => {
|
|||||||
// Deselect all other nodes and edges
|
// Deselect all other nodes and edges
|
||||||
const nodeChanges: NodeChange[] = [{ type: 'add', item: node }];
|
const nodeChanges: NodeChange[] = [{ type: 'add', item: node }];
|
||||||
const edgeChanges: EdgeChange[] = [];
|
const edgeChanges: EdgeChange[] = [];
|
||||||
nodes.forEach(({ id }) => {
|
nodes.forEach(({ id, selected }) => {
|
||||||
|
if (selected) {
|
||||||
nodeChanges.push({ type: 'select', id, selected: false });
|
nodeChanges.push({ type: 'select', id, selected: false });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
edges.forEach(({ id }) => {
|
edges.forEach(({ id, selected }) => {
|
||||||
|
if (selected) {
|
||||||
edgeChanges.push({ type: 'select', id, selected: false });
|
edgeChanges.push({ type: 'select', id, selected: false });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Onwards!
|
// Onwards!
|
||||||
|
if (nodeChanges.length > 0) {
|
||||||
dispatch(nodesChanged(nodeChanges));
|
dispatch(nodesChanged(nodeChanges));
|
||||||
|
}
|
||||||
|
if (edgeChanges.length > 0) {
|
||||||
dispatch(edgesChanged(edgeChanges));
|
dispatch(edgesChanged(edgeChanges));
|
||||||
|
}
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
[buildInvocation, store, dispatch, t, toaster]
|
[buildInvocation, store, dispatch, t, toaster]
|
||||||
|
@ -90,15 +90,17 @@ export const Flow = memo(() => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const onNodesChange: OnNodesChange = useCallback(
|
const onNodesChange: OnNodesChange = useCallback(
|
||||||
(changes) => {
|
(nodeChanges) => {
|
||||||
dispatch(nodesChanged(changes));
|
dispatch(nodesChanged(nodeChanges));
|
||||||
},
|
},
|
||||||
[dispatch]
|
[dispatch]
|
||||||
);
|
);
|
||||||
|
|
||||||
const onEdgesChange: OnEdgesChange = useCallback(
|
const onEdgesChange: OnEdgesChange = useCallback(
|
||||||
(changes) => {
|
(changes) => {
|
||||||
|
if (changes.length > 0) {
|
||||||
dispatch(edgesChanged(changes));
|
dispatch(edgesChanged(changes));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[dispatch]
|
[dispatch]
|
||||||
);
|
);
|
||||||
@ -207,14 +209,22 @@ export const Flow = memo(() => {
|
|||||||
const { nodes, edges } = store.getState().nodes.present;
|
const { nodes, edges } = store.getState().nodes.present;
|
||||||
const nodeChanges: NodeChange[] = [];
|
const nodeChanges: NodeChange[] = [];
|
||||||
const edgeChanges: EdgeChange[] = [];
|
const edgeChanges: EdgeChange[] = [];
|
||||||
nodes.forEach(({ id }) => {
|
nodes.forEach(({ id, selected }) => {
|
||||||
|
if (!selected) {
|
||||||
nodeChanges.push({ type: 'select', id, selected: true });
|
nodeChanges.push({ type: 'select', id, selected: true });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
edges.forEach(({ id }) => {
|
edges.forEach(({ id, selected }) => {
|
||||||
|
if (!selected) {
|
||||||
edgeChanges.push({ type: 'select', id, selected: true });
|
edgeChanges.push({ type: 'select', id, selected: true });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
if (nodeChanges.length > 0) {
|
||||||
dispatch(nodesChanged(nodeChanges));
|
dispatch(nodesChanged(nodeChanges));
|
||||||
|
}
|
||||||
|
if (edgeChanges.length > 0) {
|
||||||
dispatch(edgesChanged(edgeChanges));
|
dispatch(edgesChanged(edgeChanges));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[dispatch, store]
|
[dispatch, store]
|
||||||
);
|
);
|
||||||
@ -275,8 +285,12 @@ export const Flow = memo(() => {
|
|||||||
.forEach(({ id }) => {
|
.forEach(({ id }) => {
|
||||||
edgeChanges.push({ type: 'remove', id });
|
edgeChanges.push({ type: 'remove', id });
|
||||||
});
|
});
|
||||||
|
if (nodeChanges.length > 0) {
|
||||||
dispatch(nodesChanged(nodeChanges));
|
dispatch(nodesChanged(nodeChanges));
|
||||||
|
}
|
||||||
|
if (edgeChanges.length > 0) {
|
||||||
dispatch(edgesChanged(edgeChanges));
|
dispatch(edgesChanged(edgeChanges));
|
||||||
|
}
|
||||||
}, [dispatch, store]);
|
}, [dispatch, store]);
|
||||||
useHotkeys(['delete', 'backspace'], onDeleteHotkey);
|
useHotkeys(['delete', 'backspace'], onDeleteHotkey);
|
||||||
|
|
||||||
|
@ -40,9 +40,16 @@ const NodeWrapper = (props: NodeWrapperProps) => {
|
|||||||
(e: MouseEvent<HTMLDivElement>) => {
|
(e: MouseEvent<HTMLDivElement>) => {
|
||||||
if (!e.ctrlKey && !e.altKey && !e.metaKey && !e.shiftKey) {
|
if (!e.ctrlKey && !e.altKey && !e.metaKey && !e.shiftKey) {
|
||||||
const { nodes } = store.getState().nodes.present;
|
const { nodes } = store.getState().nodes.present;
|
||||||
const nodeChanges: NodeChange[] = nodes.map(({ id }) => ({ type: 'select', id, selected: id === nodeId }));
|
const nodeChanges: NodeChange[] = [];
|
||||||
|
nodes.forEach(({ id, selected }) => {
|
||||||
|
if (selected !== (id === nodeId)) {
|
||||||
|
nodeChanges.push({ type: 'select', id, selected: id === nodeId });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (nodeChanges.length > 0) {
|
||||||
dispatch(nodesChanged(nodeChanges));
|
dispatch(nodesChanged(nodeChanges));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
onCloseGlobal();
|
onCloseGlobal();
|
||||||
},
|
},
|
||||||
[onCloseGlobal, store, dispatch, nodeId]
|
[onCloseGlobal, store, dispatch, nodeId]
|
||||||
|
@ -92,15 +92,15 @@ export const useConnection = () => {
|
|||||||
);
|
);
|
||||||
if (connection) {
|
if (connection) {
|
||||||
const newEdge = connectionToEdge(connection);
|
const newEdge = connectionToEdge(connection);
|
||||||
const changes: EdgeChange[] = [{ type: 'add', item: newEdge }];
|
const edgeChanges: EdgeChange[] = [{ type: 'add', item: newEdge }];
|
||||||
|
|
||||||
const nodesToUpdate = [newEdge.source, newEdge.target];
|
const nodesToUpdate = [newEdge.source, newEdge.target];
|
||||||
if (edgePendingUpdate) {
|
if (edgePendingUpdate) {
|
||||||
$didUpdateEdge.set(true);
|
$didUpdateEdge.set(true);
|
||||||
changes.push({ type: 'remove', id: edgePendingUpdate.id });
|
edgeChanges.push({ type: 'remove', id: edgePendingUpdate.id });
|
||||||
nodesToUpdate.push(edgePendingUpdate.source, edgePendingUpdate.target);
|
nodesToUpdate.push(edgePendingUpdate.source, edgePendingUpdate.target);
|
||||||
}
|
}
|
||||||
dispatch(edgesChanged(changes));
|
dispatch(edgesChanged(edgeChanges));
|
||||||
updateNodeInternals(nodesToUpdate);
|
updateNodeInternals(nodesToUpdate);
|
||||||
}
|
}
|
||||||
$pendingConnection.set(null);
|
$pendingConnection.set(null);
|
||||||
|
@ -73,12 +73,14 @@ const pasteSelection = (withEdgesToCopiedNodes?: boolean) => {
|
|||||||
const nodeChanges: NodeChange[] = [];
|
const nodeChanges: NodeChange[] = [];
|
||||||
const edgeChanges: EdgeChange[] = [];
|
const edgeChanges: EdgeChange[] = [];
|
||||||
// Deselect existing nodes
|
// Deselect existing nodes
|
||||||
nodes.forEach(({ id }) => {
|
nodes.forEach(({ id, selected }) => {
|
||||||
|
if (selected) {
|
||||||
nodeChanges.push({
|
nodeChanges.push({
|
||||||
type: 'select',
|
type: 'select',
|
||||||
id,
|
id,
|
||||||
selected: false,
|
selected: false,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// Add new nodes
|
// Add new nodes
|
||||||
copiedNodes.forEach((n) => {
|
copiedNodes.forEach((n) => {
|
||||||
@ -88,12 +90,14 @@ const pasteSelection = (withEdgesToCopiedNodes?: boolean) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
// Deselect existing edges
|
// Deselect existing edges
|
||||||
edges.forEach(({ id }) => {
|
edges.forEach(({ id, selected }) => {
|
||||||
|
if (selected) {
|
||||||
edgeChanges.push({
|
edgeChanges.push({
|
||||||
type: 'select',
|
type: 'select',
|
||||||
id,
|
id,
|
||||||
selected: false,
|
selected: false,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// Add new edges
|
// Add new edges
|
||||||
copiedEdges.forEach((e) => {
|
copiedEdges.forEach((e) => {
|
||||||
@ -102,8 +106,12 @@ const pasteSelection = (withEdgesToCopiedNodes?: boolean) => {
|
|||||||
item: e,
|
item: e,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
if (nodeChanges.length > 0) {
|
||||||
dispatch(nodesChanged(nodeChanges));
|
dispatch(nodesChanged(nodeChanges));
|
||||||
|
}
|
||||||
|
if (edgeChanges.length > 0) {
|
||||||
dispatch(edgesChanged(edgeChanges));
|
dispatch(edgesChanged(edgeChanges));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const api = { copySelection, pasteSelection };
|
const api = { copySelection, pasteSelection };
|
||||||
|
Loading…
Reference in New Issue
Block a user