@tanstack/react-query 5.0.0-alpha.1 → 5.0.0-alpha.3
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/types.d.ts +14 -14
- package/build/lib/useInfiniteQuery.d.ts +2 -2
- package/build/lib/useInfiniteQuery.esm.js.map +1 -1
- package/build/lib/useInfiniteQuery.js.map +1 -1
- package/build/lib/useInfiniteQuery.mjs.map +1 -1
- package/build/lib/useMutation.d.ts +2 -2
- package/build/lib/useMutation.esm.js.map +1 -1
- package/build/lib/useMutation.js.map +1 -1
- package/build/lib/useMutation.mjs.map +1 -1
- package/build/lib/useMutationState.d.ts +2 -2
- package/build/lib/useMutationState.esm.js.map +1 -1
- package/build/lib/useMutationState.js.map +1 -1
- package/build/lib/useMutationState.mjs.map +1 -1
- package/build/lib/useQueries.d.ts +3 -3
- package/build/lib/useQueries.esm.js.map +1 -1
- package/build/lib/useQueries.js.map +1 -1
- package/build/lib/useQueries.mjs.map +1 -1
- package/build/lib/useQuery.d.ts +5 -5
- package/build/lib/useQuery.esm.js.map +1 -1
- package/build/lib/useQuery.js.map +1 -1
- package/build/lib/useQuery.mjs.map +1 -1
- package/build/umd/index.development.js +21 -7
- 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 +2 -2
- package/src/types.ts +14 -14
- package/src/useInfiniteQuery.ts +2 -2
- package/src/useMutation.ts +2 -2
- package/src/useMutationState.ts +3 -3
- package/src/useQueries.ts +3 -3
- package/src/useQuery.ts +6 -10
|
@@ -908,6 +908,7 @@
|
|
|
908
908
|
if (!isCancelledError(error)) {
|
|
909
909
|
// Notify cache callback
|
|
910
910
|
this.#cache.config.onError?.(error, this);
|
|
911
|
+
this.#cache.config.onSettled?.(this.state.data, error, this);
|
|
911
912
|
}
|
|
912
913
|
if (!this.isFetchingOptimistic) {
|
|
913
914
|
// Schedule query gc after fetching
|
|
@@ -932,6 +933,7 @@
|
|
|
932
933
|
|
|
933
934
|
// Notify cache callback
|
|
934
935
|
this.#cache.config.onSuccess?.(data, this);
|
|
936
|
+
this.#cache.config.onSettled?.(data, this.state.error, this);
|
|
935
937
|
if (!this.isFetchingOptimistic) {
|
|
936
938
|
// Schedule query gc after fetching
|
|
937
939
|
this.scheduleGc();
|
|
@@ -1171,18 +1173,26 @@
|
|
|
1171
1173
|
|
|
1172
1174
|
class Mutation extends Removable {
|
|
1173
1175
|
#observers;
|
|
1176
|
+
#defaultOptions;
|
|
1174
1177
|
#mutationCache;
|
|
1175
1178
|
#retryer;
|
|
1176
1179
|
constructor(config) {
|
|
1177
1180
|
super();
|
|
1178
|
-
this.options = config.options;
|
|
1179
1181
|
this.mutationId = config.mutationId;
|
|
1182
|
+
this.#defaultOptions = config.defaultOptions;
|
|
1180
1183
|
this.#mutationCache = config.mutationCache;
|
|
1181
1184
|
this.#observers = [];
|
|
1182
1185
|
this.state = config.state || getDefaultState();
|
|
1183
|
-
this.
|
|
1186
|
+
this.setOptions(config.options);
|
|
1184
1187
|
this.scheduleGc();
|
|
1185
1188
|
}
|
|
1189
|
+
setOptions(options) {
|
|
1190
|
+
this.options = {
|
|
1191
|
+
...this.#defaultOptions,
|
|
1192
|
+
...options
|
|
1193
|
+
};
|
|
1194
|
+
this.updateGcTime(this.options.gcTime);
|
|
1195
|
+
}
|
|
1186
1196
|
get meta() {
|
|
1187
1197
|
return this.options.meta;
|
|
1188
1198
|
}
|
|
@@ -1277,6 +1287,9 @@
|
|
|
1277
1287
|
// Notify cache callback
|
|
1278
1288
|
await this.#mutationCache.config.onSuccess?.(data, variables, this.state.context, this);
|
|
1279
1289
|
await this.options.onSuccess?.(data, variables, this.state.context);
|
|
1290
|
+
|
|
1291
|
+
// Notify cache callback
|
|
1292
|
+
await this.#mutationCache.config.onSettled?.(data, null, this.state.variables, this.state.context, this);
|
|
1280
1293
|
await this.options.onSettled?.(data, null, variables, this.state.context);
|
|
1281
1294
|
this.#dispatch({
|
|
1282
1295
|
type: 'success',
|
|
@@ -1288,6 +1301,9 @@
|
|
|
1288
1301
|
// Notify cache callback
|
|
1289
1302
|
await this.#mutationCache.config.onError?.(error, variables, this.state.context, this);
|
|
1290
1303
|
await this.options.onError?.(error, variables, this.state.context);
|
|
1304
|
+
|
|
1305
|
+
// Notify cache callback
|
|
1306
|
+
await this.#mutationCache.config.onSettled?.(undefined, error, this.state.variables, this.state.context, this);
|
|
1291
1307
|
await this.options.onSettled?.(undefined, error, variables, this.state.context);
|
|
1292
1308
|
throw error;
|
|
1293
1309
|
} finally {
|
|
@@ -2285,14 +2301,12 @@
|
|
|
2285
2301
|
#result;
|
|
2286
2302
|
#queries;
|
|
2287
2303
|
#observers;
|
|
2288
|
-
#observersMap;
|
|
2289
2304
|
constructor(client, queries) {
|
|
2290
2305
|
super();
|
|
2291
2306
|
this.#client = client;
|
|
2292
2307
|
this.#queries = [];
|
|
2293
2308
|
this.#result = [];
|
|
2294
2309
|
this.#observers = [];
|
|
2295
|
-
this.#observersMap = {};
|
|
2296
2310
|
if (queries) {
|
|
2297
2311
|
this.setQueries(queries);
|
|
2298
2312
|
}
|
|
@@ -2326,14 +2340,12 @@
|
|
|
2326
2340
|
// set options for the new observers to notify of changes
|
|
2327
2341
|
newObserverMatches.forEach(match => match.observer.setOptions(match.defaultedQueryOptions, notifyOptions));
|
|
2328
2342
|
const newObservers = newObserverMatches.map(match => match.observer);
|
|
2329
|
-
const newObserversMap = Object.fromEntries(newObservers.map(observer => [observer.options.queryHash, observer]));
|
|
2330
2343
|
const newResult = newObservers.map(observer => observer.getCurrentResult());
|
|
2331
2344
|
const hasIndexChange = newObservers.some((observer, index) => observer !== prevObservers[index]);
|
|
2332
2345
|
if (prevObservers.length === newObservers.length && !hasIndexChange) {
|
|
2333
2346
|
return;
|
|
2334
2347
|
}
|
|
2335
2348
|
this.#observers = newObservers;
|
|
2336
|
-
this.#observersMap = newObserversMap;
|
|
2337
2349
|
this.#result = newResult;
|
|
2338
2350
|
if (!this.hasListeners()) {
|
|
2339
2351
|
return;
|
|
@@ -2378,7 +2390,7 @@
|
|
|
2378
2390
|
const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.includes(defaultedOptions.queryHash));
|
|
2379
2391
|
const getObserver = options => {
|
|
2380
2392
|
const defaultedOptions = this.#client.defaultQueryOptions(options);
|
|
2381
|
-
const currentObserver = this.#
|
|
2393
|
+
const currentObserver = this.#observers.find(o => o.options.queryHash === defaultedOptions.queryHash);
|
|
2382
2394
|
return currentObserver ?? new QueryObserver(this.#client, defaultedOptions);
|
|
2383
2395
|
};
|
|
2384
2396
|
const newOrReusedObservers = unmatchedQueries.map(options => {
|
|
@@ -2508,6 +2520,7 @@
|
|
|
2508
2520
|
observer: this
|
|
2509
2521
|
});
|
|
2510
2522
|
}
|
|
2523
|
+
this.#currentMutation?.setOptions(this.options);
|
|
2511
2524
|
}
|
|
2512
2525
|
onUnsubscribe() {
|
|
2513
2526
|
if (!this.listeners.length) {
|
|
@@ -3008,6 +3021,7 @@
|
|
|
3008
3021
|
exports.isCancelledError = isCancelledError;
|
|
3009
3022
|
exports.isServer = isServer;
|
|
3010
3023
|
exports.keepPreviousData = keepPreviousData;
|
|
3024
|
+
exports.matchQuery = matchQuery;
|
|
3011
3025
|
exports.notifyManager = notifyManager;
|
|
3012
3026
|
exports.onlineManager = onlineManager;
|
|
3013
3027
|
exports.replaceEqualDeep = replaceEqualDeep;
|