Skip to content

Commit

Permalink
CELE-32 fix: Improve use effect dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsobspinto committed Aug 1, 2024
1 parent 9693e60 commit 5c5707f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {Box} from "@mui/material";
import {ColoringOptions, getColor} from "../../../helpers/twoD/coloringHelper";
import ContextMenu from "./ContextMenu";
import {computeGraphDifferences, updateHighlighted} from "../../../helpers/twoD/graphRendering.ts";
import {areSetsEqual} from "../../../helpers/utils.ts";

cytoscape.use(fcose);
cytoscape.use(dagre);
Expand Down Expand Up @@ -118,7 +119,7 @@ const TwoDViewer = () => {
if (cyRef.current) {
updateGraphElements(cyRef.current, connections);
}
}, [connections, hiddenNodes, workspace.neuronGroups, includePostEmbryonic]);
}, [connections, hiddenNodes, workspace.neuronGroups, includePostEmbryonic, splitJoinState]);

useEffect(() => {
if (cyRef.current) {
Expand Down Expand Up @@ -241,7 +242,9 @@ const TwoDViewer = () => {
}
});

workspace.setActiveNeurons(activeNeurons);
if(!areSetsEqual(activeNeurons, workspace.activeNeurons)){
workspace.setActiveNeurons(activeNeurons);
}
}, [splitJoinState, workspace.id]);

// Effect to handle includeLabels state
Expand Down
11 changes: 11 additions & 0 deletions applications/visualizer/frontend/src/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function areSetsEqual<T>(setA: Set<T>, setB: Set<T>): boolean {
if (setA.size !== setB.size) {
return false;
}
for (let item of setA) {
if (!setB.has(item)) {
return false;
}
}
return true;
}

0 comments on commit 5c5707f

Please sign in to comment.