@tanstack/vue-query 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.
|
@@ -1024,7 +1024,7 @@
|
|
|
1024
1024
|
this.state = reducer(this.state);
|
|
1025
1025
|
notifyManager.batch(() => {
|
|
1026
1026
|
this.#observers.forEach(observer => {
|
|
1027
|
-
observer.onQueryUpdate(
|
|
1027
|
+
observer.onQueryUpdate();
|
|
1028
1028
|
});
|
|
1029
1029
|
this.#cache.notify({
|
|
1030
1030
|
query: this,
|
|
@@ -2220,30 +2220,15 @@
|
|
|
2220
2220
|
query.addObserver(this);
|
|
2221
2221
|
}
|
|
2222
2222
|
}
|
|
2223
|
-
onQueryUpdate(
|
|
2224
|
-
|
|
2225
|
-
if (action.type === 'success') {
|
|
2226
|
-
notifyOptions.onSuccess = !action.manual;
|
|
2227
|
-
} else if (action.type === 'error' && !isCancelledError(action.error)) {
|
|
2228
|
-
notifyOptions.onError = true;
|
|
2229
|
-
}
|
|
2230
|
-
this.#updateResult(notifyOptions);
|
|
2223
|
+
onQueryUpdate() {
|
|
2224
|
+
this.#updateResult();
|
|
2231
2225
|
if (this.hasListeners()) {
|
|
2232
2226
|
this.#updateTimers();
|
|
2233
2227
|
}
|
|
2234
2228
|
}
|
|
2235
2229
|
#notify(notifyOptions) {
|
|
2236
2230
|
notifyManager.batch(() => {
|
|
2237
|
-
// First trigger the
|
|
2238
|
-
if (notifyOptions.onSuccess) {
|
|
2239
|
-
this.options.onSuccess?.(this.#currentResult.data);
|
|
2240
|
-
this.options.onSettled?.(this.#currentResult.data, null);
|
|
2241
|
-
} else if (notifyOptions.onError) {
|
|
2242
|
-
this.options.onError?.(this.#currentResult.error);
|
|
2243
|
-
this.options.onSettled?.(undefined, this.#currentResult.error);
|
|
2244
|
-
}
|
|
2245
|
-
|
|
2246
|
-
// Then trigger the listeners
|
|
2231
|
+
// First, trigger the listeners
|
|
2247
2232
|
if (notifyOptions.listeners) {
|
|
2248
2233
|
this.listeners.forEach(listener => {
|
|
2249
2234
|
listener(this.#currentResult);
|
|
@@ -2365,9 +2350,10 @@
|
|
|
2365
2350
|
}
|
|
2366
2351
|
#findMatchingObservers(queries) {
|
|
2367
2352
|
const prevObservers = this.#observers;
|
|
2353
|
+
const prevObserversMap = new Map(prevObservers.map(observer => [observer.options.queryHash, observer]));
|
|
2368
2354
|
const defaultedQueryOptions = queries.map(options => this.#client.defaultQueryOptions(options));
|
|
2369
2355
|
const matchingObservers = defaultedQueryOptions.flatMap(defaultedOptions => {
|
|
2370
|
-
const match =
|
|
2356
|
+
const match = prevObserversMap.get(defaultedOptions.queryHash);
|
|
2371
2357
|
if (match != null) {
|
|
2372
2358
|
return [{
|
|
2373
2359
|
defaultedQueryOptions: defaultedOptions,
|
|
@@ -2376,8 +2362,8 @@
|
|
|
2376
2362
|
}
|
|
2377
2363
|
return [];
|
|
2378
2364
|
});
|
|
2379
|
-
const matchedQueryHashes = matchingObservers.map(match => match.defaultedQueryOptions.queryHash);
|
|
2380
|
-
const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.
|
|
2365
|
+
const matchedQueryHashes = new Set(matchingObservers.map(match => match.defaultedQueryOptions.queryHash));
|
|
2366
|
+
const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.has(defaultedOptions.queryHash));
|
|
2381
2367
|
const getObserver = options => {
|
|
2382
2368
|
const defaultedOptions = this.#client.defaultQueryOptions(options);
|
|
2383
2369
|
const currentObserver = this.#observers.find(o => o.options.queryHash === defaultedOptions.queryHash);
|