mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48: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;
|
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] {
|
function useWaveObjectValue<T>(oref: string): [T, boolean] {
|
||||||
let wov = waveObjectValueCache.get(oref);
|
let wov = waveObjectValueCache.get(oref);
|
||||||
if (wov == null) {
|
if (wov == null) {
|
||||||
@ -309,6 +339,8 @@ export {
|
|||||||
cleanWaveObjectCache,
|
cleanWaveObjectCache,
|
||||||
clearWaveObjectCache,
|
clearWaveObjectCache,
|
||||||
getObjectValue,
|
getObjectValue,
|
||||||
|
getWaveObjectAtom,
|
||||||
|
getWaveObjectLoadingAtom,
|
||||||
loadAndPinWaveObject,
|
loadAndPinWaveObject,
|
||||||
makeORef,
|
makeORef,
|
||||||
setObjectValue,
|
setObjectValue,
|
||||||
|
Loading…
Reference in New Issue
Block a user