MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / createWaveValueObject

Function createWaveValueObject

frontend/app/store/wos.ts:164–191  ·  view source on GitHub ↗
(oref: string, shouldFetch: boolean)

Source from the content-addressed store, hash-verified

162}
163
164function createWaveValueObject<T extends WaveObj>(oref: string, shouldFetch: boolean): WaveObjectValue<T> {
165 const wov = { pendingPromise: null, dataAtom: null };
166 wov.dataAtom = atom({ value: null, loading: true });
167 if (!shouldFetch) {
168 return wov;
169 }
170 const startTs = Date.now();
171 const localPromise = GetObject<T>(oref);
172 wov.pendingPromise = localPromise;
173 localPromise.then((val) => {
174 if (wov.pendingPromise != localPromise) {
175 return;
176 }
177 const [otype, oid] = splitORef(oref);
178 if (val != null) {
179 if (val["otype"] != otype) {
180 throw new Error("GetObject returned wrong type");
181 }
182 if (val["oid"] != oid) {
183 throw new Error("GetObject returned wrong id");
184 }
185 }
186 wov.pendingPromise = null;
187 globalStore.set(wov.dataAtom, { value: val, loading: false });
188 console.log("WaveObj resolved", oref, Date.now() - startTs + "ms");
189 });
190 return wov;
191}
192
193function getWaveObjectValue<T extends WaveObj>(oref: string, createIfMissing = true): WaveObjectValue<T> {
194 let wov = waveObjectValueCache.get(oref);

Callers 1

getWaveObjectValueFunction · 0.85

Calls 3

GetObjectFunction · 0.85
splitORefFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected