Skip to content

Commit

Permalink
Merge pull request #243 from flatironinstitute/fix-setting-data-both-…
Browse files Browse the repository at this point in the history
…languages

Don't cache data contents in script state
  • Loading branch information
WardBrian authored Nov 4, 2024
2 parents 7ffaa63 + e9c2579 commit 03430c8
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 03430c8

Please sign in to comment.