Skip to content

Commit

Permalink
Don't cache data contents in script state
Browse files Browse the repository at this point in the history
  • Loading branch information
WardBrian committed Nov 4, 2024
1 parent 7b7e63d commit e9c2579
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions gui/src/app/Scripting/DataGeneration/useDataGenState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,24 @@ const useDataGenState = (source: "python" | "r") => {
const [status, setStatus] = useState<InterpreterStatus>("idle");
const consoleRef = useRef<HTMLDivElement>(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],
);
Expand Down

0 comments on commit e9c2579

Please sign in to comment.