diff --git a/frontend/app/store/wos.ts b/frontend/app/store/wos.ts index 66f78eb5a..f43117630 100644 --- a/frontend/app/store/wos.ts +++ b/frontend/app/store/wos.ts @@ -131,6 +131,36 @@ function useWaveObjectValueWithSuspense(oref: string): T { return dataValue.value; } +function getWaveObjectAtom(oref: string): jotai.Atom { + let wov = waveObjectValueCache.get(oref); + if (wov == null) { + wov = createWaveValueObject(oref, true); + waveObjectValueCache.set(oref, wov); + } + return jotai.atom((get) => { + let dataValue = get(wov.dataAtom); + if (dataValue.loading) { + return null; + } + return dataValue.value; + }); +} + +function getWaveObjectLoadingAtom(oref: string): jotai.Atom { + let wov = waveObjectValueCache.get(oref); + if (wov == null) { + wov = createWaveValueObject(oref, true); + waveObjectValueCache.set(oref, wov); + } + return jotai.atom((get) => { + let dataValue = get(wov.dataAtom); + if (dataValue.loading) { + return null; + } + return dataValue.loading; + }); +} + function useWaveObjectValue(oref: string): [T, boolean] { let wov = waveObjectValueCache.get(oref); if (wov == null) { @@ -309,6 +339,8 @@ export { cleanWaveObjectCache, clearWaveObjectCache, getObjectValue, + getWaveObjectAtom, + getWaveObjectLoadingAtom, loadAndPinWaveObject, makeORef, setObjectValue,