@tanstack/query-core 5.0.0-alpha.2 → 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/_virtual/_rollupPluginBabelHelpers.esm.js +13 -0
- package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js.map +1 -0
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js +16 -0
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
- package/build/lib/focusManager.esm.js +31 -15
- package/build/lib/focusManager.esm.js.map +1 -1
- package/build/lib/focusManager.js +31 -15
- package/build/lib/focusManager.js.map +1 -1
- package/build/lib/hydration.d.ts +2 -6
- package/build/lib/hydration.esm.js +9 -20
- package/build/lib/hydration.esm.js.map +1 -1
- package/build/lib/hydration.js +9 -20
- package/build/lib/hydration.js.map +1 -1
- package/build/lib/hydration.mjs +4 -18
- package/build/lib/hydration.mjs.map +1 -1
- package/build/lib/index.d.ts +3 -3
- package/build/lib/infiniteQueryBehavior.d.ts +2 -2
- package/build/lib/infiniteQueryBehavior.esm.js +52 -48
- package/build/lib/infiniteQueryBehavior.esm.js.map +1 -1
- package/build/lib/infiniteQueryBehavior.js +52 -48
- package/build/lib/infiniteQueryBehavior.js.map +1 -1
- package/build/lib/infiniteQueryBehavior.mjs +48 -45
- package/build/lib/infiniteQueryBehavior.mjs.map +1 -1
- package/build/lib/infiniteQueryObserver.d.ts +6 -6
- package/build/lib/infiniteQueryObserver.esm.js +7 -8
- package/build/lib/infiniteQueryObserver.esm.js.map +1 -1
- package/build/lib/infiniteQueryObserver.js +7 -8
- package/build/lib/infiniteQueryObserver.js.map +1 -1
- package/build/lib/infiniteQueryObserver.mjs +4 -6
- package/build/lib/infiniteQueryObserver.mjs.map +1 -1
- package/build/lib/mutation.d.ts +2 -1
- package/build/lib/mutation.esm.js +134 -101
- package/build/lib/mutation.esm.js.map +1 -1
- package/build/lib/mutation.js +134 -101
- package/build/lib/mutation.js.map +1 -1
- package/build/lib/mutation.mjs +10 -2
- package/build/lib/mutation.mjs.map +1 -1
- package/build/lib/mutationCache.d.ts +2 -2
- package/build/lib/mutationCache.esm.js +34 -20
- package/build/lib/mutationCache.esm.js.map +1 -1
- package/build/lib/mutationCache.js +34 -20
- package/build/lib/mutationCache.js.map +1 -1
- package/build/lib/mutationCache.mjs +5 -4
- package/build/lib/mutationCache.mjs.map +1 -1
- package/build/lib/mutationObserver.esm.js +81 -50
- package/build/lib/mutationObserver.esm.js.map +1 -1
- package/build/lib/mutationObserver.js +81 -50
- package/build/lib/mutationObserver.js.map +1 -1
- package/build/lib/mutationObserver.mjs +1 -0
- package/build/lib/mutationObserver.mjs.map +1 -1
- package/build/lib/onlineManager.esm.js +29 -14
- package/build/lib/onlineManager.esm.js.map +1 -1
- package/build/lib/onlineManager.js +29 -14
- package/build/lib/onlineManager.js.map +1 -1
- package/build/lib/queriesObserver.esm.js +95 -65
- package/build/lib/queriesObserver.esm.js.map +1 -1
- package/build/lib/queriesObserver.js +95 -65
- 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.d.ts +4 -3
- package/build/lib/query.esm.js +210 -161
- package/build/lib/query.esm.js.map +1 -1
- package/build/lib/query.js +210 -161
- 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/queryCache.d.ts +2 -2
- package/build/lib/queryCache.esm.js +21 -13
- package/build/lib/queryCache.esm.js.map +1 -1
- package/build/lib/queryCache.js +21 -13
- package/build/lib/queryCache.js.map +1 -1
- package/build/lib/queryCache.mjs +5 -4
- package/build/lib/queryCache.mjs.map +1 -1
- package/build/lib/queryClient.esm.js +107 -66
- package/build/lib/queryClient.esm.js.map +1 -1
- package/build/lib/queryClient.js +107 -66
- package/build/lib/queryClient.js.map +1 -1
- package/build/lib/queryClient.mjs +5 -4
- package/build/lib/queryClient.mjs.map +1 -1
- package/build/lib/queryObserver.d.ts +2 -4
- package/build/lib/queryObserver.esm.js +299 -211
- package/build/lib/queryObserver.esm.js.map +1 -1
- package/build/lib/queryObserver.js +297 -209
- package/build/lib/queryObserver.js.map +1 -1
- package/build/lib/queryObserver.mjs +11 -23
- package/build/lib/queryObserver.mjs.map +1 -1
- package/build/lib/removable.esm.js +13 -6
- package/build/lib/removable.esm.js.map +1 -1
- package/build/lib/removable.js +13 -6
- package/build/lib/removable.js.map +1 -1
- package/build/lib/retryer.esm.js +15 -14
- package/build/lib/retryer.esm.js.map +1 -1
- package/build/lib/retryer.js +15 -14
- package/build/lib/retryer.js.map +1 -1
- package/build/lib/tests/utils.d.ts +4 -5
- package/build/lib/types.d.ts +5 -15
- package/build/lib/utils.esm.js +1 -1
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +1 -1
- package/build/lib/utils.js.map +1 -1
- package/build/umd/index.development.js +97 -109
- 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/hydration.ts +18 -37
- package/src/index.ts +2 -4
- package/src/infiniteQueryBehavior.ts +52 -60
- package/src/infiniteQueryObserver.ts +15 -10
- package/src/mutation.ts +14 -5
- package/src/mutationCache.ts +6 -6
- package/src/mutationObserver.ts +1 -0
- package/src/queriesObserver.ts +8 -8
- package/src/query.ts +13 -8
- package/src/queryCache.ts +9 -8
- package/src/queryClient.ts +2 -4
- package/src/queryObserver.ts +17 -31
- package/src/tests/focusManager.test.tsx +12 -14
- package/src/tests/hydration.test.tsx +22 -17
- package/src/tests/infiniteQueryBehavior.test.tsx +16 -9
- package/src/tests/infiniteQueryObserver.test.tsx +62 -1
- package/src/tests/mutationCache.test.tsx +11 -10
- package/src/tests/mutationObserver.test.tsx +3 -2
- package/src/tests/mutations.test.tsx +41 -9
- package/src/tests/notifyManager.test.tsx +7 -6
- package/src/tests/onlineManager.test.tsx +12 -17
- package/src/tests/queriesObserver.test.tsx +18 -17
- package/src/tests/query.test.tsx +18 -17
- package/src/tests/queryCache.test.tsx +14 -13
- package/src/tests/queryClient.test.tsx +49 -48
- package/src/tests/queryObserver.test.tsx +65 -9
- package/src/tests/utils.test.tsx +2 -1
- package/src/tests/utils.ts +5 -4
- package/src/types.ts +9 -13
|
@@ -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,
|
|
@@ -1116,10 +1116,11 @@
|
|
|
1116
1116
|
return [...this.#queries.values()];
|
|
1117
1117
|
}
|
|
1118
1118
|
find(filters) {
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1119
|
+
const defaultedFilters = {
|
|
1120
|
+
exact: true,
|
|
1121
|
+
...filters
|
|
1122
|
+
};
|
|
1123
|
+
return this.getAll().find(query => matchQuery(defaultedFilters, query));
|
|
1123
1124
|
}
|
|
1124
1125
|
findAll(filters = {}) {
|
|
1125
1126
|
const queries = this.getAll();
|
|
@@ -1154,18 +1155,26 @@
|
|
|
1154
1155
|
|
|
1155
1156
|
class Mutation extends Removable {
|
|
1156
1157
|
#observers;
|
|
1158
|
+
#defaultOptions;
|
|
1157
1159
|
#mutationCache;
|
|
1158
1160
|
#retryer;
|
|
1159
1161
|
constructor(config) {
|
|
1160
1162
|
super();
|
|
1161
|
-
this.options = config.options;
|
|
1162
1163
|
this.mutationId = config.mutationId;
|
|
1164
|
+
this.#defaultOptions = config.defaultOptions;
|
|
1163
1165
|
this.#mutationCache = config.mutationCache;
|
|
1164
1166
|
this.#observers = [];
|
|
1165
1167
|
this.state = config.state || getDefaultState();
|
|
1166
|
-
this.
|
|
1168
|
+
this.setOptions(config.options);
|
|
1167
1169
|
this.scheduleGc();
|
|
1168
1170
|
}
|
|
1171
|
+
setOptions(options) {
|
|
1172
|
+
this.options = {
|
|
1173
|
+
...this.#defaultOptions,
|
|
1174
|
+
...options
|
|
1175
|
+
};
|
|
1176
|
+
this.updateGcTime(this.options.gcTime);
|
|
1177
|
+
}
|
|
1169
1178
|
get meta() {
|
|
1170
1179
|
return this.options.meta;
|
|
1171
1180
|
}
|
|
@@ -1417,10 +1426,11 @@
|
|
|
1417
1426
|
return this.#mutations;
|
|
1418
1427
|
}
|
|
1419
1428
|
find(filters) {
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1429
|
+
const defaultedFilters = {
|
|
1430
|
+
exact: true,
|
|
1431
|
+
...filters
|
|
1432
|
+
};
|
|
1433
|
+
return this.#mutations.find(mutation => matchMutation(defaultedFilters, mutation));
|
|
1424
1434
|
}
|
|
1425
1435
|
findAll(filters = {}) {
|
|
1426
1436
|
return this.#mutations.filter(mutation => matchMutation(filters, mutation));
|
|
@@ -1446,12 +1456,15 @@
|
|
|
1446
1456
|
function infiniteQueryBehavior() {
|
|
1447
1457
|
return {
|
|
1448
1458
|
onFetch: context => {
|
|
1449
|
-
context.fetchFn = () => {
|
|
1459
|
+
context.fetchFn = async () => {
|
|
1450
1460
|
const options = context.options;
|
|
1451
1461
|
const direction = context.fetchOptions?.meta?.fetchMore?.direction;
|
|
1452
1462
|
const oldPages = context.state.data?.pages || [];
|
|
1453
1463
|
const oldPageParams = context.state.data?.pageParams || [];
|
|
1454
|
-
|
|
1464
|
+
const empty = {
|
|
1465
|
+
pages: [],
|
|
1466
|
+
pageParams: []
|
|
1467
|
+
};
|
|
1455
1468
|
let cancelled = false;
|
|
1456
1469
|
const addSignalProperty = object => {
|
|
1457
1470
|
Object.defineProperty(object, 'signal', {
|
|
@@ -1471,95 +1484,95 @@
|
|
|
1471
1484
|
|
|
1472
1485
|
// Get query function
|
|
1473
1486
|
const queryFn = context.options.queryFn || (() => Promise.reject(new Error('Missing queryFn')));
|
|
1474
|
-
const buildNewPages = (pages, param, page, previous) => {
|
|
1475
|
-
const {
|
|
1476
|
-
maxPages
|
|
1477
|
-
} = context.options;
|
|
1478
|
-
if (previous) {
|
|
1479
|
-
newPageParams = addToStart(newPageParams, param, maxPages);
|
|
1480
|
-
return addToStart(pages, page, maxPages);
|
|
1481
|
-
}
|
|
1482
|
-
newPageParams = addToEnd(newPageParams, param, maxPages);
|
|
1483
|
-
return addToEnd(pages, page, maxPages);
|
|
1484
|
-
};
|
|
1485
1487
|
|
|
1486
1488
|
// Create function to fetch a page
|
|
1487
|
-
const fetchPage = (
|
|
1489
|
+
const fetchPage = async (data, param, previous) => {
|
|
1488
1490
|
if (cancelled) {
|
|
1489
1491
|
return Promise.reject();
|
|
1490
1492
|
}
|
|
1491
|
-
if (typeof param === 'undefined' && pages.length) {
|
|
1492
|
-
return Promise.resolve(
|
|
1493
|
+
if (typeof param === 'undefined' && data.pages.length) {
|
|
1494
|
+
return Promise.resolve(data);
|
|
1493
1495
|
}
|
|
1494
1496
|
const queryFnContext = {
|
|
1495
1497
|
queryKey: context.queryKey,
|
|
1496
1498
|
pageParam: param,
|
|
1499
|
+
direction: previous ? 'backward' : 'forward',
|
|
1497
1500
|
meta: context.options.meta
|
|
1498
1501
|
};
|
|
1499
1502
|
addSignalProperty(queryFnContext);
|
|
1500
|
-
const
|
|
1501
|
-
const
|
|
1502
|
-
|
|
1503
|
+
const page = await queryFn(queryFnContext);
|
|
1504
|
+
const {
|
|
1505
|
+
maxPages
|
|
1506
|
+
} = context.options;
|
|
1507
|
+
const addTo = previous ? addToStart : addToEnd;
|
|
1508
|
+
return {
|
|
1509
|
+
pages: addTo(data.pages, page, maxPages),
|
|
1510
|
+
pageParams: addTo(data.pageParams, param, maxPages)
|
|
1511
|
+
};
|
|
1503
1512
|
};
|
|
1504
|
-
let
|
|
1513
|
+
let result;
|
|
1505
1514
|
|
|
1506
1515
|
// Fetch first page?
|
|
1507
1516
|
if (!oldPages.length) {
|
|
1508
|
-
|
|
1517
|
+
result = await fetchPage(empty, options.defaultPageParam);
|
|
1509
1518
|
}
|
|
1510
1519
|
|
|
1511
1520
|
// fetch next / previous page?
|
|
1512
1521
|
else if (direction) {
|
|
1513
1522
|
const previous = direction === 'backward';
|
|
1514
|
-
const
|
|
1515
|
-
|
|
1523
|
+
const pageParamFn = previous ? getPreviousPageParam : getNextPageParam;
|
|
1524
|
+
const oldData = {
|
|
1525
|
+
pages: oldPages,
|
|
1526
|
+
pageParams: oldPageParams
|
|
1527
|
+
};
|
|
1528
|
+
const param = pageParamFn(options, oldData);
|
|
1529
|
+
result = await fetchPage(oldData, param, previous);
|
|
1516
1530
|
}
|
|
1517
1531
|
|
|
1518
1532
|
// Refetch pages
|
|
1519
1533
|
else {
|
|
1520
|
-
newPageParams = [];
|
|
1521
|
-
|
|
1522
1534
|
// Fetch first page
|
|
1523
|
-
|
|
1535
|
+
result = await fetchPage(empty, oldPageParams[0]);
|
|
1524
1536
|
|
|
1525
1537
|
// Fetch remaining pages
|
|
1526
1538
|
for (let i = 1; i < oldPages.length; i++) {
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
return fetchPage(pages, param);
|
|
1530
|
-
});
|
|
1539
|
+
const param = getNextPageParam(options, result);
|
|
1540
|
+
result = await fetchPage(result, param);
|
|
1531
1541
|
}
|
|
1532
1542
|
}
|
|
1533
|
-
|
|
1534
|
-
pages,
|
|
1535
|
-
pageParams: newPageParams
|
|
1536
|
-
}));
|
|
1537
|
-
return finalPromise;
|
|
1543
|
+
return result;
|
|
1538
1544
|
};
|
|
1539
1545
|
}
|
|
1540
1546
|
};
|
|
1541
1547
|
}
|
|
1542
|
-
function getNextPageParam(options,
|
|
1543
|
-
|
|
1548
|
+
function getNextPageParam(options, {
|
|
1549
|
+
pages,
|
|
1550
|
+
pageParams
|
|
1551
|
+
}) {
|
|
1552
|
+
const lastIndex = pages.length - 1;
|
|
1553
|
+
return options.getNextPageParam(pages[lastIndex], pages, pageParams[lastIndex], pageParams);
|
|
1544
1554
|
}
|
|
1545
|
-
function getPreviousPageParam(options,
|
|
1546
|
-
|
|
1555
|
+
function getPreviousPageParam(options, {
|
|
1556
|
+
pages,
|
|
1557
|
+
pageParams
|
|
1558
|
+
}) {
|
|
1559
|
+
return options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams);
|
|
1547
1560
|
}
|
|
1548
1561
|
|
|
1549
1562
|
/**
|
|
1550
1563
|
* Checks if there is a next page.
|
|
1551
1564
|
*/
|
|
1552
|
-
function hasNextPage(options,
|
|
1553
|
-
if (!
|
|
1554
|
-
return typeof getNextPageParam(options,
|
|
1565
|
+
function hasNextPage(options, data) {
|
|
1566
|
+
if (!data) return false;
|
|
1567
|
+
return typeof getNextPageParam(options, data) !== 'undefined';
|
|
1555
1568
|
}
|
|
1556
1569
|
|
|
1557
1570
|
/**
|
|
1558
1571
|
* Checks if there is a previous page.
|
|
1559
1572
|
*/
|
|
1560
|
-
function hasPreviousPage(options,
|
|
1561
|
-
if (!
|
|
1562
|
-
return typeof getPreviousPageParam(options,
|
|
1573
|
+
function hasPreviousPage(options, data) {
|
|
1574
|
+
if (!data || !options.getPreviousPageParam) return false;
|
|
1575
|
+
return typeof getPreviousPageParam(options, data) !== 'undefined';
|
|
1563
1576
|
}
|
|
1564
1577
|
|
|
1565
1578
|
// CLASS
|
|
@@ -1684,10 +1697,11 @@
|
|
|
1684
1697
|
});
|
|
1685
1698
|
}
|
|
1686
1699
|
cancelQueries(filters = {}, cancelOptions = {}) {
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1700
|
+
const defaultedCancelOptions = {
|
|
1701
|
+
revert: true,
|
|
1702
|
+
...cancelOptions
|
|
1703
|
+
};
|
|
1704
|
+
const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).map(query => query.cancel(defaultedCancelOptions)));
|
|
1691
1705
|
return Promise.all(promises).then(noop).catch(noop);
|
|
1692
1706
|
}
|
|
1693
1707
|
invalidateQueries(filters = {}, options = {}) {
|
|
@@ -1836,10 +1850,12 @@
|
|
|
1836
1850
|
#currentResult = undefined;
|
|
1837
1851
|
#currentResultState;
|
|
1838
1852
|
#currentResultOptions;
|
|
1839
|
-
#previousQueryResult;
|
|
1840
1853
|
#selectError;
|
|
1841
1854
|
#selectFn;
|
|
1842
1855
|
#selectResult;
|
|
1856
|
+
// This property keeps track of the last defined query data.
|
|
1857
|
+
// It will be used to pass the previous data to the placeholder function between renders.
|
|
1858
|
+
#lastDefinedQueryData;
|
|
1843
1859
|
#staleTimeoutId;
|
|
1844
1860
|
#refetchIntervalId;
|
|
1845
1861
|
#currentRefetchInterval;
|
|
@@ -2034,7 +2050,6 @@
|
|
|
2034
2050
|
const prevResultOptions = this.#currentResultOptions;
|
|
2035
2051
|
const queryChange = query !== prevQuery;
|
|
2036
2052
|
const queryInitialState = queryChange ? query.state : this.#currentQueryInitialState;
|
|
2037
|
-
const prevQueryResult = queryChange ? this.#currentResult : this.#previousQueryResult;
|
|
2038
2053
|
const {
|
|
2039
2054
|
state
|
|
2040
2055
|
} = query;
|
|
@@ -2093,7 +2108,7 @@
|
|
|
2093
2108
|
if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
|
|
2094
2109
|
placeholderData = prevResult.data;
|
|
2095
2110
|
} else {
|
|
2096
|
-
placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(
|
|
2111
|
+
placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(this.#lastDefinedQueryData) : options.placeholderData;
|
|
2097
2112
|
if (options.select && typeof placeholderData !== 'undefined') {
|
|
2098
2113
|
try {
|
|
2099
2114
|
placeholderData = options.select(placeholderData);
|
|
@@ -2157,6 +2172,9 @@
|
|
|
2157
2172
|
if (shallowEqualObjects(nextResult, prevResult)) {
|
|
2158
2173
|
return;
|
|
2159
2174
|
}
|
|
2175
|
+
if (this.#currentResultState.data !== undefined) {
|
|
2176
|
+
this.#lastDefinedQueryData = this.#currentResultState.data;
|
|
2177
|
+
}
|
|
2160
2178
|
this.#currentResult = nextResult;
|
|
2161
2179
|
|
|
2162
2180
|
// Determine which callbacks to trigger
|
|
@@ -2197,36 +2215,20 @@
|
|
|
2197
2215
|
const prevQuery = this.#currentQuery;
|
|
2198
2216
|
this.#currentQuery = query;
|
|
2199
2217
|
this.#currentQueryInitialState = query.state;
|
|
2200
|
-
this.#previousQueryResult = this.#currentResult;
|
|
2201
2218
|
if (this.hasListeners()) {
|
|
2202
2219
|
prevQuery?.removeObserver(this);
|
|
2203
2220
|
query.addObserver(this);
|
|
2204
2221
|
}
|
|
2205
2222
|
}
|
|
2206
|
-
onQueryUpdate(
|
|
2207
|
-
|
|
2208
|
-
if (action.type === 'success') {
|
|
2209
|
-
notifyOptions.onSuccess = !action.manual;
|
|
2210
|
-
} else if (action.type === 'error' && !isCancelledError(action.error)) {
|
|
2211
|
-
notifyOptions.onError = true;
|
|
2212
|
-
}
|
|
2213
|
-
this.#updateResult(notifyOptions);
|
|
2223
|
+
onQueryUpdate() {
|
|
2224
|
+
this.#updateResult();
|
|
2214
2225
|
if (this.hasListeners()) {
|
|
2215
2226
|
this.#updateTimers();
|
|
2216
2227
|
}
|
|
2217
2228
|
}
|
|
2218
2229
|
#notify(notifyOptions) {
|
|
2219
2230
|
notifyManager.batch(() => {
|
|
2220
|
-
// First trigger the
|
|
2221
|
-
if (notifyOptions.onSuccess) {
|
|
2222
|
-
this.options.onSuccess?.(this.#currentResult.data);
|
|
2223
|
-
this.options.onSettled?.(this.#currentResult.data, null);
|
|
2224
|
-
} else if (notifyOptions.onError) {
|
|
2225
|
-
this.options.onError?.(this.#currentResult.error);
|
|
2226
|
-
this.options.onSettled?.(undefined, this.#currentResult.error);
|
|
2227
|
-
}
|
|
2228
|
-
|
|
2229
|
-
// Then trigger the listeners
|
|
2231
|
+
// First, trigger the listeners
|
|
2230
2232
|
if (notifyOptions.listeners) {
|
|
2231
2233
|
this.listeners.forEach(listener => {
|
|
2232
2234
|
listener(this.#currentResult);
|
|
@@ -2348,9 +2350,10 @@
|
|
|
2348
2350
|
}
|
|
2349
2351
|
#findMatchingObservers(queries) {
|
|
2350
2352
|
const prevObservers = this.#observers;
|
|
2353
|
+
const prevObserversMap = new Map(prevObservers.map(observer => [observer.options.queryHash, observer]));
|
|
2351
2354
|
const defaultedQueryOptions = queries.map(options => this.#client.defaultQueryOptions(options));
|
|
2352
2355
|
const matchingObservers = defaultedQueryOptions.flatMap(defaultedOptions => {
|
|
2353
|
-
const match =
|
|
2356
|
+
const match = prevObserversMap.get(defaultedOptions.queryHash);
|
|
2354
2357
|
if (match != null) {
|
|
2355
2358
|
return [{
|
|
2356
2359
|
defaultedQueryOptions: defaultedOptions,
|
|
@@ -2359,8 +2362,8 @@
|
|
|
2359
2362
|
}
|
|
2360
2363
|
return [];
|
|
2361
2364
|
});
|
|
2362
|
-
const matchedQueryHashes = matchingObservers.map(match => match.defaultedQueryOptions.queryHash);
|
|
2363
|
-
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));
|
|
2364
2367
|
const getObserver = options => {
|
|
2365
2368
|
const defaultedOptions = this.#client.defaultQueryOptions(options);
|
|
2366
2369
|
const currentObserver = this.#observers.find(o => o.options.queryHash === defaultedOptions.queryHash);
|
|
@@ -2417,7 +2420,7 @@
|
|
|
2417
2420
|
options.behavior = infiniteQueryBehavior();
|
|
2418
2421
|
return super.getOptimisticResult(options);
|
|
2419
2422
|
}
|
|
2420
|
-
fetchNextPage(options
|
|
2423
|
+
fetchNextPage(options) {
|
|
2421
2424
|
return this.fetch({
|
|
2422
2425
|
...options,
|
|
2423
2426
|
meta: {
|
|
@@ -2427,9 +2430,7 @@
|
|
|
2427
2430
|
}
|
|
2428
2431
|
});
|
|
2429
2432
|
}
|
|
2430
|
-
fetchPreviousPage({
|
|
2431
|
-
...options
|
|
2432
|
-
} = {}) {
|
|
2433
|
+
fetchPreviousPage(options) {
|
|
2433
2434
|
return this.fetch({
|
|
2434
2435
|
...options,
|
|
2435
2436
|
meta: {
|
|
@@ -2454,8 +2455,8 @@
|
|
|
2454
2455
|
...result,
|
|
2455
2456
|
fetchNextPage: this.fetchNextPage,
|
|
2456
2457
|
fetchPreviousPage: this.fetchPreviousPage,
|
|
2457
|
-
hasNextPage: hasNextPage(options, state.data
|
|
2458
|
-
hasPreviousPage: hasPreviousPage(options, state.data
|
|
2458
|
+
hasNextPage: hasNextPage(options, state.data),
|
|
2459
|
+
hasPreviousPage: hasPreviousPage(options, state.data),
|
|
2459
2460
|
isFetchingNextPage,
|
|
2460
2461
|
isFetchingPreviousPage,
|
|
2461
2462
|
isRefetching: isRefetching && !isFetchingNextPage && !isFetchingPreviousPage
|
|
@@ -2493,6 +2494,7 @@
|
|
|
2493
2494
|
observer: this
|
|
2494
2495
|
});
|
|
2495
2496
|
}
|
|
2497
|
+
this.#currentMutation?.setOptions(this.options);
|
|
2496
2498
|
}
|
|
2497
2499
|
onUnsubscribe() {
|
|
2498
2500
|
if (!this.listeners.length) {
|
|
@@ -2580,24 +2582,10 @@
|
|
|
2580
2582
|
return query.state.status === 'success';
|
|
2581
2583
|
}
|
|
2582
2584
|
function dehydrate(client, options = {}) {
|
|
2583
|
-
const
|
|
2584
|
-
const
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
client.getMutationCache().getAll().forEach(mutation => {
|
|
2588
|
-
if (shouldDehydrateMutation(mutation)) {
|
|
2589
|
-
mutations.push(dehydrateMutation(mutation));
|
|
2590
|
-
}
|
|
2591
|
-
});
|
|
2592
|
-
}
|
|
2593
|
-
if (options.dehydrateQueries !== false) {
|
|
2594
|
-
const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;
|
|
2595
|
-
client.getQueryCache().getAll().forEach(query => {
|
|
2596
|
-
if (shouldDehydrateQuery(query)) {
|
|
2597
|
-
queries.push(dehydrateQuery(query));
|
|
2598
|
-
}
|
|
2599
|
-
});
|
|
2600
|
-
}
|
|
2585
|
+
const filterMutation = options.shouldDehydrateMutation ?? defaultShouldDehydrateMutation;
|
|
2586
|
+
const mutations = client.getMutationCache().getAll().flatMap(mutation => filterMutation(mutation) ? [dehydrateMutation(mutation)] : []);
|
|
2587
|
+
const filterQuery = options.shouldDehydrateQuery ?? defaultShouldDehydrateQuery;
|
|
2588
|
+
const queries = client.getQueryCache().getAll().flatMap(query => filterQuery(query) ? [dehydrateQuery(query)] : []);
|
|
2601
2589
|
return {
|
|
2602
2590
|
mutations,
|
|
2603
2591
|
queries
|