Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't cache data contents in script state #243

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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