refactor(react): use array for nodeInternals, rename to nodes

This commit is contained in:
moklick
2023-06-12 16:56:02 +02:00
parent cefdfd4e70
commit c6501aff62
33 changed files with 146 additions and 197 deletions
+3 -3
View File
@@ -11,7 +11,7 @@ export function getMouseHandler(
return handler === undefined
? handler
: (event: MouseEvent) => {
const node = getState().nodeInternals.get(id)!;
const node = getState().nodes.find((n) => n.id === id)!;
handler(event, { ...node });
};
}
@@ -34,8 +34,8 @@ export function handleNodeClick({
unselect?: boolean;
nodeRef?: RefObject<HTMLDivElement>;
}) {
const { addSelectedNodes, unselectNodesAndEdges, multiSelectionActive, nodeInternals } = store.getState();
const node = nodeInternals.get(id)!;
const { addSelectedNodes, unselectNodesAndEdges, multiSelectionActive, nodes } = store.getState();
const node = nodes.find((n) => n.id === id)!;
store.setState({ nodesSelectionActive: false });
@@ -78,7 +78,7 @@ export default (NodeComponent: ComponentType<NodeProps>) => {
}
if (onClick) {
const node = store.getState().nodeInternals.get(id)!;
const node = store.getState().nodes.find((n) => n.id === id)!;
onClick(event, { ...node });
}
};