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

Function subscribeToObserver

packages/solid-query/src/useQueries.ts:357–378  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

355
356 let taskQueue: Array<() => void> = []
357 const subscribeToObserver = () =>
358 observer.subscribe((result) => {
359 taskQueue.push(() => {
360 batch(() => {
361 const dataResources_ = dataResources()
362 for (let index = 0; index < dataResources_.length; index++) {
363 const dataResource = dataResources_[index]!
364 const unwrappedResult = { ...unwrap(result[index]) }
365 // @ts-expect-error typescript pedantry regarding the possible range of index
366 setState(index, unwrap(unwrappedResult))
367 dataResource[1].mutate(() => unwrap(state[index]!.data))
368 dataResource[1].refetch()
369 }
370 })
371 })
372
373 queueMicrotask(() => {
374 const taskToRun = taskQueue.pop()
375 if (taskToRun) taskToRun()
376 taskQueue = []
377 })
378 })
379
380 let unsubscribe: () => void = noop
381 createComputed<() => void>((cleanup) => {

Callers 1

useQueriesFunction · 0.85

Calls 4

unwrapFunction · 0.85
refetchMethod · 0.80
subscribeMethod · 0.45
mutateMethod · 0.45

Tested by

no test coverage detected