MCPcopy Index your code
hub / github.com/TanStack/db / subscribeToQuery

Function subscribeToQuery

packages/query-db-collection/src/query.ts:1409–1426  ·  view source on GitHub ↗
(
      observer: QueryObserver<Array<any>, any, Array<any>, Array<any>, any>,
      hashedQueryKey: string,
    )

Source from the content-addressed store, hash-verified

1407 }
1408
1409 const subscribeToQuery = (
1410 observer: QueryObserver<Array<any>, any, Array<any>, Array<any>, any>,
1411 hashedQueryKey: string,
1412 ) => {
1413 if (!isSubscribed(hashedQueryKey)) {
1414 const cachedQueryKey = hashToQueryKey.get(hashedQueryKey)!
1415 const handleQueryResult = makeQueryResultHandler(cachedQueryKey)
1416 const unsubscribeFn = observer.subscribe(handleQueryResult)
1417 unsubscribes.set(hashedQueryKey, unsubscribeFn)
1418
1419 // Process the current result immediately if available
1420 // This ensures data is synced when resubscribing to a query with cached data
1421 const currentResult = observer.getCurrentResult()
1422 if (currentResult.isSuccess || currentResult.isError) {
1423 handleQueryResult(currentResult)
1424 }
1425 }
1426 }
1427
1428 const subscribeToQueries = () => {
1429 state.observers.forEach(subscribeToQuery)

Callers 1

createQueryFromOptsFunction · 0.85

Calls 6

isSubscribedFunction · 0.85
makeQueryResultHandlerFunction · 0.85
handleQueryResultFunction · 0.85
getMethod · 0.45
subscribeMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected