From 7a54b79bda75091f4f3f1fa674b00ce0b11faf0a Mon Sep 17 00:00:00 2001 From: sawka Date: Tue, 28 May 2024 17:17:52 -0700 Subject: [PATCH] added getWaveObjectAtom --- frontend/app/store/wos.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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,