@tanstack/vue-query 5.0.0-alpha.1 → 5.0.0-alpha.10
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/__mocks__/useBaseQuery.d.ts +1 -2
- package/build/lib/__mocks__/useQueryClient.d.ts +1 -2
- package/build/lib/devtools/devtools.esm.js +50 -9
- package/build/lib/devtools/devtools.esm.js.map +1 -1
- package/build/lib/devtools/devtools.js +50 -9
- package/build/lib/devtools/devtools.js.map +1 -1
- package/build/lib/devtools/devtools.mjs +46 -7
- package/build/lib/devtools/devtools.mjs.map +1 -1
- package/build/lib/devtools/utils.esm.js +0 -1
- package/build/lib/devtools/utils.esm.js.map +1 -1
- package/build/lib/devtools/utils.js +0 -1
- package/build/lib/devtools/utils.js.map +1 -1
- package/build/lib/devtools/utils.mjs +0 -1
- package/build/lib/devtools/utils.mjs.map +1 -1
- package/build/lib/index.d.ts +2 -2
- package/build/lib/index.esm.js +1 -1
- package/build/lib/index.js +3 -2
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +1 -1
- package/build/lib/mutationCache.d.ts +2 -2
- package/build/lib/mutationCache.esm.js.map +1 -1
- package/build/lib/mutationCache.js.map +1 -1
- package/build/lib/mutationCache.mjs.map +1 -1
- package/build/lib/queryCache.d.ts +2 -2
- package/build/lib/queryCache.esm.js.map +1 -1
- package/build/lib/queryCache.js.map +1 -1
- package/build/lib/queryCache.mjs.map +1 -1
- package/build/lib/queryClient.d.ts +6 -6
- package/build/lib/queryClient.esm.js +1 -1
- package/build/lib/queryClient.esm.js.map +1 -1
- package/build/lib/queryClient.js +1 -1
- package/build/lib/queryClient.js.map +1 -1
- package/build/lib/queryClient.mjs.map +1 -1
- package/build/lib/useBaseQuery.esm.js.map +1 -1
- package/build/lib/useBaseQuery.js.map +1 -1
- package/build/lib/useBaseQuery.mjs.map +1 -1
- package/build/lib/useInfiniteQuery.d.ts +3 -3
- 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 +4 -4
- 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 +12 -0
- package/build/lib/useMutationState.esm.js +33 -0
- package/build/lib/useMutationState.esm.js.map +1 -0
- package/build/lib/useMutationState.js +36 -0
- package/build/lib/useMutationState.js.map +1 -0
- package/build/lib/useMutationState.mjs +33 -0
- package/build/lib/useMutationState.mjs.map +1 -0
- package/build/lib/useQueries.d.ts +2 -3
- package/build/lib/useQueries.esm.js +4 -5
- package/build/lib/useQueries.esm.js.map +1 -1
- package/build/lib/useQueries.js +4 -5
- package/build/lib/useQueries.js.map +1 -1
- package/build/lib/useQueries.mjs +4 -5
- package/build/lib/useQueries.mjs.map +1 -1
- package/build/lib/useQuery.d.ts +4 -4
- 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/lib/useQueryClient.esm.js +2 -1
- package/build/lib/useQueryClient.esm.js.map +1 -1
- package/build/lib/useQueryClient.js +2 -1
- package/build/lib/useQueryClient.js.map +1 -1
- package/build/lib/vueQueryPlugin.esm.js +0 -2
- package/build/lib/vueQueryPlugin.esm.js.map +1 -1
- package/build/lib/vueQueryPlugin.js +0 -2
- package/build/lib/vueQueryPlugin.js.map +1 -1
- package/build/lib/vueQueryPlugin.mjs +0 -2
- package/build/lib/vueQueryPlugin.mjs.map +1 -1
- package/build/umd/index.development.js +143 -84
- 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 +6 -6
- package/build/lib/useIsMutating.d.ts +0 -6
- package/build/lib/useIsMutating.esm.js +0 -24
- package/build/lib/useIsMutating.esm.js.map +0 -1
- package/build/lib/useIsMutating.js +0 -26
- package/build/lib/useIsMutating.js.map +0 -1
- package/build/lib/useIsMutating.mjs +0 -24
- package/build/lib/useIsMutating.mjs.map +0 -1
|
@@ -889,6 +889,7 @@
|
|
|
889
889
|
if (!isCancelledError(error)) {
|
|
890
890
|
// Notify cache callback
|
|
891
891
|
this.#cache.config.onError?.(error, this);
|
|
892
|
+
this.#cache.config.onSettled?.(this.state.data, error, this);
|
|
892
893
|
}
|
|
893
894
|
if (!this.isFetchingOptimistic) {
|
|
894
895
|
// Schedule query gc after fetching
|
|
@@ -913,6 +914,7 @@
|
|
|
913
914
|
|
|
914
915
|
// Notify cache callback
|
|
915
916
|
this.#cache.config.onSuccess?.(data, this);
|
|
917
|
+
this.#cache.config.onSettled?.(data, this.state.error, this);
|
|
916
918
|
if (!this.isFetchingOptimistic) {
|
|
917
919
|
// Schedule query gc after fetching
|
|
918
920
|
this.scheduleGc();
|
|
@@ -1152,18 +1154,26 @@
|
|
|
1152
1154
|
|
|
1153
1155
|
class Mutation extends Removable {
|
|
1154
1156
|
#observers;
|
|
1157
|
+
#defaultOptions;
|
|
1155
1158
|
#mutationCache;
|
|
1156
1159
|
#retryer;
|
|
1157
1160
|
constructor(config) {
|
|
1158
1161
|
super();
|
|
1159
|
-
this.options = config.options;
|
|
1160
1162
|
this.mutationId = config.mutationId;
|
|
1163
|
+
this.#defaultOptions = config.defaultOptions;
|
|
1161
1164
|
this.#mutationCache = config.mutationCache;
|
|
1162
1165
|
this.#observers = [];
|
|
1163
1166
|
this.state = config.state || getDefaultState();
|
|
1164
|
-
this.
|
|
1167
|
+
this.setOptions(config.options);
|
|
1165
1168
|
this.scheduleGc();
|
|
1166
1169
|
}
|
|
1170
|
+
setOptions(options) {
|
|
1171
|
+
this.options = {
|
|
1172
|
+
...this.#defaultOptions,
|
|
1173
|
+
...options
|
|
1174
|
+
};
|
|
1175
|
+
this.updateGcTime(this.options.gcTime);
|
|
1176
|
+
}
|
|
1167
1177
|
get meta() {
|
|
1168
1178
|
return this.options.meta;
|
|
1169
1179
|
}
|
|
@@ -1258,6 +1268,9 @@
|
|
|
1258
1268
|
// Notify cache callback
|
|
1259
1269
|
await this.#mutationCache.config.onSuccess?.(data, variables, this.state.context, this);
|
|
1260
1270
|
await this.options.onSuccess?.(data, variables, this.state.context);
|
|
1271
|
+
|
|
1272
|
+
// Notify cache callback
|
|
1273
|
+
await this.#mutationCache.config.onSettled?.(data, null, this.state.variables, this.state.context, this);
|
|
1261
1274
|
await this.options.onSettled?.(data, null, variables, this.state.context);
|
|
1262
1275
|
this.#dispatch({
|
|
1263
1276
|
type: 'success',
|
|
@@ -1269,6 +1282,9 @@
|
|
|
1269
1282
|
// Notify cache callback
|
|
1270
1283
|
await this.#mutationCache.config.onError?.(error, variables, this.state.context, this);
|
|
1271
1284
|
await this.options.onError?.(error, variables, this.state.context);
|
|
1285
|
+
|
|
1286
|
+
// Notify cache callback
|
|
1287
|
+
await this.#mutationCache.config.onSettled?.(undefined, error, this.state.variables, this.state.context, this);
|
|
1272
1288
|
await this.options.onSettled?.(undefined, error, variables, this.state.context);
|
|
1273
1289
|
throw error;
|
|
1274
1290
|
} finally {
|
|
@@ -1438,12 +1454,15 @@
|
|
|
1438
1454
|
function infiniteQueryBehavior() {
|
|
1439
1455
|
return {
|
|
1440
1456
|
onFetch: context => {
|
|
1441
|
-
context.fetchFn = () => {
|
|
1457
|
+
context.fetchFn = async () => {
|
|
1442
1458
|
const options = context.options;
|
|
1443
1459
|
const direction = context.fetchOptions?.meta?.fetchMore?.direction;
|
|
1444
1460
|
const oldPages = context.state.data?.pages || [];
|
|
1445
1461
|
const oldPageParams = context.state.data?.pageParams || [];
|
|
1446
|
-
|
|
1462
|
+
const empty = {
|
|
1463
|
+
pages: [],
|
|
1464
|
+
pageParams: []
|
|
1465
|
+
};
|
|
1447
1466
|
let cancelled = false;
|
|
1448
1467
|
const addSignalProperty = object => {
|
|
1449
1468
|
Object.defineProperty(object, 'signal', {
|
|
@@ -1463,95 +1482,95 @@
|
|
|
1463
1482
|
|
|
1464
1483
|
// Get query function
|
|
1465
1484
|
const queryFn = context.options.queryFn || (() => Promise.reject(new Error('Missing queryFn')));
|
|
1466
|
-
const buildNewPages = (pages, param, page, previous) => {
|
|
1467
|
-
const {
|
|
1468
|
-
maxPages
|
|
1469
|
-
} = context.options;
|
|
1470
|
-
if (previous) {
|
|
1471
|
-
newPageParams = addToStart(newPageParams, param, maxPages);
|
|
1472
|
-
return addToStart(pages, page, maxPages);
|
|
1473
|
-
}
|
|
1474
|
-
newPageParams = addToEnd(newPageParams, param, maxPages);
|
|
1475
|
-
return addToEnd(pages, page, maxPages);
|
|
1476
|
-
};
|
|
1477
1485
|
|
|
1478
1486
|
// Create function to fetch a page
|
|
1479
|
-
const fetchPage = (
|
|
1487
|
+
const fetchPage = async (data, param, previous) => {
|
|
1480
1488
|
if (cancelled) {
|
|
1481
1489
|
return Promise.reject();
|
|
1482
1490
|
}
|
|
1483
|
-
if (typeof param === 'undefined' && pages.length) {
|
|
1484
|
-
return Promise.resolve(
|
|
1491
|
+
if (typeof param === 'undefined' && data.pages.length) {
|
|
1492
|
+
return Promise.resolve(data);
|
|
1485
1493
|
}
|
|
1486
1494
|
const queryFnContext = {
|
|
1487
1495
|
queryKey: context.queryKey,
|
|
1488
1496
|
pageParam: param,
|
|
1497
|
+
direction: previous ? 'backward' : 'forward',
|
|
1489
1498
|
meta: context.options.meta
|
|
1490
1499
|
};
|
|
1491
1500
|
addSignalProperty(queryFnContext);
|
|
1492
|
-
const
|
|
1493
|
-
const
|
|
1494
|
-
|
|
1501
|
+
const page = await queryFn(queryFnContext);
|
|
1502
|
+
const {
|
|
1503
|
+
maxPages
|
|
1504
|
+
} = context.options;
|
|
1505
|
+
const addTo = previous ? addToStart : addToEnd;
|
|
1506
|
+
return {
|
|
1507
|
+
pages: addTo(data.pages, page, maxPages),
|
|
1508
|
+
pageParams: addTo(data.pageParams, param, maxPages)
|
|
1509
|
+
};
|
|
1495
1510
|
};
|
|
1496
|
-
let
|
|
1511
|
+
let result;
|
|
1497
1512
|
|
|
1498
1513
|
// Fetch first page?
|
|
1499
1514
|
if (!oldPages.length) {
|
|
1500
|
-
|
|
1515
|
+
result = await fetchPage(empty, options.defaultPageParam);
|
|
1501
1516
|
}
|
|
1502
1517
|
|
|
1503
1518
|
// fetch next / previous page?
|
|
1504
1519
|
else if (direction) {
|
|
1505
1520
|
const previous = direction === 'backward';
|
|
1506
|
-
const
|
|
1507
|
-
|
|
1521
|
+
const pageParamFn = previous ? getPreviousPageParam : getNextPageParam;
|
|
1522
|
+
const oldData = {
|
|
1523
|
+
pages: oldPages,
|
|
1524
|
+
pageParams: oldPageParams
|
|
1525
|
+
};
|
|
1526
|
+
const param = pageParamFn(options, oldData);
|
|
1527
|
+
result = await fetchPage(oldData, param, previous);
|
|
1508
1528
|
}
|
|
1509
1529
|
|
|
1510
1530
|
// Refetch pages
|
|
1511
1531
|
else {
|
|
1512
|
-
newPageParams = [];
|
|
1513
|
-
|
|
1514
1532
|
// Fetch first page
|
|
1515
|
-
|
|
1533
|
+
result = await fetchPage(empty, oldPageParams[0]);
|
|
1516
1534
|
|
|
1517
1535
|
// Fetch remaining pages
|
|
1518
1536
|
for (let i = 1; i < oldPages.length; i++) {
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
return fetchPage(pages, param);
|
|
1522
|
-
});
|
|
1537
|
+
const param = getNextPageParam(options, result);
|
|
1538
|
+
result = await fetchPage(result, param);
|
|
1523
1539
|
}
|
|
1524
1540
|
}
|
|
1525
|
-
|
|
1526
|
-
pages,
|
|
1527
|
-
pageParams: newPageParams
|
|
1528
|
-
}));
|
|
1529
|
-
return finalPromise;
|
|
1541
|
+
return result;
|
|
1530
1542
|
};
|
|
1531
1543
|
}
|
|
1532
1544
|
};
|
|
1533
1545
|
}
|
|
1534
|
-
function getNextPageParam(options,
|
|
1535
|
-
|
|
1546
|
+
function getNextPageParam(options, {
|
|
1547
|
+
pages,
|
|
1548
|
+
pageParams
|
|
1549
|
+
}) {
|
|
1550
|
+
const lastIndex = pages.length - 1;
|
|
1551
|
+
return options.getNextPageParam(pages[lastIndex], pages, pageParams[lastIndex], pageParams);
|
|
1536
1552
|
}
|
|
1537
|
-
function getPreviousPageParam(options,
|
|
1538
|
-
|
|
1553
|
+
function getPreviousPageParam(options, {
|
|
1554
|
+
pages,
|
|
1555
|
+
pageParams
|
|
1556
|
+
}) {
|
|
1557
|
+
return options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams);
|
|
1539
1558
|
}
|
|
1540
1559
|
|
|
1541
1560
|
/**
|
|
1542
1561
|
* Checks if there is a next page.
|
|
1543
1562
|
*/
|
|
1544
|
-
function hasNextPage(options,
|
|
1545
|
-
if (!
|
|
1546
|
-
return typeof getNextPageParam(options,
|
|
1563
|
+
function hasNextPage(options, data) {
|
|
1564
|
+
if (!data) return false;
|
|
1565
|
+
return typeof getNextPageParam(options, data) !== 'undefined';
|
|
1547
1566
|
}
|
|
1548
1567
|
|
|
1549
1568
|
/**
|
|
1550
1569
|
* Checks if there is a previous page.
|
|
1551
1570
|
*/
|
|
1552
|
-
function hasPreviousPage(options,
|
|
1553
|
-
if (!
|
|
1554
|
-
return typeof getPreviousPageParam(options,
|
|
1571
|
+
function hasPreviousPage(options, data) {
|
|
1572
|
+
if (!data || !options.getPreviousPageParam) return false;
|
|
1573
|
+
return typeof getPreviousPageParam(options, data) !== 'undefined';
|
|
1555
1574
|
}
|
|
1556
1575
|
|
|
1557
1576
|
// CLASS
|
|
@@ -2266,14 +2285,12 @@
|
|
|
2266
2285
|
#result;
|
|
2267
2286
|
#queries;
|
|
2268
2287
|
#observers;
|
|
2269
|
-
#observersMap;
|
|
2270
2288
|
constructor(client, queries) {
|
|
2271
2289
|
super();
|
|
2272
2290
|
this.#client = client;
|
|
2273
2291
|
this.#queries = [];
|
|
2274
2292
|
this.#result = [];
|
|
2275
2293
|
this.#observers = [];
|
|
2276
|
-
this.#observersMap = {};
|
|
2277
2294
|
if (queries) {
|
|
2278
2295
|
this.setQueries(queries);
|
|
2279
2296
|
}
|
|
@@ -2307,14 +2324,12 @@
|
|
|
2307
2324
|
// set options for the new observers to notify of changes
|
|
2308
2325
|
newObserverMatches.forEach(match => match.observer.setOptions(match.defaultedQueryOptions, notifyOptions));
|
|
2309
2326
|
const newObservers = newObserverMatches.map(match => match.observer);
|
|
2310
|
-
const newObserversMap = Object.fromEntries(newObservers.map(observer => [observer.options.queryHash, observer]));
|
|
2311
2327
|
const newResult = newObservers.map(observer => observer.getCurrentResult());
|
|
2312
2328
|
const hasIndexChange = newObservers.some((observer, index) => observer !== prevObservers[index]);
|
|
2313
2329
|
if (prevObservers.length === newObservers.length && !hasIndexChange) {
|
|
2314
2330
|
return;
|
|
2315
2331
|
}
|
|
2316
2332
|
this.#observers = newObservers;
|
|
2317
|
-
this.#observersMap = newObserversMap;
|
|
2318
2333
|
this.#result = newResult;
|
|
2319
2334
|
if (!this.hasListeners()) {
|
|
2320
2335
|
return;
|
|
@@ -2359,7 +2374,7 @@
|
|
|
2359
2374
|
const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.includes(defaultedOptions.queryHash));
|
|
2360
2375
|
const getObserver = options => {
|
|
2361
2376
|
const defaultedOptions = this.#client.defaultQueryOptions(options);
|
|
2362
|
-
const currentObserver = this.#
|
|
2377
|
+
const currentObserver = this.#observers.find(o => o.options.queryHash === defaultedOptions.queryHash);
|
|
2363
2378
|
return currentObserver ?? new QueryObserver(this.#client, defaultedOptions);
|
|
2364
2379
|
};
|
|
2365
2380
|
const newOrReusedObservers = unmatchedQueries.map(options => {
|
|
@@ -2413,7 +2428,7 @@
|
|
|
2413
2428
|
options.behavior = infiniteQueryBehavior();
|
|
2414
2429
|
return super.getOptimisticResult(options);
|
|
2415
2430
|
}
|
|
2416
|
-
fetchNextPage(options
|
|
2431
|
+
fetchNextPage(options) {
|
|
2417
2432
|
return this.fetch({
|
|
2418
2433
|
...options,
|
|
2419
2434
|
meta: {
|
|
@@ -2423,9 +2438,7 @@
|
|
|
2423
2438
|
}
|
|
2424
2439
|
});
|
|
2425
2440
|
}
|
|
2426
|
-
fetchPreviousPage({
|
|
2427
|
-
...options
|
|
2428
|
-
} = {}) {
|
|
2441
|
+
fetchPreviousPage(options) {
|
|
2429
2442
|
return this.fetch({
|
|
2430
2443
|
...options,
|
|
2431
2444
|
meta: {
|
|
@@ -2450,8 +2463,8 @@
|
|
|
2450
2463
|
...result,
|
|
2451
2464
|
fetchNextPage: this.fetchNextPage,
|
|
2452
2465
|
fetchPreviousPage: this.fetchPreviousPage,
|
|
2453
|
-
hasNextPage: hasNextPage(options, state.data
|
|
2454
|
-
hasPreviousPage: hasPreviousPage(options, state.data
|
|
2466
|
+
hasNextPage: hasNextPage(options, state.data),
|
|
2467
|
+
hasPreviousPage: hasPreviousPage(options, state.data),
|
|
2455
2468
|
isFetchingNextPage,
|
|
2456
2469
|
isFetchingPreviousPage,
|
|
2457
2470
|
isRefetching: isRefetching && !isFetchingNextPage && !isFetchingPreviousPage
|
|
@@ -2489,6 +2502,7 @@
|
|
|
2489
2502
|
observer: this
|
|
2490
2503
|
});
|
|
2491
2504
|
}
|
|
2505
|
+
this.#currentMutation?.setOptions(this.options);
|
|
2492
2506
|
}
|
|
2493
2507
|
onUnsubscribe() {
|
|
2494
2508
|
if (!this.listeners.length) {
|
|
@@ -3661,7 +3675,6 @@
|
|
|
3661
3675
|
};
|
|
3662
3676
|
}
|
|
3663
3677
|
|
|
3664
|
-
/* istanbul ignore file */
|
|
3665
3678
|
// eslint-disable-next-line no-shadow
|
|
3666
3679
|
var QueryState;
|
|
3667
3680
|
(function (QueryState) {
|
|
@@ -3739,7 +3752,6 @@
|
|
|
3739
3752
|
'Last Updated': dateSort
|
|
3740
3753
|
};
|
|
3741
3754
|
|
|
3742
|
-
/* istanbul ignore file */
|
|
3743
3755
|
const pluginId = 'vue-query';
|
|
3744
3756
|
const pluginName = 'Vue Query';
|
|
3745
3757
|
function setupDevtools(app, queryClient) {
|
|
@@ -3747,8 +3759,8 @@
|
|
|
3747
3759
|
id: pluginId,
|
|
3748
3760
|
label: pluginName,
|
|
3749
3761
|
packageName: 'vue-query',
|
|
3750
|
-
homepage: 'https://tanstack.com/query/
|
|
3751
|
-
logo: 'https://vue-query
|
|
3762
|
+
homepage: 'https://tanstack.com/query/latest',
|
|
3763
|
+
logo: 'https://raw.githubusercontent.com/TanStack/query/main/packages/vue-query/media/vue-query.svg',
|
|
3752
3764
|
app,
|
|
3753
3765
|
settings: {
|
|
3754
3766
|
baseSort: {
|
|
@@ -3772,16 +3784,31 @@
|
|
|
3772
3784
|
value: key
|
|
3773
3785
|
})),
|
|
3774
3786
|
defaultValue: Object.keys(sortFns)[0]
|
|
3787
|
+
},
|
|
3788
|
+
onlineMode: {
|
|
3789
|
+
type: 'choice',
|
|
3790
|
+
component: 'button-group',
|
|
3791
|
+
label: 'Online mode',
|
|
3792
|
+
options: [{
|
|
3793
|
+
label: 'Online',
|
|
3794
|
+
value: 1
|
|
3795
|
+
}, {
|
|
3796
|
+
label: 'Offline',
|
|
3797
|
+
value: 0
|
|
3798
|
+
}],
|
|
3799
|
+
defaultValue: 1
|
|
3775
3800
|
}
|
|
3776
3801
|
}
|
|
3777
3802
|
}, api => {
|
|
3803
|
+
const initialSettings = api.getSettings();
|
|
3804
|
+
onlineManager.setOnline(Boolean(initialSettings.onlineMode.valueOf()));
|
|
3778
3805
|
const queryCache = queryClient.getQueryCache();
|
|
3779
3806
|
api.addInspector({
|
|
3780
3807
|
id: pluginId,
|
|
3781
3808
|
label: pluginName,
|
|
3782
3809
|
icon: 'api',
|
|
3783
3810
|
nodeActions: [{
|
|
3784
|
-
icon: '
|
|
3811
|
+
icon: 'file_download',
|
|
3785
3812
|
tooltip: 'Refetch',
|
|
3786
3813
|
action: queryHash => {
|
|
3787
3814
|
queryCache.get(queryHash)?.fetch();
|
|
@@ -3806,6 +3833,27 @@
|
|
|
3806
3833
|
const query = queryCache.get(queryHash);
|
|
3807
3834
|
queryCache.remove(query);
|
|
3808
3835
|
}
|
|
3836
|
+
}, {
|
|
3837
|
+
icon: 'hourglass_empty',
|
|
3838
|
+
tooltip: 'Force loading',
|
|
3839
|
+
action: queryHash => {
|
|
3840
|
+
const query = queryCache.get(queryHash);
|
|
3841
|
+
query.setState({
|
|
3842
|
+
data: undefined,
|
|
3843
|
+
status: 'pending'
|
|
3844
|
+
});
|
|
3845
|
+
}
|
|
3846
|
+
}, {
|
|
3847
|
+
icon: 'error_outline',
|
|
3848
|
+
tooltip: 'Force error',
|
|
3849
|
+
action: queryHash => {
|
|
3850
|
+
const query = queryCache.get(queryHash);
|
|
3851
|
+
query.setState({
|
|
3852
|
+
data: undefined,
|
|
3853
|
+
status: 'error',
|
|
3854
|
+
error: new Error('Unknown error from devtools')
|
|
3855
|
+
});
|
|
3856
|
+
}
|
|
3809
3857
|
}]
|
|
3810
3858
|
});
|
|
3811
3859
|
api.addTimelineLayer({
|
|
@@ -3816,9 +3864,7 @@
|
|
|
3816
3864
|
queryCache.subscribe(event => {
|
|
3817
3865
|
api.sendInspectorTree(pluginId);
|
|
3818
3866
|
api.sendInspectorState(pluginId);
|
|
3819
|
-
if (
|
|
3820
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
3821
|
-
event && ['queryAdded', 'queryRemoved', 'queryUpdated'].includes(event.type)) {
|
|
3867
|
+
if (['added', 'removed', 'updated'].includes(event.type)) {
|
|
3822
3868
|
api.addTimelineEvent({
|
|
3823
3869
|
layerId: pluginId,
|
|
3824
3870
|
event: {
|
|
@@ -3833,6 +3879,11 @@
|
|
|
3833
3879
|
});
|
|
3834
3880
|
}
|
|
3835
3881
|
});
|
|
3882
|
+
api.on.setPluginSettings(payload => {
|
|
3883
|
+
if (payload.key === 'onlineMode') {
|
|
3884
|
+
onlineManager.setOnline(Boolean(payload.newValue));
|
|
3885
|
+
}
|
|
3886
|
+
});
|
|
3836
3887
|
api.on.getInspectorTree(payload => {
|
|
3837
3888
|
if (payload.inspectorId === pluginId) {
|
|
3838
3889
|
const queries = queryCache.getAll();
|
|
@@ -3925,8 +3976,6 @@
|
|
|
3925
3976
|
originalUnmount();
|
|
3926
3977
|
};
|
|
3927
3978
|
}
|
|
3928
|
-
|
|
3929
|
-
/* istanbul ignore next */
|
|
3930
3979
|
if (vueDemi.isVue2) {
|
|
3931
3980
|
app.mixin({
|
|
3932
3981
|
beforeCreate() {
|
|
@@ -4026,9 +4075,8 @@
|
|
|
4026
4075
|
|
|
4027
4076
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4028
4077
|
function useQueries({
|
|
4029
|
-
queries
|
|
4030
|
-
|
|
4031
|
-
}) {
|
|
4078
|
+
queries
|
|
4079
|
+
}, queryClient) {
|
|
4032
4080
|
const client = queryClient || useQueryClient();
|
|
4033
4081
|
const defaultedQueries = vueDemi.computed(() => cloneDeepUnref(queries).map(options => {
|
|
4034
4082
|
const defaulted = client.defaultQueryOptions(options);
|
|
@@ -4047,14 +4095,14 @@
|
|
|
4047
4095
|
state.value.splice(0, result.length, ...result);
|
|
4048
4096
|
});
|
|
4049
4097
|
// Subscription would not fire for persisted results
|
|
4050
|
-
state.value
|
|
4098
|
+
state.value = observer.getOptimisticResult(defaultedQueries.value);
|
|
4051
4099
|
}
|
|
4052
4100
|
}, {
|
|
4053
4101
|
immediate: true
|
|
4054
4102
|
});
|
|
4055
4103
|
vueDemi.watch(defaultedQueries, () => {
|
|
4056
4104
|
observer.setQueries(defaultedQueries.value);
|
|
4057
|
-
state.value
|
|
4105
|
+
state.value = observer.getCurrentResult();
|
|
4058
4106
|
}, {
|
|
4059
4107
|
deep: true
|
|
4060
4108
|
});
|
|
@@ -4127,22 +4175,31 @@
|
|
|
4127
4175
|
return isFetching;
|
|
4128
4176
|
}
|
|
4129
4177
|
|
|
4130
|
-
function useIsMutating(
|
|
4131
|
-
const filters = vueDemi.computed(() => cloneDeepUnref(mutationFilters));
|
|
4178
|
+
function useIsMutating(filters = {}, queryClient) {
|
|
4132
4179
|
const client = queryClient || useQueryClient();
|
|
4133
|
-
const
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
});
|
|
4137
|
-
vueDemi.
|
|
4138
|
-
|
|
4139
|
-
},
|
|
4140
|
-
|
|
4180
|
+
const unreffedFilters = vueDemi.computed(() => ({
|
|
4181
|
+
...cloneDeepUnref(filters),
|
|
4182
|
+
status: 'pending'
|
|
4183
|
+
}));
|
|
4184
|
+
const length = vueDemi.computed(() => useMutationState({
|
|
4185
|
+
filters: unreffedFilters
|
|
4186
|
+
}, client).value.length);
|
|
4187
|
+
return length;
|
|
4188
|
+
}
|
|
4189
|
+
function getResult(mutationCache, options) {
|
|
4190
|
+
return mutationCache.findAll(options.filters).map(mutation => options.select ? options.select(mutation) : mutation.state);
|
|
4191
|
+
}
|
|
4192
|
+
function useMutationState(options = {}, queryClient) {
|
|
4193
|
+
const mutationCache = (queryClient || useQueryClient()).getMutationCache();
|
|
4194
|
+
const state = vueDemi.ref(getResult(mutationCache, options));
|
|
4195
|
+
const unsubscribe = mutationCache.subscribe(() => {
|
|
4196
|
+
const result = getResult(mutationCache, options);
|
|
4197
|
+
state.value = result;
|
|
4141
4198
|
});
|
|
4142
4199
|
vueDemi.onScopeDispose(() => {
|
|
4143
4200
|
unsubscribe();
|
|
4144
4201
|
});
|
|
4145
|
-
return
|
|
4202
|
+
return vueDemi.readonly(state);
|
|
4146
4203
|
}
|
|
4147
4204
|
|
|
4148
4205
|
exports.CancelledError = CancelledError;
|
|
@@ -4164,6 +4221,7 @@
|
|
|
4164
4221
|
exports.isCancelledError = isCancelledError;
|
|
4165
4222
|
exports.isServer = isServer;
|
|
4166
4223
|
exports.keepPreviousData = keepPreviousData;
|
|
4224
|
+
exports.matchQuery = matchQuery;
|
|
4167
4225
|
exports.notifyManager = notifyManager;
|
|
4168
4226
|
exports.onlineManager = onlineManager;
|
|
4169
4227
|
exports.replaceEqualDeep = replaceEqualDeep;
|
|
@@ -4171,6 +4229,7 @@
|
|
|
4171
4229
|
exports.useIsFetching = useIsFetching;
|
|
4172
4230
|
exports.useIsMutating = useIsMutating;
|
|
4173
4231
|
exports.useMutation = useMutation;
|
|
4232
|
+
exports.useMutationState = useMutationState;
|
|
4174
4233
|
exports.useQueries = useQueries;
|
|
4175
4234
|
exports.useQuery = useQuery;
|
|
4176
4235
|
exports.useQueryClient = useQueryClient;
|