From f6d2ee2175d60bd74d444ff6b6cd75d89ff52cb8 Mon Sep 17 00:00:00 2001 From: Doug Martin Date: Mon, 8 Apr 2024 15:43:12 -0400 Subject: [PATCH] fix: Only call codap data changed when values change [PT-187390522] This prevents redrawing the autolayed graph after a simulation run. --- src/hooks/use-codap.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hooks/use-codap.ts b/src/hooks/use-codap.ts index fbceed9..6a48c1b 100644 --- a/src/hooks/use-codap.ts +++ b/src/hooks/use-codap.ts @@ -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, @@ -44,6 +44,7 @@ export const useCODAP = ({onCODAPDataChanged, getGraph, setGraph, setInitialGrap const [attribute, setAttribute] = useState(undefined); const [sequenceNumber, setSequenceNumber] = useState(0); const [viewMode, setViewMode] = useState(); + const valuesRef = useRef(); const getPluginState = useCallback(() => { const state: any = { @@ -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]);