Skip to content
0

katanakit-js / QueriesObserver

Class: QueriesObserver<TCombinedResult> ​

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/queriesObserver.d.ts:36

A QueriesObserver watches an array of queries at once, exposing them as a single array of QueryObserverResults (or, when a combine option is given, as a combined value derived from that array). It manages one internal QueryObserver per query, and is the primitive that framework adapters (e.g. useQueries) build their hooks on top of.

Example ​

ts
const observer = new QueriesObserver(queryClient, [
  { queryKey: ['post', 1], queryFn: fetchPost },
  { queryKey: ['post', 2], queryFn: fetchPost },
])

const unsubscribe = observer.subscribe((result) => {
  console.log(result)
})

Extends ​

  • Subscribable<QueriesObserverListener>

Type Parameters ​

Type ParameterDefault type
TCombinedResultQueryObserverResult[]

Constructors ​

Constructor ​

ts
new QueriesObserver<TCombinedResult>(
   client, 
   queries, 
   options?
): QueriesObserver<TCombinedResult>;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/queriesObserver.d.ts:38

Parameters ​

ParameterType
clientQueryClient
queriesQueryObserverOptions<any, any, any, any, any, never>[]
options?QueriesObserverOptions<TCombinedResult>

Returns ​

QueriesObserver<TCombinedResult>

Overrides ​

ts
Subscribable<QueriesObserverListener>.constructor

Properties ​

PropertyModifierTypeInherited fromDefined in
listenersprotectedSet<QueriesObserverListener>Subscribable.listenersnode_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/subscribable-CysQ0tne.d.ts:8

Methods ​

destroy() ​

ts
destroy(): void;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/queriesObserver.d.ts:45

Stops observing all queries: clears all listeners and destroys every underlying QueryObserver this observer manages.

Returns ​

void


getCurrentResult() ​

ts
getCurrentResult(): QueryObserverResult[];

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/queriesObserver.d.ts:72

Returns the most recently computed array of QueryObserverResults, one per observed query, in the same order as the queries passed to the constructor or setQueries.

Returns ​

QueryObserverResult[]

Example ​

ts
const results = observer.getCurrentResult()
const data = results.map((result) => result.data)

getObservers() ​

ts
getObservers(): QueryObserver<unknown, Error, unknown, unknown, readonly unknown[]>[];

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/queriesObserver.d.ts:83

Returns the underlying QueryObserver instances this observer manages, in the same order as the queries passed to the constructor or setQueries.

Returns ​

QueryObserver<unknown, Error, unknown, unknown, readonly unknown[]>[]


getOptimisticResult() ​

ts
getOptimisticResult(queries, combine): [QueryObserverResult[], (r?) => TCombinedResult, () => QueryObserverResult[]];

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/queriesObserver.d.ts:91

The QueriesObserver counterpart of QueryObserver#getOptimisticResult — computes the result for the given (already-defaulted) queries right now, synchronously. Called by framework adapters (e.g. useQueries) ahead of subscribing, returning a tuple of the raw per-query results, a function to compute the combined result from them, and a function to wrap the results for property-access tracking.

Parameters ​

ParameterType
queriesQueryObserverOptions<unknown, Error, unknown, unknown, readonly unknown[], never>[]
combineCombineFn<TCombinedResult> | undefined

Returns ​

[QueryObserverResult[], (r?) => TCombinedResult, () => QueryObserverResult[]]


getQueries() ​

ts
getQueries(): Query<unknown, Error, unknown, readonly unknown[]>[];

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/queriesObserver.d.ts:77

Returns the underlying Query instances currently being observed, in the same order as the queries passed to the constructor or setQueries.

Returns ​

Query<unknown, Error, unknown, readonly unknown[]>[]


hasListeners() ​

ts
hasListeners(): boolean;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/subscribable-CysQ0tne.d.ts:28

Returns true while at least one listener is registered, false once they have all unsubscribed.

Returns ​

boolean

Inherited from ​

ts
Subscribable.hasListeners

onSubscribe() ​

ts
protected onSubscribe(): void;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/queriesObserver.d.ts:39

Returns ​

void

Overrides ​

ts
Subscribable.onSubscribe

onUnsubscribe() ​

ts
protected onUnsubscribe(): void;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/queriesObserver.d.ts:40

Returns ​

void

Overrides ​

ts
Subscribable.onUnsubscribe

setQueries() ​

ts
setQueries(queries, options?): void;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/queriesObserver.d.ts:60

Replaces the set of queries being observed. Existing QueryObservers are reused for queries that match an already-observed query hash; observers for queries that are no longer present are destroyed, and new observers are created and subscribed to for newly added queries.

Parameters ​

ParameterType
queriesQueryObserverOptions<unknown, Error, unknown, unknown, readonly unknown[], never>[]
options?QueriesObserverOptions<TCombinedResult>

Returns ​

void

Example ​

ts
observer.setQueries([
  { queryKey: ['post', 1], queryFn: fetchPost },
  { queryKey: ['post', 3], queryFn: fetchPost },
])

subscribe() ​

ts
subscribe(listener): () => void;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/subscribable-CysQ0tne.d.ts:24

Registers a listener to be called on every update this object notifies about. Returns a function that removes the listener again — call it to stop listening. The base class never drops a listener on its own, though some subclasses clear all of theirs in destroy().

Parameters ​

ParameterTypeDescription
listenerQueriesObserverListenerCalled on each update, with whatever the subclass passes to its subscribers.

Returns ​

() => void

Example ​

ts
const unsubscribe = subscribable.subscribe(() => {
  // react to the update
})

unsubscribe()

Inherited from ​

ts
Subscribable.subscribe

Released under the MIT License.