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

Function makeQueryNew

packages/vue/src/query.ts:564–588  ·  view source on GitHub ↗
(_getRuntime: () => Context.Context<R>, getAtomRt: () => AtomClientRuntime)

Source from the content-addressed store, hash-verified

562 options?: (AtomQueryNewOptions<A, TData> | CustomUseQueryOptions<A, E, TData>) & {
563 readonly mode?: "optional"
564 }
565): QueryView<TData, E> => {
566 const atomRt = getAtomRt()
567 const registry = injectRegistry()
568 const [req, enabledRef] = optionValue<I>(arg, options)
569 const family = getQueryFamily(atomRt, q)
570 const atomRef = computed(() => enabledRef.value ? observedAtom(family(req.value), options) : disabledQueryAtom)
571 // useAtomValue returns Readonly<Ref>, not ComputedRef — re-wrap before withDataFallback / QueryView.
572 const rawAtomResult = useAtomValue(() => atomRef.value)
573 const rawResult = computed(() => rawAtomResult.value)
574 // `initialData` / `placeholderData` display fallback (old `.query()` API). Applied only while the
575 // result is still Initial; Failures/Success pass through unmasked. Neither is written to cache
576 // (the base atom stays Initial, so the mount-staleness check still triggers the real fetch). The
577 // fallback runs PRE-select, matching TanStack (`initialData`/`placeholderData` are TQueryData).
578 const fallbackResult = withDataFallback(rawResult, options)
579 const select = options?.select
580 const result = (select
581 ? computed(() => AsyncResult.map(fallbackResult.value, select))
582 : fallbackResult) as ComputedRef<AsyncResult.AsyncResult<TData, E>>
583 const refresh = () => registry.refresh(atomRef.value)
584 const awaitResult = () =>
585 select
586 ? awaitAtomResult(registry, atomRef.value).pipe(Effect.map(select))
587 : awaitAtomResult(registry, atomRef.value)
588 const refetch = () =>
589 Effect.gen(function*() {
590 yield* refreshAtomWithCurrentSpan(registry, atomRef.value)
591 return yield* awaitResult()

Callers 1

constructorMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…