MCPcopy
hub / github.com/TanStack/query / subscribeToObserver

Function subscribeToObserver

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

Source from the content-addressed store, hash-verified

269
270 let taskQueue: Array<() => void> = []
271 const subscribeToObserver = () =>
272 observer.subscribe((result) => {
273 taskQueue.push(() => {
274 batch(() => {
275 const dataResources_ = dataResources()
276 for (let index = 0; index < dataResources_.length; index++) {
277 const dataResource = dataResources_[index]!
278 const unwrappedResult = { ...unwrap(result[index]) }
279 // @ts-expect-error typescript pedantry regarding the possible range of index
280 setState(index, unwrap(unwrappedResult))
281 dataResource[1].mutate(() => unwrap(state[index]!.data))
282 dataResource[1].refetch()
283 }
284 })
285 })
286
287 queueMicrotask(() => {
288 const taskToRun = taskQueue.pop()
289 if (taskToRun) taskToRun()
290 taskQueue = []
291 })
292 })
293
294 let unsubscribe: () => void = noop
295 createComputed<() => void>((cleanup) => {

Callers 1

useQueriesFunction · 0.85

Calls 3

refetchMethod · 0.80
subscribeMethod · 0.45
mutateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…