@tanstack/query-core 5.0.0-alpha.19 → 5.0.0-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-core",
3
- "version": "5.0.0-alpha.19",
3
+ "version": "5.0.0-alpha.21",
4
4
  "description": "The framework agnostic core that powers TanStack Query",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -134,28 +134,28 @@ export class QueriesObserver extends Subscribable<QueriesObserverListener> {
134
134
  queries: QueryObserverOptions[],
135
135
  ): QueryObserverMatch[] {
136
136
  const prevObservers = this.#observers
137
+ const prevObserversMap = new Map(
138
+ prevObservers.map((observer) => [observer.options.queryHash, observer]),
139
+ )
140
+
137
141
  const defaultedQueryOptions = queries.map((options) =>
138
142
  this.#client.defaultQueryOptions(options),
139
143
  )
140
144
 
141
145
  const matchingObservers: QueryObserverMatch[] =
142
146
  defaultedQueryOptions.flatMap((defaultedOptions) => {
143
- const match = prevObservers.find(
144
- (observer) =>
145
- observer.options.queryHash === defaultedOptions.queryHash,
146
- )
147
+ const match = prevObserversMap.get(defaultedOptions.queryHash)
147
148
  if (match != null) {
148
149
  return [{ defaultedQueryOptions: defaultedOptions, observer: match }]
149
150
  }
150
151
  return []
151
152
  })
152
153
 
153
- const matchedQueryHashes = matchingObservers.map(
154
- (match) => match.defaultedQueryOptions.queryHash,
154
+ const matchedQueryHashes = new Set(
155
+ matchingObservers.map((match) => match.defaultedQueryOptions.queryHash),
155
156
  )
156
157
  const unmatchedQueries = defaultedQueryOptions.filter(
157
- (defaultedOptions) =>
158
- !matchedQueryHashes.includes(defaultedOptions.queryHash),
158
+ (defaultedOptions) => !matchedQueryHashes.has(defaultedOptions.queryHash),
159
159
  )
160
160
 
161
161
  const getObserver = (options: QueryObserverOptions): QueryObserver => {
package/src/query.ts CHANGED
@@ -588,7 +588,7 @@ export class Query<
588
588
 
589
589
  notifyManager.batch(() => {
590
590
  this.#observers.forEach((observer) => {
591
- observer.onQueryUpdate(action)
591
+ observer.onQueryUpdate()
592
592
  })
593
593
 
594
594
  this.#cache.notify({ query: this, type: 'updated', action })
@@ -17,11 +17,11 @@ import type {
17
17
  QueryOptions,
18
18
  RefetchOptions,
19
19
  } from './types'
20
- import type { Query, QueryState, Action, FetchOptions } from './query'
20
+ import type { Query, QueryState, FetchOptions } from './query'
21
21
  import type { QueryClient } from './queryClient'
22
22
  import { focusManager } from './focusManager'
23
23
  import { Subscribable } from './subscribable'
24
- import { canFetch, isCancelledError } from './retryer'
24
+ import { canFetch } from './retryer'
25
25
 
26
26
  type QueryObserverListener<TData, TError> = (
27
27
  result: QueryObserverResult<TData, TError>,
@@ -29,8 +29,6 @@ type QueryObserverListener<TData, TError> = (
29
29
 
30
30
  export interface NotifyOptions {
31
31
  listeners?: boolean
32
- onError?: boolean
33
- onSuccess?: boolean
34
32
  }
35
33
 
36
34
  export interface ObserverFetchOptions extends FetchOptions {
@@ -632,16 +630,8 @@ export class QueryObserver<
632
630
  }
633
631
  }
634
632
 
635
- onQueryUpdate(action: Action<TData, TError>): void {
636
- const notifyOptions: NotifyOptions = {}
637
-
638
- if (action.type === 'success') {
639
- notifyOptions.onSuccess = !action.manual
640
- } else if (action.type === 'error' && !isCancelledError(action.error)) {
641
- notifyOptions.onError = true
642
- }
643
-
644
- this.#updateResult(notifyOptions)
633
+ onQueryUpdate(): void {
634
+ this.#updateResult()
645
635
 
646
636
  if (this.hasListeners()) {
647
637
  this.#updateTimers()
@@ -650,16 +640,7 @@ export class QueryObserver<
650
640
 
651
641
  #notify(notifyOptions: NotifyOptions): void {
652
642
  notifyManager.batch(() => {
653
- // First trigger the configuration callbacks
654
- if (notifyOptions.onSuccess) {
655
- this.options.onSuccess?.(this.#currentResult.data!)
656
- this.options.onSettled?.(this.#currentResult.data, null)
657
- } else if (notifyOptions.onError) {
658
- this.options.onError?.(this.#currentResult.error!)
659
- this.options.onSettled?.(undefined, this.#currentResult.error)
660
- }
661
-
662
- // Then trigger the listeners
643
+ // First, trigger the listeners
663
644
  if (notifyOptions.listeners) {
664
645
  this.listeners.forEach((listener) => {
665
646
  listener(this.#currentResult)
package/src/types.ts CHANGED
@@ -259,18 +259,6 @@ export interface QueryObserverOptions<
259
259
  * By default, access to properties will be tracked, and the component will only re-render when one of the tracked properties change.
260
260
  */
261
261
  notifyOnChangeProps?: Array<keyof InfiniteQueryObserverResult> | 'all'
262
- /**
263
- * This callback will fire any time the query successfully fetches new data.
264
- */
265
- onSuccess?: (data: TData) => void
266
- /**
267
- * This callback will fire if the query encounters an error and will be passed the error.
268
- */
269
- onError?: (err: TError) => void
270
- /**
271
- * This callback will fire any time the query is either successfully fetched or errors and be passed either the data or error.
272
- */
273
- onSettled?: (data: TData | undefined, error: TError | null) => void
274
262
  /**
275
263
  * Whether errors should be thrown instead of setting the `error` property.
276
264
  * If set to `true` or `suspense` is `true`, all errors will be thrown to the error boundary.