MCPcopy Create free account
hub / github.com/effect-app/libs / useAtomQuery

Function useAtomQuery

packages/vue/src/query.ts:287–312  ·  view source on GitHub ↗
(
  atom: () => Atom.Atom<AsyncResult.AsyncResult<A, E>>
)

Source from the content-addressed store, hash-verified

285export const withDataFallback = <A, E>(
286 // Structural read so both Ref and Readonly<Ref> from useAtomValue are accepted.
287 rawResult: { readonly value: AsyncResult.AsyncResult<A, E> },
288 options?: unknown
289): ComputedRef<AsyncResult.AsyncResult<A, E>> => {
290 const opts = options as
291 | { readonly initialData?: A | (() => A); readonly placeholderData?: A | ((prev: A | undefined) => A) }
292 | undefined
293 const initialData = opts?.initialData
294 const placeholderData = opts?.placeholderData
295 if (initialData === undefined && placeholderData === undefined) {
296 // Identity when no fallback options. Callers that need a real ComputedRef
297 // (e.g. useAtomValue's Readonly<Ref>) wrap before calling this helper.
298 return rawResult as ComputedRef<AsyncResult.AsyncResult<A, E>>
299 }
300
301 let lastData: A | undefined
302 return computed(() => {
303 const r = rawResult.value
304 const concrete = AsyncResult.value(r)
305 if (Option.isSome(concrete)) {
306 lastData = concrete.value
307 }
308 // Fallback is pending-only. Failure (even without previousSuccess) and Success pass through.
309 if (!AsyncResult.isInitial(r)) {
310 return r
311 }
312 if (initialData !== undefined) {
313 const v = typeof initialData === "function" ? (initialData as () => A)() : initialData
314 return AsyncResult.success(v, { waiting: r.waiting })
315 }

Callers 4

makeClient.test.tsFile · 0.85
setupFunction · 0.85
setupFunction · 0.85
useAtomSuspenseFunction · 0.85

Calls 4

injectRegistryFunction · 0.85
computedFunction · 0.85
valueMethod · 0.65
useAtomValueFunction · 0.50

Tested by 2

setupFunction · 0.68
setupFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…