MCPcopy Create free account
hub / github.com/TanStack/query / run

Function run

packages/vue-query/src/useBaseQuery.ts:231–265  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

229 // noop
230 }
231 const run = () => {
232 // Apply the latest options before resolving `enabled`, so a query callback sees the current query.
233 // fix #6133
234 observer.setOptions(defaultedOptions.value)
235 const { enabled } = defaultedOptions.value
236 if (
237 (typeof enabled === 'function'
238 ? enabled(observer.getCurrentQuery())
239 : enabled) !== false
240 ) {
241 const optimisticResult = observer.getOptimisticResult(
242 defaultedOptions.value,
243 )
244 if (optimisticResult.isStale) {
245 stopWatch()
246 observer
247 .fetchOptimistic(defaultedOptions.value)
248 .then(resolve, (error: TError) => {
249 if (
250 shouldThrowError(defaultedOptions.value.throwOnError, [
251 error,
252 observer.getCurrentQuery(),
253 ])
254 ) {
255 reject(error)
256 } else {
257 resolve(observer.getCurrentResult())
258 }
259 })
260 } else {
261 stopWatch()
262 resolve(optimisticResult)
263 }
264 }
265 }
266
267 run()
268

Callers 1

suspenseFunction · 0.70

Calls 9

shouldThrowErrorFunction · 0.90
stopWatchFunction · 0.85
rejectFunction · 0.85
resolveFunction · 0.85
getCurrentQueryMethod · 0.80
fetchOptimisticMethod · 0.80
setOptionsMethod · 0.45
getOptimisticResultMethod · 0.45
getCurrentResultMethod · 0.45

Tested by

no test coverage detected