@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/build/lib/queriesObserver.esm.js +4 -3
- package/build/lib/queriesObserver.esm.js.map +1 -1
- package/build/lib/queriesObserver.js +4 -3
- package/build/lib/queriesObserver.js.map +1 -1
- package/build/lib/queriesObserver.mjs +4 -3
- package/build/lib/queriesObserver.mjs.map +1 -1
- package/build/lib/query.esm.js +1 -1
- package/build/lib/query.esm.js.map +1 -1
- package/build/lib/query.js +1 -1
- package/build/lib/query.js.map +1 -1
- package/build/lib/query.mjs +1 -1
- package/build/lib/query.mjs.map +1 -1
- package/build/lib/queryObserver.d.ts +2 -4
- package/build/lib/queryObserver.esm.js +4 -21
- package/build/lib/queryObserver.esm.js.map +1 -1
- package/build/lib/queryObserver.js +3 -20
- package/build/lib/queryObserver.js.map +1 -1
- package/build/lib/queryObserver.mjs +4 -19
- package/build/lib/queryObserver.mjs.map +1 -1
- package/build/lib/types.d.ts +0 -12
- package/build/umd/index.development.js +8 -22
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/queriesObserver.ts +8 -8
- package/src/query.ts +1 -1
- package/src/queryObserver.ts +5 -24
- package/src/types.ts +0 -12
package/package.json
CHANGED
package/src/queriesObserver.ts
CHANGED
|
@@ -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 =
|
|
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 =
|
|
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
package/src/queryObserver.ts
CHANGED
|
@@ -17,11 +17,11 @@ import type {
|
|
|
17
17
|
QueryOptions,
|
|
18
18
|
RefetchOptions,
|
|
19
19
|
} from './types'
|
|
20
|
-
import type { Query, QueryState,
|
|
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
|
|
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(
|
|
636
|
-
|
|
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
|
|
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.
|