mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
added getWaveObjectAtom
This commit is contained in:
parent
609f2ec85c
commit
7a54b79bda
@ -131,6 +131,36 @@ function useWaveObjectValueWithSuspense<T>(oref: string): T {
|
||||
return dataValue.value;
|
||||
}
|
||||
|
||||
function getWaveObjectAtom<T extends WaveObj>(oref: string): jotai.Atom<T> {
|
||||
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<T extends WaveObj>(oref: string): jotai.Atom<boolean> {
|
||||
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<T>(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,
|
||||
|
Loading…
Reference in New Issue
Block a user