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",