From 0f6ff129e2c827e379a386f13ac59efd95ae7bcb Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Wed, 17 Jul 2024 20:10:57 +0000 Subject: [PATCH] Further tweaks --- gui/src/app/StanSampler/StanSampler.ts | 15 ++++++++------- gui/src/app/StanSampler/useStanSampler.ts | 13 +++++-------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/gui/src/app/StanSampler/StanSampler.ts b/gui/src/app/StanSampler/StanSampler.ts index 51287343..d69e6a8b 100644 --- a/gui/src/app/StanSampler/StanSampler.ts +++ b/gui/src/app/StanSampler/StanSampler.ts @@ -1,7 +1,6 @@ import { SamplingOpts } from "@SpCore/ProjectDataModel"; import { Replies, Requests } from "@SpStanSampler/StanModelWorker"; import StanWorkerUrl from "@SpStanSampler/StanModelWorker?worker&url"; -import React from "react"; import type { SamplerParams } from "tinystan"; import { type StanRunAction } from "./useStanSampler"; @@ -13,24 +12,26 @@ export type StanSamplerStatus = | "completed" | "failed"; +type StanSamplerAndCleanup = { + sampler: StanSampler; + cleanup: () => void; +}; + class StanSampler { #worker: Worker | undefined; #samplingStartTimeSec: number = 0; private constructor( private compiledUrl: string, - private update: React.Dispatch, + private update: (action: StanRunAction) => void, ) { this._initialize(); } static __unsafe_create( compiledUrl: string, - update: React.Dispatch, - ): { - sampler: StanSampler; - cleanup: () => void; - } { + update: (action: StanRunAction) => void, + ): StanSamplerAndCleanup { const sampler = new StanSampler(compiledUrl, update); const cleanup = () => { console.log("terminating model worker"); diff --git a/gui/src/app/StanSampler/useStanSampler.ts b/gui/src/app/StanSampler/useStanSampler.ts index 412eb1a6..e38d6267 100644 --- a/gui/src/app/StanSampler/useStanSampler.ts +++ b/gui/src/app/StanSampler/useStanSampler.ts @@ -52,14 +52,11 @@ export const StanRunReducer = ( case "progressUpdate": return { ...state, progress: action.progress }; case "statusUpdate": - if (action.errorMessage) { - return { - ...state, - status: action.status, - errorMessage: action.errorMessage, - }; - } - return { ...state, status: action.status }; + return { + ...state, + status: action.status, + errorMessage: action.errorMessage ?? state.errorMessage, + }; case "startSampling": return { status: "sampling",