Skip to content

Commit

Permalink
fix: Only call codap data changed when values change [PT-187390522]
Browse files Browse the repository at this point in the history
This prevents redrawing the autolayed graph after a simulation run.
  • Loading branch information
dougmartin committed Apr 8, 2024
1 parent e042321 commit f6d2ee2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/hooks/use-codap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useState } from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import { Edge, GraphData, Node } from "../type";
import {
getValuesForAttribute,
Expand Down Expand Up @@ -44,6 +44,7 @@ export const useCODAP = ({onCODAPDataChanged, getGraph, setGraph, setInitialGrap
const [attribute, setAttribute] = useState<CODAPAttribute|undefined>(undefined);
const [sequenceNumber, setSequenceNumber] = useState(0);
const [viewMode, setViewMode] = useState<ViewMode|undefined>();
const valuesRef = useRef<string[]>();

const getPluginState = useCallback(() => {
const state: any = {
Expand Down Expand Up @@ -76,8 +77,9 @@ export const useCODAP = ({onCODAPDataChanged, getGraph, setGraph, setInitialGrap

const handleDataChanged = useCallback(async ({datasetName, collectionName, attributeName}: CODAPAttribute) => {
const values = await getValuesForAttribute(datasetName, collectionName, attributeName);
if (viewMode === "dataset") {
if (viewMode === "dataset" && (JSON.stringify(values) !== JSON.stringify(valuesRef.current))) {
onCODAPDataChanged(values);
valuesRef.current = values;
}
}, [onCODAPDataChanged, viewMode]);

Expand Down

0 comments on commit f6d2ee2

Please sign in to comment.