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

Function swrToQuery

packages/vue/src/internal/tanstackQuery.ts:24–43  ·  view source on GitHub ↗
(r: {
  readonly error: CauseException<E> | null | undefined
  readonly data: A | undefined
  readonly isValidating: boolean
})

Source from the content-addressed store, hash-verified

22import { makeRunPromise } from "../runtime.ts"
23
24const swrToQuery = <E, A>(r: {
25 readonly error: CauseException<E> | null | undefined
26 readonly data: A | undefined
27 readonly isValidating: boolean
28}): AsyncResult.AsyncResult<A, E> => {
29 if (r.error !== undefined && r.error !== null) {
30 return AsyncResult.failureWithPrevious(
31 r.error.originalCause,
32 {
33 previous: r.data === undefined ? Option.none() : Option.some(AsyncResult.success(r.data)),
34 waiting: r.isValidating
35 }
36 )
37 }
38 if (r.data !== undefined) {
39 return AsyncResult.success<A, E>(r.data, { waiting: r.isValidating })
40 }
41
42 return AsyncResult.initial(r.isValidating)
43}
44
45const recoverCauseException = <A, E>(error: unknown): Effect.Effect<A, E> =>
46 error instanceof CauseException

Callers 1

useQueryFunction · 0.85

Calls 2

someMethod · 0.80
initialMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…