From e9c257941549cec2b68d5eeb71edecd1d50aebc8 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Mon, 4 Nov 2024 21:06:57 +0000 Subject: [PATCH] Don't cache data contents in script state --- .../DataGeneration/useDataGenState.ts | 43 +++++++------------ 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/gui/src/app/Scripting/DataGeneration/useDataGenState.ts b/gui/src/app/Scripting/DataGeneration/useDataGenState.ts index 830918b..265cf9a 100644 --- a/gui/src/app/Scripting/DataGeneration/useDataGenState.ts +++ b/gui/src/app/Scripting/DataGeneration/useDataGenState.ts @@ -10,37 +10,24 @@ const useDataGenState = (source: "python" | "r") => { const [status, setStatus] = useState("idle"); const consoleRef = useRef(null); - const { data, update } = useContext(ProjectContext); + const { update } = useContext(ProjectContext); - // we don't want the callback to force itself to re-render when data is set - const lastData = useRef(data.dataFileContent); const onData = useCallback( (newData: unknown) => { - const dataJson = JSON.stringify(newData, null, 2); - - if (dataJson !== lastData.current) { - lastData.current = dataJson; - update({ - type: "generateData", - content: dataJson, - dataSource: - source === "python" - ? DataSource.GENERATED_BY_PYTHON - : DataSource.GENERATED_BY_R, - }); - // Use "stan-playground" prefix to distinguish from console output of the running code - writeConsoleOutToDiv( - consoleRef, - "[stan-playground] Data updated", - "stdout", - ); - } else { - writeConsoleOutToDiv( - consoleRef, - "[stan-playground] Data unchanged", - "stdout", - ); - } + update({ + type: "generateData", + content: JSON.stringify(newData, null, 2), + dataSource: + source === "python" + ? DataSource.GENERATED_BY_PYTHON + : DataSource.GENERATED_BY_R, + }); + // Use "stan-playground" prefix to distinguish from console output of the running code + writeConsoleOutToDiv( + consoleRef, + "[stan-playground] Data updated", + "stdout", + ); }, [update, consoleRef], );