tsdf 14.0.0 → 15.0.0
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/dist/main.cjs +111 -107
- package/dist/main.d.cts +24 -10
- package/dist/main.d.ts +24 -10
- package/dist/main.js +111 -107
- package/package.json +1 -1
package/dist/main.cjs
CHANGED
|
@@ -880,29 +880,41 @@ function newTSDFCollectionStore({
|
|
|
880
880
|
}
|
|
881
881
|
function useMultipleItems(items, {
|
|
882
882
|
selector,
|
|
883
|
-
selectorUsesExternalDeps
|
|
883
|
+
selectorUsesExternalDeps,
|
|
884
|
+
returnIdleStatus: allItemsReturnIdleStatus,
|
|
885
|
+
returnRefetchingStatus: allItemsReturnRefetchingStatus,
|
|
886
|
+
omitPayload: allItemsOmitPayload,
|
|
887
|
+
disableRefetchOnMount: allItemsDisableRefetchOnMount,
|
|
888
|
+
isOffScreen: allItemsIsOffScreen
|
|
884
889
|
} = {}) {
|
|
885
890
|
const queriesWithId = useDeepMemo(() => {
|
|
886
891
|
return items.map((queryProps) => {
|
|
887
892
|
return {
|
|
888
893
|
itemKey: getItemKey(queryProps.payload),
|
|
889
894
|
payload: queryProps.payload,
|
|
890
|
-
disableRefetchOnMount: queryProps.disableRefetchOnMount ?? globalDisableRefetchOnMount,
|
|
891
|
-
returnIdleStatus: queryProps.returnIdleStatus,
|
|
892
|
-
returnRefetchingStatus: queryProps.returnRefetchingStatus,
|
|
893
|
-
omitPayload: queryProps.omitPayload,
|
|
894
|
-
isOffScreen: queryProps.isOffScreen,
|
|
895
|
+
disableRefetchOnMount: queryProps.disableRefetchOnMount ?? allItemsDisableRefetchOnMount ?? globalDisableRefetchOnMount,
|
|
896
|
+
returnIdleStatus: queryProps.returnIdleStatus ?? allItemsReturnIdleStatus,
|
|
897
|
+
returnRefetchingStatus: queryProps.returnRefetchingStatus ?? allItemsReturnRefetchingStatus,
|
|
898
|
+
omitPayload: queryProps.omitPayload ?? allItemsOmitPayload,
|
|
899
|
+
isOffScreen: queryProps.isOffScreen ?? allItemsIsOffScreen,
|
|
895
900
|
queryMetadata: queryProps.queryMetadata
|
|
896
901
|
};
|
|
897
902
|
});
|
|
898
|
-
}, [
|
|
903
|
+
}, [
|
|
904
|
+
items,
|
|
905
|
+
allItemsDisableRefetchOnMount,
|
|
906
|
+
allItemsIsOffScreen,
|
|
907
|
+
allItemsOmitPayload,
|
|
908
|
+
allItemsReturnIdleStatus,
|
|
909
|
+
allItemsReturnRefetchingStatus
|
|
910
|
+
]);
|
|
899
911
|
const dataSelector = (0, import_react7.useCallback)(
|
|
900
912
|
(itemState) => {
|
|
901
913
|
if (selector)
|
|
902
914
|
return selector(itemState);
|
|
903
915
|
return itemState;
|
|
904
916
|
},
|
|
905
|
-
// eslint-disable-next-line
|
|
917
|
+
// eslint-disable-next-line @lucasols/extended-lint/exhaustive-deps
|
|
906
918
|
[selectorUsesExternalDeps ? selector : 0]
|
|
907
919
|
);
|
|
908
920
|
const resultSelector = (0, import_react7.useCallback)(
|
|
@@ -1059,7 +1071,7 @@ function newTSDFCollectionStore({
|
|
|
1059
1071
|
isLoading: false,
|
|
1060
1072
|
queryMetadata: void 0
|
|
1061
1073
|
},
|
|
1062
|
-
// eslint-disable-next-line
|
|
1074
|
+
// eslint-disable-next-line @lucasols/extended-lint/exhaustive-deps
|
|
1063
1075
|
[item]
|
|
1064
1076
|
);
|
|
1065
1077
|
const [useModifyResult, emitIsLoadedEvt] = useEnsureIsLoaded(
|
|
@@ -1228,7 +1240,6 @@ function newTSDFListQueryStore({
|
|
|
1228
1240
|
disableInitialDataInvalidation,
|
|
1229
1241
|
mediumPriorityThrottleMs,
|
|
1230
1242
|
dynamicRealtimeThrottleMs,
|
|
1231
|
-
syncMutationsAndInvalidations,
|
|
1232
1243
|
optimisticListUpdates,
|
|
1233
1244
|
onInvalidateItem,
|
|
1234
1245
|
onInvalidateQuery
|
|
@@ -1505,9 +1516,46 @@ function newTSDFListQueryStore({
|
|
|
1505
1516
|
}
|
|
1506
1517
|
}
|
|
1507
1518
|
const storeEvents = (0, import_evtmitter4.evtmitter)();
|
|
1519
|
+
const itemInvalidationWasTriggered = /* @__PURE__ */ new Set();
|
|
1520
|
+
function invalidateItem(itemId, priority = "highPriority") {
|
|
1521
|
+
if (!fetchItemOrquestrator) {
|
|
1522
|
+
throw new Error(noFetchFnError);
|
|
1523
|
+
}
|
|
1524
|
+
const itemsKey = getItemsKeyArray(itemId);
|
|
1525
|
+
for (const { itemKey, payload } of itemsKey) {
|
|
1526
|
+
const item = store.state.itemQueries[itemKey];
|
|
1527
|
+
if (!item)
|
|
1528
|
+
continue;
|
|
1529
|
+
const currentInvalidationPriority = item.refetchOnMount ? fetchTypePriority[item.refetchOnMount] : -1;
|
|
1530
|
+
const newInvalidationPriority = fetchTypePriority[priority];
|
|
1531
|
+
if (currentInvalidationPriority >= newInvalidationPriority)
|
|
1532
|
+
continue;
|
|
1533
|
+
store.produceState(
|
|
1534
|
+
(draft) => {
|
|
1535
|
+
const query = draft.itemQueries[itemKey];
|
|
1536
|
+
if (!query)
|
|
1537
|
+
return;
|
|
1538
|
+
query.refetchOnMount = priority;
|
|
1539
|
+
},
|
|
1540
|
+
{ action: { type: "invalidate-item", queryKey: itemKey } }
|
|
1541
|
+
);
|
|
1542
|
+
itemInvalidationWasTriggered.delete(itemKey);
|
|
1543
|
+
storeEvents.emit("invalidateItem", { priority, itemKey });
|
|
1544
|
+
if (onInvalidateItem) {
|
|
1545
|
+
const itemState = store.state.items[itemKey];
|
|
1546
|
+
if (itemState) {
|
|
1547
|
+
onInvalidateItem({ priority, itemState, payload });
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1508
1552
|
const queryInvalidationWasTriggered = /* @__PURE__ */ new Set();
|
|
1509
|
-
function
|
|
1510
|
-
|
|
1553
|
+
function invalidateQueryAndItems({
|
|
1554
|
+
itemPayload,
|
|
1555
|
+
queryPayload,
|
|
1556
|
+
type: priority = "highPriority"
|
|
1557
|
+
}) {
|
|
1558
|
+
const queriesKey = queryPayload ? getQueriesKeyArray(queryPayload) : [];
|
|
1511
1559
|
for (const { key, payload } of queriesKey) {
|
|
1512
1560
|
const queryState = store.state.queries[key];
|
|
1513
1561
|
if (!queryState)
|
|
@@ -1529,27 +1577,8 @@ function newTSDFListQueryStore({
|
|
|
1529
1577
|
storeEvents.emit("invalidateQuery", { priority, queryKey: key });
|
|
1530
1578
|
onInvalidateQuery?.(payload, priority);
|
|
1531
1579
|
}
|
|
1532
|
-
if (
|
|
1533
|
-
invalidateItem(
|
|
1534
|
-
(itemPayload) => queriesKey.some(({ payload }) => {
|
|
1535
|
-
return syncMutationsAndInvalidations.syncItemAndQuery(
|
|
1536
|
-
itemPayload,
|
|
1537
|
-
payload
|
|
1538
|
-
);
|
|
1539
|
-
}),
|
|
1540
|
-
priority,
|
|
1541
|
-
true
|
|
1542
|
-
);
|
|
1543
|
-
invalidateQuery(
|
|
1544
|
-
(queryToInvalidatePayload, _, queryToInvalidateKey) => queriesKey.some((alreadyInvalidatedQueryPayload) => {
|
|
1545
|
-
return queryToInvalidateKey !== alreadyInvalidatedQueryPayload.key && syncMutationsAndInvalidations.syncQueries(
|
|
1546
|
-
alreadyInvalidatedQueryPayload.payload,
|
|
1547
|
-
queryToInvalidatePayload
|
|
1548
|
-
);
|
|
1549
|
-
}),
|
|
1550
|
-
priority,
|
|
1551
|
-
true
|
|
1552
|
-
);
|
|
1580
|
+
if (itemPayload) {
|
|
1581
|
+
invalidateItem(itemPayload, priority);
|
|
1553
1582
|
}
|
|
1554
1583
|
}
|
|
1555
1584
|
function defaultItemSelector(data) {
|
|
@@ -1557,23 +1586,37 @@ function newTSDFListQueryStore({
|
|
|
1557
1586
|
}
|
|
1558
1587
|
function useMultipleListQueries(queries, {
|
|
1559
1588
|
itemSelector = defaultItemSelector,
|
|
1560
|
-
selectorUsesExternalDeps
|
|
1589
|
+
selectorUsesExternalDeps,
|
|
1590
|
+
returnIdleStatus: allItemsReturnIdleStatus,
|
|
1591
|
+
returnRefetchingStatus: allItemsReturnRefetchingStatus,
|
|
1592
|
+
omitPayload: allItemsOmitPayload,
|
|
1593
|
+
disableRefetchOnMount: allItemsDisableRefetchOnMount,
|
|
1594
|
+
isOffScreen: allItemsIsOffScreen,
|
|
1595
|
+
loadSize: allItemsLoadSize
|
|
1561
1596
|
} = {}) {
|
|
1562
1597
|
const queriesWithId = useDeepMemo(() => {
|
|
1563
1598
|
return queries.map((item) => {
|
|
1564
1599
|
return {
|
|
1565
1600
|
key: getQueryKey(item.payload),
|
|
1566
1601
|
payload: item.payload,
|
|
1567
|
-
disableRefetchOnMount: item.disableRefetchOnMount ?? globalDisableRefetchOnMount,
|
|
1568
|
-
returnIdleStatus: item.returnIdleStatus,
|
|
1569
|
-
returnRefetchingStatus: item.returnRefetchingStatus,
|
|
1602
|
+
disableRefetchOnMount: item.disableRefetchOnMount ?? allItemsDisableRefetchOnMount ?? globalDisableRefetchOnMount,
|
|
1603
|
+
returnIdleStatus: item.returnIdleStatus ?? allItemsReturnIdleStatus,
|
|
1604
|
+
returnRefetchingStatus: item.returnRefetchingStatus ?? allItemsReturnRefetchingStatus,
|
|
1570
1605
|
queryMetadata: item.queryMetadata,
|
|
1571
|
-
isOffScreen: item.isOffScreen,
|
|
1572
|
-
omitPayload: item.omitPayload,
|
|
1573
|
-
loadSize: item.loadSize
|
|
1606
|
+
isOffScreen: item.isOffScreen ?? allItemsIsOffScreen,
|
|
1607
|
+
omitPayload: item.omitPayload ?? allItemsOmitPayload,
|
|
1608
|
+
loadSize: item.loadSize ?? allItemsLoadSize
|
|
1574
1609
|
};
|
|
1575
1610
|
});
|
|
1576
|
-
}, [
|
|
1611
|
+
}, [
|
|
1612
|
+
allItemsDisableRefetchOnMount,
|
|
1613
|
+
allItemsIsOffScreen,
|
|
1614
|
+
allItemsLoadSize,
|
|
1615
|
+
allItemsOmitPayload,
|
|
1616
|
+
allItemsReturnIdleStatus,
|
|
1617
|
+
allItemsReturnRefetchingStatus,
|
|
1618
|
+
queries
|
|
1619
|
+
]);
|
|
1577
1620
|
const dataSelector = (0, import_react9.useCallback)(itemSelector, [
|
|
1578
1621
|
selectorUsesExternalDeps ? itemSelector : 0
|
|
1579
1622
|
]);
|
|
@@ -1860,70 +1903,19 @@ function newTSDFListQueryStore({
|
|
|
1860
1903
|
}
|
|
1861
1904
|
return [{ payload: itemsPayload, itemKey: getItemKey(itemsPayload) }];
|
|
1862
1905
|
}
|
|
1863
|
-
const itemInvalidationWasTriggered = /* @__PURE__ */ new Set();
|
|
1864
|
-
function invalidateItem(itemId, priority = "highPriority", ignoreInvalidationSync = false) {
|
|
1865
|
-
if (!fetchItemOrquestrator) {
|
|
1866
|
-
throw new Error(noFetchFnError);
|
|
1867
|
-
}
|
|
1868
|
-
const itemsKey = getItemsKeyArray(itemId);
|
|
1869
|
-
for (const { itemKey, payload } of itemsKey) {
|
|
1870
|
-
const item = store.state.itemQueries[itemKey];
|
|
1871
|
-
if (!item)
|
|
1872
|
-
continue;
|
|
1873
|
-
const currentInvalidationPriority = item.refetchOnMount ? fetchTypePriority[item.refetchOnMount] : -1;
|
|
1874
|
-
const newInvalidationPriority = fetchTypePriority[priority];
|
|
1875
|
-
if (currentInvalidationPriority >= newInvalidationPriority)
|
|
1876
|
-
continue;
|
|
1877
|
-
store.produceState(
|
|
1878
|
-
(draft) => {
|
|
1879
|
-
const query = draft.itemQueries[itemKey];
|
|
1880
|
-
if (!query)
|
|
1881
|
-
return;
|
|
1882
|
-
query.refetchOnMount = priority;
|
|
1883
|
-
},
|
|
1884
|
-
{ action: { type: "invalidate-item", queryKey: itemKey } }
|
|
1885
|
-
);
|
|
1886
|
-
itemInvalidationWasTriggered.delete(itemKey);
|
|
1887
|
-
storeEvents.emit("invalidateItem", { priority, itemKey });
|
|
1888
|
-
if (onInvalidateItem) {
|
|
1889
|
-
const itemState = store.state.items[itemKey];
|
|
1890
|
-
if (itemState) {
|
|
1891
|
-
onInvalidateItem({
|
|
1892
|
-
priority,
|
|
1893
|
-
itemState,
|
|
1894
|
-
payload
|
|
1895
|
-
});
|
|
1896
|
-
}
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
if (syncMutationsAndInvalidations && !ignoreInvalidationSync) {
|
|
1900
|
-
invalidateQuery(
|
|
1901
|
-
(query) => itemsKey.some(
|
|
1902
|
-
({ payload }) => syncMutationsAndInvalidations.syncItemAndQuery(payload, query)
|
|
1903
|
-
),
|
|
1904
|
-
priority,
|
|
1905
|
-
true
|
|
1906
|
-
);
|
|
1907
|
-
}
|
|
1908
|
-
}
|
|
1909
1906
|
function startItemMutation(itemId) {
|
|
1910
1907
|
const itemsKey = getItemsKeyArray(itemId);
|
|
1911
1908
|
const endMutations = [];
|
|
1912
|
-
for (const { itemKey
|
|
1909
|
+
for (const { itemKey } of itemsKey) {
|
|
1913
1910
|
endMutations.push(
|
|
1914
1911
|
fetchItemOrquestrator?.get(itemKey).startMutation() || (() => {
|
|
1915
1912
|
})
|
|
1916
1913
|
);
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
)) {
|
|
1923
|
-
endMutations.push(
|
|
1924
|
-
fetchQueryOrquestrator.get(queryKey).startMutation()
|
|
1925
|
-
);
|
|
1926
|
-
}
|
|
1914
|
+
for (const [queryKey, query] of Object.entries(store.state.queries)) {
|
|
1915
|
+
if (query.items.includes(itemKey)) {
|
|
1916
|
+
endMutations.push(
|
|
1917
|
+
fetchQueryOrquestrator.get(queryKey).startMutation()
|
|
1918
|
+
);
|
|
1927
1919
|
}
|
|
1928
1920
|
}
|
|
1929
1921
|
}
|
|
@@ -1939,7 +1931,11 @@ function newTSDFListQueryStore({
|
|
|
1939
1931
|
function useMultipleItems(items, {
|
|
1940
1932
|
selector = defaultItemDataSelector,
|
|
1941
1933
|
loadFromStateOnly,
|
|
1942
|
-
selectorUsesExternalDeps
|
|
1934
|
+
selectorUsesExternalDeps,
|
|
1935
|
+
returnIdleStatus: allItemsReturnIdleStatus,
|
|
1936
|
+
returnRefetchingStatus: allItemsReturnRefetchingStatus,
|
|
1937
|
+
disableRefetchOnMount: allItemsDisableRefetchOnMount,
|
|
1938
|
+
isOffScreen: allItemsIsOffScreen
|
|
1943
1939
|
} = {}) {
|
|
1944
1940
|
const dataSelector = (0, import_react9.useCallback)(selector, [
|
|
1945
1941
|
selectorUsesExternalDeps ? selector : 0
|
|
@@ -1949,14 +1945,20 @@ function newTSDFListQueryStore({
|
|
|
1949
1945
|
(itemPayload) => ({
|
|
1950
1946
|
itemKey: getItemKey(itemPayload.payload),
|
|
1951
1947
|
payload: itemPayload.payload,
|
|
1952
|
-
disableRefetchOnMount: itemPayload.disableRefetchOnMount,
|
|
1953
|
-
returnIdleStatus: itemPayload.returnIdleStatus,
|
|
1954
|
-
returnRefetchingStatus: itemPayload.returnRefetchingStatus,
|
|
1955
|
-
isOffScreen: itemPayload.isOffScreen,
|
|
1948
|
+
disableRefetchOnMount: itemPayload.disableRefetchOnMount ?? allItemsDisableRefetchOnMount,
|
|
1949
|
+
returnIdleStatus: itemPayload.returnIdleStatus ?? allItemsReturnIdleStatus,
|
|
1950
|
+
returnRefetchingStatus: itemPayload.returnRefetchingStatus ?? allItemsReturnRefetchingStatus,
|
|
1951
|
+
isOffScreen: itemPayload.isOffScreen ?? allItemsIsOffScreen,
|
|
1956
1952
|
queryMetadata: itemPayload.queryMetadata
|
|
1957
1953
|
})
|
|
1958
1954
|
),
|
|
1959
|
-
[
|
|
1955
|
+
[
|
|
1956
|
+
allItemsDisableRefetchOnMount,
|
|
1957
|
+
allItemsIsOffScreen,
|
|
1958
|
+
allItemsReturnIdleStatus,
|
|
1959
|
+
allItemsReturnRefetchingStatus,
|
|
1960
|
+
items
|
|
1961
|
+
]
|
|
1960
1962
|
);
|
|
1961
1963
|
const resultSelector = (0, import_react9.useCallback)(
|
|
1962
1964
|
(state) => {
|
|
@@ -2271,7 +2273,10 @@ function newTSDFListQueryStore({
|
|
|
2271
2273
|
}
|
|
2272
2274
|
});
|
|
2273
2275
|
if (queriesToInvalidate.length)
|
|
2274
|
-
|
|
2276
|
+
invalidateQueryAndItems({
|
|
2277
|
+
queryPayload: queriesToInvalidate,
|
|
2278
|
+
itemPayload: false
|
|
2279
|
+
});
|
|
2275
2280
|
}
|
|
2276
2281
|
function addItemToState(itemPayload, data, {
|
|
2277
2282
|
addItemToQueries
|
|
@@ -2354,8 +2359,7 @@ function newTSDFListQueryStore({
|
|
|
2354
2359
|
deleteItemState,
|
|
2355
2360
|
getItemState,
|
|
2356
2361
|
loadMore,
|
|
2357
|
-
|
|
2358
|
-
invalidateItem,
|
|
2362
|
+
invalidateQueryAndItems,
|
|
2359
2363
|
scheduleItemFetch,
|
|
2360
2364
|
awaitItemFetch,
|
|
2361
2365
|
awaitListQueryFetch,
|
package/dist/main.d.cts
CHANGED
|
@@ -120,9 +120,14 @@ declare function newTSDFCollectionStore<ItemState extends ValidStoreState, NErro
|
|
|
120
120
|
data: ItemState;
|
|
121
121
|
error: null;
|
|
122
122
|
}>;
|
|
123
|
-
useMultipleItems: <Selected = ItemState | null, QueryMetadata extends Record<string, unknown> | undefined = undefined>(items: CollectionUseMultipleItemsQuery<ItemPayload, QueryMetadata>[], { selector, selectorUsesExternalDeps, }?: {
|
|
123
|
+
useMultipleItems: <Selected = ItemState | null, QueryMetadata extends Record<string, unknown> | undefined = undefined>(items: CollectionUseMultipleItemsQuery<ItemPayload, QueryMetadata>[], { selector, selectorUsesExternalDeps, returnIdleStatus: allItemsReturnIdleStatus, returnRefetchingStatus: allItemsReturnRefetchingStatus, omitPayload: allItemsOmitPayload, disableRefetchOnMount: allItemsDisableRefetchOnMount, isOffScreen: allItemsIsOffScreen, }?: {
|
|
124
124
|
selector?: ((data: ItemState | null) => Selected) | undefined;
|
|
125
125
|
selectorUsesExternalDeps?: boolean | undefined;
|
|
126
|
+
returnIdleStatus?: boolean | undefined;
|
|
127
|
+
returnRefetchingStatus?: boolean | undefined;
|
|
128
|
+
omitPayload?: boolean | undefined;
|
|
129
|
+
disableRefetchOnMount?: boolean | undefined;
|
|
130
|
+
isOffScreen?: boolean | undefined;
|
|
126
131
|
}) => readonly TSFDUseCollectionItemReturn<Selected, ItemPayload, NError, QueryMetadata>[];
|
|
127
132
|
useItem: <Selected_1 = ItemState | null>(payload: ItemPayload | undefined | false | null, { omitPayload, selector, selectorUsesExternalDeps, ensureIsLoaded, returnRefetchingStatus, disableRefetchOnMount, returnIdleStatus, isOffScreen, }?: {
|
|
128
133
|
selector?: ((data: ItemState | null) => Selected_1) | undefined;
|
|
@@ -232,7 +237,7 @@ type ListQueryUseMultipleListQueriesQuery<QueryPayload extends ValidPayload, Que
|
|
|
232
237
|
isOffScreen?: boolean;
|
|
233
238
|
loadSize?: number;
|
|
234
239
|
};
|
|
235
|
-
declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload>({ debugName, fetchListFn, fetchItemFn, errorNormalizer, defaultQuerySize, getInitialData, disableRefetchOnMount: globalDisableRefetchOnMount, lowPriorityThrottleMs, disableInitialDataInvalidation, mediumPriorityThrottleMs, dynamicRealtimeThrottleMs,
|
|
240
|
+
declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload>({ debugName, fetchListFn, fetchItemFn, errorNormalizer, defaultQuerySize, getInitialData, disableRefetchOnMount: globalDisableRefetchOnMount, lowPriorityThrottleMs, disableInitialDataInvalidation, mediumPriorityThrottleMs, dynamicRealtimeThrottleMs, optimisticListUpdates, onInvalidateItem, onInvalidateQuery, }: {
|
|
236
241
|
debugName?: string;
|
|
237
242
|
fetchListFn: (payload: QueryPayload, size: number) => Promise<FetchListFnReturn<ItemState, ItemPayload>>;
|
|
238
243
|
fetchItemFn?: (itemId: ItemPayload) => Promise<ItemState>;
|
|
@@ -240,10 +245,6 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
240
245
|
defaultQuerySize?: number;
|
|
241
246
|
getInitialData?: () => ListQueryStoreInitialData<ItemState, QueryPayload, ItemPayload> | undefined;
|
|
242
247
|
disableInitialDataInvalidation?: boolean;
|
|
243
|
-
syncMutationsAndInvalidations?: {
|
|
244
|
-
syncQueries: (query1: QueryPayload, query2: QueryPayload) => boolean;
|
|
245
|
-
syncItemAndQuery: (itemPayload: ItemPayload, query: QueryPayload) => boolean;
|
|
246
|
-
};
|
|
247
248
|
disableRefetchOnMount?: boolean;
|
|
248
249
|
lowPriorityThrottleMs?: number;
|
|
249
250
|
mediumPriorityThrottleMs?: number;
|
|
@@ -280,8 +281,11 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
280
281
|
(itemPayload: ItemPayload): ItemState | null | undefined;
|
|
281
282
|
};
|
|
282
283
|
loadMore: (params: QueryPayload, size?: number) => ScheduleFetchResults;
|
|
283
|
-
|
|
284
|
-
|
|
284
|
+
invalidateQueryAndItems: ({ itemPayload, queryPayload, type: priority, }: {
|
|
285
|
+
itemPayload: false | ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[];
|
|
286
|
+
queryPayload: false | QueryPayload | QueryPayload[] | ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean);
|
|
287
|
+
type?: FetchType | undefined;
|
|
288
|
+
}) => void;
|
|
285
289
|
scheduleItemFetch: {
|
|
286
290
|
(fetchType: FetchType, itemPayload: ItemPayload): ScheduleFetchResults;
|
|
287
291
|
(fetchType: FetchType, itemPayload: ItemPayload[]): ScheduleFetchResults[];
|
|
@@ -306,9 +310,15 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
306
310
|
error: null;
|
|
307
311
|
hasMore: boolean;
|
|
308
312
|
}>;
|
|
309
|
-
useMultipleListQueries: <SelectedItem = ItemState, QueryMetadata extends Record<string, unknown> | undefined = undefined>(queries: ListQueryUseMultipleListQueriesQuery<QueryPayload, QueryMetadata>[], { itemSelector, selectorUsesExternalDeps, }?: {
|
|
313
|
+
useMultipleListQueries: <SelectedItem = ItemState, QueryMetadata extends Record<string, unknown> | undefined = undefined>(queries: ListQueryUseMultipleListQueriesQuery<QueryPayload, QueryMetadata>[], { itemSelector, selectorUsesExternalDeps, returnIdleStatus: allItemsReturnIdleStatus, returnRefetchingStatus: allItemsReturnRefetchingStatus, omitPayload: allItemsOmitPayload, disableRefetchOnMount: allItemsDisableRefetchOnMount, isOffScreen: allItemsIsOffScreen, loadSize: allItemsLoadSize, }?: {
|
|
310
314
|
itemSelector?: ((data: ItemState, id: ItemPayload, itemKey: string) => SelectedItem) | undefined;
|
|
311
315
|
selectorUsesExternalDeps?: boolean | undefined;
|
|
316
|
+
returnIdleStatus?: boolean | undefined;
|
|
317
|
+
returnRefetchingStatus?: boolean | undefined;
|
|
318
|
+
omitPayload?: boolean | undefined;
|
|
319
|
+
disableRefetchOnMount?: boolean | undefined;
|
|
320
|
+
isOffScreen?: boolean | undefined;
|
|
321
|
+
loadSize?: number | undefined;
|
|
312
322
|
}) => readonly TSFDUseListQueryReturn<SelectedItem, QueryPayload, NError, QueryMetadata>[];
|
|
313
323
|
useListQuery: <SelectedItem_1 = ItemState>(payload: QueryPayload | false | null | undefined, { isOffScreen, itemSelector, disableRefetchOnMount, returnIdleStatus, returnRefetchingStatus, loadSize, omitPayload, ensureIsLoaded, selectorUsesExternalDeps, }?: {
|
|
314
324
|
itemSelector?: ((data: ItemState, id: ItemPayload, itemKey: string) => SelectedItem_1) | undefined;
|
|
@@ -332,10 +342,14 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
332
342
|
loadFromStateOnly?: boolean | undefined;
|
|
333
343
|
isOffScreen?: boolean | undefined;
|
|
334
344
|
}) => TSFDUseListItemReturn<SelectedItem_2, NError, ItemPayload, undefined>;
|
|
335
|
-
useMultipleItems: <SelectedItem_3 = ItemState | null, QueryMetadata_1 extends Record<string, unknown> | undefined = undefined>(items: ListQueryUseMultipleItemsQuery<ItemPayload, QueryMetadata_1>[], { selector, loadFromStateOnly, selectorUsesExternalDeps, }?: {
|
|
345
|
+
useMultipleItems: <SelectedItem_3 = ItemState | null, QueryMetadata_1 extends Record<string, unknown> | undefined = undefined>(items: ListQueryUseMultipleItemsQuery<ItemPayload, QueryMetadata_1>[], { selector, loadFromStateOnly, selectorUsesExternalDeps, returnIdleStatus: allItemsReturnIdleStatus, returnRefetchingStatus: allItemsReturnRefetchingStatus, disableRefetchOnMount: allItemsDisableRefetchOnMount, isOffScreen: allItemsIsOffScreen, }?: {
|
|
336
346
|
loadFromStateOnly?: boolean | undefined;
|
|
337
347
|
selector?: ((data: ItemState | null, id: ItemPayload | null) => SelectedItem_3) | undefined;
|
|
338
348
|
selectorUsesExternalDeps?: boolean | undefined;
|
|
349
|
+
returnIdleStatus?: boolean | undefined;
|
|
350
|
+
returnRefetchingStatus?: boolean | undefined;
|
|
351
|
+
disableRefetchOnMount?: boolean | undefined;
|
|
352
|
+
isOffScreen?: boolean | undefined;
|
|
339
353
|
}) => readonly TSFDUseListItemReturn<SelectedItem_3, NError, ItemPayload, QueryMetadata_1>[];
|
|
340
354
|
addItemToState: (itemPayload: ItemPayload, data: ItemState, { addItemToQueries, }?: {
|
|
341
355
|
addItemToQueries?: {
|
package/dist/main.d.ts
CHANGED
|
@@ -120,9 +120,14 @@ declare function newTSDFCollectionStore<ItemState extends ValidStoreState, NErro
|
|
|
120
120
|
data: ItemState;
|
|
121
121
|
error: null;
|
|
122
122
|
}>;
|
|
123
|
-
useMultipleItems: <Selected = ItemState | null, QueryMetadata extends Record<string, unknown> | undefined = undefined>(items: CollectionUseMultipleItemsQuery<ItemPayload, QueryMetadata>[], { selector, selectorUsesExternalDeps, }?: {
|
|
123
|
+
useMultipleItems: <Selected = ItemState | null, QueryMetadata extends Record<string, unknown> | undefined = undefined>(items: CollectionUseMultipleItemsQuery<ItemPayload, QueryMetadata>[], { selector, selectorUsesExternalDeps, returnIdleStatus: allItemsReturnIdleStatus, returnRefetchingStatus: allItemsReturnRefetchingStatus, omitPayload: allItemsOmitPayload, disableRefetchOnMount: allItemsDisableRefetchOnMount, isOffScreen: allItemsIsOffScreen, }?: {
|
|
124
124
|
selector?: ((data: ItemState | null) => Selected) | undefined;
|
|
125
125
|
selectorUsesExternalDeps?: boolean | undefined;
|
|
126
|
+
returnIdleStatus?: boolean | undefined;
|
|
127
|
+
returnRefetchingStatus?: boolean | undefined;
|
|
128
|
+
omitPayload?: boolean | undefined;
|
|
129
|
+
disableRefetchOnMount?: boolean | undefined;
|
|
130
|
+
isOffScreen?: boolean | undefined;
|
|
126
131
|
}) => readonly TSFDUseCollectionItemReturn<Selected, ItemPayload, NError, QueryMetadata>[];
|
|
127
132
|
useItem: <Selected_1 = ItemState | null>(payload: ItemPayload | undefined | false | null, { omitPayload, selector, selectorUsesExternalDeps, ensureIsLoaded, returnRefetchingStatus, disableRefetchOnMount, returnIdleStatus, isOffScreen, }?: {
|
|
128
133
|
selector?: ((data: ItemState | null) => Selected_1) | undefined;
|
|
@@ -232,7 +237,7 @@ type ListQueryUseMultipleListQueriesQuery<QueryPayload extends ValidPayload, Que
|
|
|
232
237
|
isOffScreen?: boolean;
|
|
233
238
|
loadSize?: number;
|
|
234
239
|
};
|
|
235
|
-
declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload>({ debugName, fetchListFn, fetchItemFn, errorNormalizer, defaultQuerySize, getInitialData, disableRefetchOnMount: globalDisableRefetchOnMount, lowPriorityThrottleMs, disableInitialDataInvalidation, mediumPriorityThrottleMs, dynamicRealtimeThrottleMs,
|
|
240
|
+
declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload>({ debugName, fetchListFn, fetchItemFn, errorNormalizer, defaultQuerySize, getInitialData, disableRefetchOnMount: globalDisableRefetchOnMount, lowPriorityThrottleMs, disableInitialDataInvalidation, mediumPriorityThrottleMs, dynamicRealtimeThrottleMs, optimisticListUpdates, onInvalidateItem, onInvalidateQuery, }: {
|
|
236
241
|
debugName?: string;
|
|
237
242
|
fetchListFn: (payload: QueryPayload, size: number) => Promise<FetchListFnReturn<ItemState, ItemPayload>>;
|
|
238
243
|
fetchItemFn?: (itemId: ItemPayload) => Promise<ItemState>;
|
|
@@ -240,10 +245,6 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
240
245
|
defaultQuerySize?: number;
|
|
241
246
|
getInitialData?: () => ListQueryStoreInitialData<ItemState, QueryPayload, ItemPayload> | undefined;
|
|
242
247
|
disableInitialDataInvalidation?: boolean;
|
|
243
|
-
syncMutationsAndInvalidations?: {
|
|
244
|
-
syncQueries: (query1: QueryPayload, query2: QueryPayload) => boolean;
|
|
245
|
-
syncItemAndQuery: (itemPayload: ItemPayload, query: QueryPayload) => boolean;
|
|
246
|
-
};
|
|
247
248
|
disableRefetchOnMount?: boolean;
|
|
248
249
|
lowPriorityThrottleMs?: number;
|
|
249
250
|
mediumPriorityThrottleMs?: number;
|
|
@@ -280,8 +281,11 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
280
281
|
(itemPayload: ItemPayload): ItemState | null | undefined;
|
|
281
282
|
};
|
|
282
283
|
loadMore: (params: QueryPayload, size?: number) => ScheduleFetchResults;
|
|
283
|
-
|
|
284
|
-
|
|
284
|
+
invalidateQueryAndItems: ({ itemPayload, queryPayload, type: priority, }: {
|
|
285
|
+
itemPayload: false | ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[];
|
|
286
|
+
queryPayload: false | QueryPayload | QueryPayload[] | ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean);
|
|
287
|
+
type?: FetchType | undefined;
|
|
288
|
+
}) => void;
|
|
285
289
|
scheduleItemFetch: {
|
|
286
290
|
(fetchType: FetchType, itemPayload: ItemPayload): ScheduleFetchResults;
|
|
287
291
|
(fetchType: FetchType, itemPayload: ItemPayload[]): ScheduleFetchResults[];
|
|
@@ -306,9 +310,15 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
306
310
|
error: null;
|
|
307
311
|
hasMore: boolean;
|
|
308
312
|
}>;
|
|
309
|
-
useMultipleListQueries: <SelectedItem = ItemState, QueryMetadata extends Record<string, unknown> | undefined = undefined>(queries: ListQueryUseMultipleListQueriesQuery<QueryPayload, QueryMetadata>[], { itemSelector, selectorUsesExternalDeps, }?: {
|
|
313
|
+
useMultipleListQueries: <SelectedItem = ItemState, QueryMetadata extends Record<string, unknown> | undefined = undefined>(queries: ListQueryUseMultipleListQueriesQuery<QueryPayload, QueryMetadata>[], { itemSelector, selectorUsesExternalDeps, returnIdleStatus: allItemsReturnIdleStatus, returnRefetchingStatus: allItemsReturnRefetchingStatus, omitPayload: allItemsOmitPayload, disableRefetchOnMount: allItemsDisableRefetchOnMount, isOffScreen: allItemsIsOffScreen, loadSize: allItemsLoadSize, }?: {
|
|
310
314
|
itemSelector?: ((data: ItemState, id: ItemPayload, itemKey: string) => SelectedItem) | undefined;
|
|
311
315
|
selectorUsesExternalDeps?: boolean | undefined;
|
|
316
|
+
returnIdleStatus?: boolean | undefined;
|
|
317
|
+
returnRefetchingStatus?: boolean | undefined;
|
|
318
|
+
omitPayload?: boolean | undefined;
|
|
319
|
+
disableRefetchOnMount?: boolean | undefined;
|
|
320
|
+
isOffScreen?: boolean | undefined;
|
|
321
|
+
loadSize?: number | undefined;
|
|
312
322
|
}) => readonly TSFDUseListQueryReturn<SelectedItem, QueryPayload, NError, QueryMetadata>[];
|
|
313
323
|
useListQuery: <SelectedItem_1 = ItemState>(payload: QueryPayload | false | null | undefined, { isOffScreen, itemSelector, disableRefetchOnMount, returnIdleStatus, returnRefetchingStatus, loadSize, omitPayload, ensureIsLoaded, selectorUsesExternalDeps, }?: {
|
|
314
324
|
itemSelector?: ((data: ItemState, id: ItemPayload, itemKey: string) => SelectedItem_1) | undefined;
|
|
@@ -332,10 +342,14 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
332
342
|
loadFromStateOnly?: boolean | undefined;
|
|
333
343
|
isOffScreen?: boolean | undefined;
|
|
334
344
|
}) => TSFDUseListItemReturn<SelectedItem_2, NError, ItemPayload, undefined>;
|
|
335
|
-
useMultipleItems: <SelectedItem_3 = ItemState | null, QueryMetadata_1 extends Record<string, unknown> | undefined = undefined>(items: ListQueryUseMultipleItemsQuery<ItemPayload, QueryMetadata_1>[], { selector, loadFromStateOnly, selectorUsesExternalDeps, }?: {
|
|
345
|
+
useMultipleItems: <SelectedItem_3 = ItemState | null, QueryMetadata_1 extends Record<string, unknown> | undefined = undefined>(items: ListQueryUseMultipleItemsQuery<ItemPayload, QueryMetadata_1>[], { selector, loadFromStateOnly, selectorUsesExternalDeps, returnIdleStatus: allItemsReturnIdleStatus, returnRefetchingStatus: allItemsReturnRefetchingStatus, disableRefetchOnMount: allItemsDisableRefetchOnMount, isOffScreen: allItemsIsOffScreen, }?: {
|
|
336
346
|
loadFromStateOnly?: boolean | undefined;
|
|
337
347
|
selector?: ((data: ItemState | null, id: ItemPayload | null) => SelectedItem_3) | undefined;
|
|
338
348
|
selectorUsesExternalDeps?: boolean | undefined;
|
|
349
|
+
returnIdleStatus?: boolean | undefined;
|
|
350
|
+
returnRefetchingStatus?: boolean | undefined;
|
|
351
|
+
disableRefetchOnMount?: boolean | undefined;
|
|
352
|
+
isOffScreen?: boolean | undefined;
|
|
339
353
|
}) => readonly TSFDUseListItemReturn<SelectedItem_3, NError, ItemPayload, QueryMetadata_1>[];
|
|
340
354
|
addItemToState: (itemPayload: ItemPayload, data: ItemState, { addItemToQueries, }?: {
|
|
341
355
|
addItemToQueries?: {
|
package/dist/main.js
CHANGED
|
@@ -850,29 +850,41 @@ function newTSDFCollectionStore({
|
|
|
850
850
|
}
|
|
851
851
|
function useMultipleItems(items, {
|
|
852
852
|
selector,
|
|
853
|
-
selectorUsesExternalDeps
|
|
853
|
+
selectorUsesExternalDeps,
|
|
854
|
+
returnIdleStatus: allItemsReturnIdleStatus,
|
|
855
|
+
returnRefetchingStatus: allItemsReturnRefetchingStatus,
|
|
856
|
+
omitPayload: allItemsOmitPayload,
|
|
857
|
+
disableRefetchOnMount: allItemsDisableRefetchOnMount,
|
|
858
|
+
isOffScreen: allItemsIsOffScreen
|
|
854
859
|
} = {}) {
|
|
855
860
|
const queriesWithId = useDeepMemo(() => {
|
|
856
861
|
return items.map((queryProps) => {
|
|
857
862
|
return {
|
|
858
863
|
itemKey: getItemKey(queryProps.payload),
|
|
859
864
|
payload: queryProps.payload,
|
|
860
|
-
disableRefetchOnMount: queryProps.disableRefetchOnMount ?? globalDisableRefetchOnMount,
|
|
861
|
-
returnIdleStatus: queryProps.returnIdleStatus,
|
|
862
|
-
returnRefetchingStatus: queryProps.returnRefetchingStatus,
|
|
863
|
-
omitPayload: queryProps.omitPayload,
|
|
864
|
-
isOffScreen: queryProps.isOffScreen,
|
|
865
|
+
disableRefetchOnMount: queryProps.disableRefetchOnMount ?? allItemsDisableRefetchOnMount ?? globalDisableRefetchOnMount,
|
|
866
|
+
returnIdleStatus: queryProps.returnIdleStatus ?? allItemsReturnIdleStatus,
|
|
867
|
+
returnRefetchingStatus: queryProps.returnRefetchingStatus ?? allItemsReturnRefetchingStatus,
|
|
868
|
+
omitPayload: queryProps.omitPayload ?? allItemsOmitPayload,
|
|
869
|
+
isOffScreen: queryProps.isOffScreen ?? allItemsIsOffScreen,
|
|
865
870
|
queryMetadata: queryProps.queryMetadata
|
|
866
871
|
};
|
|
867
872
|
});
|
|
868
|
-
}, [
|
|
873
|
+
}, [
|
|
874
|
+
items,
|
|
875
|
+
allItemsDisableRefetchOnMount,
|
|
876
|
+
allItemsIsOffScreen,
|
|
877
|
+
allItemsOmitPayload,
|
|
878
|
+
allItemsReturnIdleStatus,
|
|
879
|
+
allItemsReturnRefetchingStatus
|
|
880
|
+
]);
|
|
869
881
|
const dataSelector = useCallback2(
|
|
870
882
|
(itemState) => {
|
|
871
883
|
if (selector)
|
|
872
884
|
return selector(itemState);
|
|
873
885
|
return itemState;
|
|
874
886
|
},
|
|
875
|
-
// eslint-disable-next-line
|
|
887
|
+
// eslint-disable-next-line @lucasols/extended-lint/exhaustive-deps
|
|
876
888
|
[selectorUsesExternalDeps ? selector : 0]
|
|
877
889
|
);
|
|
878
890
|
const resultSelector = useCallback2(
|
|
@@ -1029,7 +1041,7 @@ function newTSDFCollectionStore({
|
|
|
1029
1041
|
isLoading: false,
|
|
1030
1042
|
queryMetadata: void 0
|
|
1031
1043
|
},
|
|
1032
|
-
// eslint-disable-next-line
|
|
1044
|
+
// eslint-disable-next-line @lucasols/extended-lint/exhaustive-deps
|
|
1033
1045
|
[item]
|
|
1034
1046
|
);
|
|
1035
1047
|
const [useModifyResult, emitIsLoadedEvt] = useEnsureIsLoaded(
|
|
@@ -1198,7 +1210,6 @@ function newTSDFListQueryStore({
|
|
|
1198
1210
|
disableInitialDataInvalidation,
|
|
1199
1211
|
mediumPriorityThrottleMs,
|
|
1200
1212
|
dynamicRealtimeThrottleMs,
|
|
1201
|
-
syncMutationsAndInvalidations,
|
|
1202
1213
|
optimisticListUpdates,
|
|
1203
1214
|
onInvalidateItem,
|
|
1204
1215
|
onInvalidateQuery
|
|
@@ -1475,9 +1486,46 @@ function newTSDFListQueryStore({
|
|
|
1475
1486
|
}
|
|
1476
1487
|
}
|
|
1477
1488
|
const storeEvents = evtmitter4();
|
|
1489
|
+
const itemInvalidationWasTriggered = /* @__PURE__ */ new Set();
|
|
1490
|
+
function invalidateItem(itemId, priority = "highPriority") {
|
|
1491
|
+
if (!fetchItemOrquestrator) {
|
|
1492
|
+
throw new Error(noFetchFnError);
|
|
1493
|
+
}
|
|
1494
|
+
const itemsKey = getItemsKeyArray(itemId);
|
|
1495
|
+
for (const { itemKey, payload } of itemsKey) {
|
|
1496
|
+
const item = store.state.itemQueries[itemKey];
|
|
1497
|
+
if (!item)
|
|
1498
|
+
continue;
|
|
1499
|
+
const currentInvalidationPriority = item.refetchOnMount ? fetchTypePriority[item.refetchOnMount] : -1;
|
|
1500
|
+
const newInvalidationPriority = fetchTypePriority[priority];
|
|
1501
|
+
if (currentInvalidationPriority >= newInvalidationPriority)
|
|
1502
|
+
continue;
|
|
1503
|
+
store.produceState(
|
|
1504
|
+
(draft) => {
|
|
1505
|
+
const query = draft.itemQueries[itemKey];
|
|
1506
|
+
if (!query)
|
|
1507
|
+
return;
|
|
1508
|
+
query.refetchOnMount = priority;
|
|
1509
|
+
},
|
|
1510
|
+
{ action: { type: "invalidate-item", queryKey: itemKey } }
|
|
1511
|
+
);
|
|
1512
|
+
itemInvalidationWasTriggered.delete(itemKey);
|
|
1513
|
+
storeEvents.emit("invalidateItem", { priority, itemKey });
|
|
1514
|
+
if (onInvalidateItem) {
|
|
1515
|
+
const itemState = store.state.items[itemKey];
|
|
1516
|
+
if (itemState) {
|
|
1517
|
+
onInvalidateItem({ priority, itemState, payload });
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1478
1522
|
const queryInvalidationWasTriggered = /* @__PURE__ */ new Set();
|
|
1479
|
-
function
|
|
1480
|
-
|
|
1523
|
+
function invalidateQueryAndItems({
|
|
1524
|
+
itemPayload,
|
|
1525
|
+
queryPayload,
|
|
1526
|
+
type: priority = "highPriority"
|
|
1527
|
+
}) {
|
|
1528
|
+
const queriesKey = queryPayload ? getQueriesKeyArray(queryPayload) : [];
|
|
1481
1529
|
for (const { key, payload } of queriesKey) {
|
|
1482
1530
|
const queryState = store.state.queries[key];
|
|
1483
1531
|
if (!queryState)
|
|
@@ -1499,27 +1547,8 @@ function newTSDFListQueryStore({
|
|
|
1499
1547
|
storeEvents.emit("invalidateQuery", { priority, queryKey: key });
|
|
1500
1548
|
onInvalidateQuery?.(payload, priority);
|
|
1501
1549
|
}
|
|
1502
|
-
if (
|
|
1503
|
-
invalidateItem(
|
|
1504
|
-
(itemPayload) => queriesKey.some(({ payload }) => {
|
|
1505
|
-
return syncMutationsAndInvalidations.syncItemAndQuery(
|
|
1506
|
-
itemPayload,
|
|
1507
|
-
payload
|
|
1508
|
-
);
|
|
1509
|
-
}),
|
|
1510
|
-
priority,
|
|
1511
|
-
true
|
|
1512
|
-
);
|
|
1513
|
-
invalidateQuery(
|
|
1514
|
-
(queryToInvalidatePayload, _, queryToInvalidateKey) => queriesKey.some((alreadyInvalidatedQueryPayload) => {
|
|
1515
|
-
return queryToInvalidateKey !== alreadyInvalidatedQueryPayload.key && syncMutationsAndInvalidations.syncQueries(
|
|
1516
|
-
alreadyInvalidatedQueryPayload.payload,
|
|
1517
|
-
queryToInvalidatePayload
|
|
1518
|
-
);
|
|
1519
|
-
}),
|
|
1520
|
-
priority,
|
|
1521
|
-
true
|
|
1522
|
-
);
|
|
1550
|
+
if (itemPayload) {
|
|
1551
|
+
invalidateItem(itemPayload, priority);
|
|
1523
1552
|
}
|
|
1524
1553
|
}
|
|
1525
1554
|
function defaultItemSelector(data) {
|
|
@@ -1527,23 +1556,37 @@ function newTSDFListQueryStore({
|
|
|
1527
1556
|
}
|
|
1528
1557
|
function useMultipleListQueries(queries, {
|
|
1529
1558
|
itemSelector = defaultItemSelector,
|
|
1530
|
-
selectorUsesExternalDeps
|
|
1559
|
+
selectorUsesExternalDeps,
|
|
1560
|
+
returnIdleStatus: allItemsReturnIdleStatus,
|
|
1561
|
+
returnRefetchingStatus: allItemsReturnRefetchingStatus,
|
|
1562
|
+
omitPayload: allItemsOmitPayload,
|
|
1563
|
+
disableRefetchOnMount: allItemsDisableRefetchOnMount,
|
|
1564
|
+
isOffScreen: allItemsIsOffScreen,
|
|
1565
|
+
loadSize: allItemsLoadSize
|
|
1531
1566
|
} = {}) {
|
|
1532
1567
|
const queriesWithId = useDeepMemo(() => {
|
|
1533
1568
|
return queries.map((item) => {
|
|
1534
1569
|
return {
|
|
1535
1570
|
key: getQueryKey(item.payload),
|
|
1536
1571
|
payload: item.payload,
|
|
1537
|
-
disableRefetchOnMount: item.disableRefetchOnMount ?? globalDisableRefetchOnMount,
|
|
1538
|
-
returnIdleStatus: item.returnIdleStatus,
|
|
1539
|
-
returnRefetchingStatus: item.returnRefetchingStatus,
|
|
1572
|
+
disableRefetchOnMount: item.disableRefetchOnMount ?? allItemsDisableRefetchOnMount ?? globalDisableRefetchOnMount,
|
|
1573
|
+
returnIdleStatus: item.returnIdleStatus ?? allItemsReturnIdleStatus,
|
|
1574
|
+
returnRefetchingStatus: item.returnRefetchingStatus ?? allItemsReturnRefetchingStatus,
|
|
1540
1575
|
queryMetadata: item.queryMetadata,
|
|
1541
|
-
isOffScreen: item.isOffScreen,
|
|
1542
|
-
omitPayload: item.omitPayload,
|
|
1543
|
-
loadSize: item.loadSize
|
|
1576
|
+
isOffScreen: item.isOffScreen ?? allItemsIsOffScreen,
|
|
1577
|
+
omitPayload: item.omitPayload ?? allItemsOmitPayload,
|
|
1578
|
+
loadSize: item.loadSize ?? allItemsLoadSize
|
|
1544
1579
|
};
|
|
1545
1580
|
});
|
|
1546
|
-
}, [
|
|
1581
|
+
}, [
|
|
1582
|
+
allItemsDisableRefetchOnMount,
|
|
1583
|
+
allItemsIsOffScreen,
|
|
1584
|
+
allItemsLoadSize,
|
|
1585
|
+
allItemsOmitPayload,
|
|
1586
|
+
allItemsReturnIdleStatus,
|
|
1587
|
+
allItemsReturnRefetchingStatus,
|
|
1588
|
+
queries
|
|
1589
|
+
]);
|
|
1547
1590
|
const dataSelector = useCallback3(itemSelector, [
|
|
1548
1591
|
selectorUsesExternalDeps ? itemSelector : 0
|
|
1549
1592
|
]);
|
|
@@ -1830,70 +1873,19 @@ function newTSDFListQueryStore({
|
|
|
1830
1873
|
}
|
|
1831
1874
|
return [{ payload: itemsPayload, itemKey: getItemKey(itemsPayload) }];
|
|
1832
1875
|
}
|
|
1833
|
-
const itemInvalidationWasTriggered = /* @__PURE__ */ new Set();
|
|
1834
|
-
function invalidateItem(itemId, priority = "highPriority", ignoreInvalidationSync = false) {
|
|
1835
|
-
if (!fetchItemOrquestrator) {
|
|
1836
|
-
throw new Error(noFetchFnError);
|
|
1837
|
-
}
|
|
1838
|
-
const itemsKey = getItemsKeyArray(itemId);
|
|
1839
|
-
for (const { itemKey, payload } of itemsKey) {
|
|
1840
|
-
const item = store.state.itemQueries[itemKey];
|
|
1841
|
-
if (!item)
|
|
1842
|
-
continue;
|
|
1843
|
-
const currentInvalidationPriority = item.refetchOnMount ? fetchTypePriority[item.refetchOnMount] : -1;
|
|
1844
|
-
const newInvalidationPriority = fetchTypePriority[priority];
|
|
1845
|
-
if (currentInvalidationPriority >= newInvalidationPriority)
|
|
1846
|
-
continue;
|
|
1847
|
-
store.produceState(
|
|
1848
|
-
(draft) => {
|
|
1849
|
-
const query = draft.itemQueries[itemKey];
|
|
1850
|
-
if (!query)
|
|
1851
|
-
return;
|
|
1852
|
-
query.refetchOnMount = priority;
|
|
1853
|
-
},
|
|
1854
|
-
{ action: { type: "invalidate-item", queryKey: itemKey } }
|
|
1855
|
-
);
|
|
1856
|
-
itemInvalidationWasTriggered.delete(itemKey);
|
|
1857
|
-
storeEvents.emit("invalidateItem", { priority, itemKey });
|
|
1858
|
-
if (onInvalidateItem) {
|
|
1859
|
-
const itemState = store.state.items[itemKey];
|
|
1860
|
-
if (itemState) {
|
|
1861
|
-
onInvalidateItem({
|
|
1862
|
-
priority,
|
|
1863
|
-
itemState,
|
|
1864
|
-
payload
|
|
1865
|
-
});
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
if (syncMutationsAndInvalidations && !ignoreInvalidationSync) {
|
|
1870
|
-
invalidateQuery(
|
|
1871
|
-
(query) => itemsKey.some(
|
|
1872
|
-
({ payload }) => syncMutationsAndInvalidations.syncItemAndQuery(payload, query)
|
|
1873
|
-
),
|
|
1874
|
-
priority,
|
|
1875
|
-
true
|
|
1876
|
-
);
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
1876
|
function startItemMutation(itemId) {
|
|
1880
1877
|
const itemsKey = getItemsKeyArray(itemId);
|
|
1881
1878
|
const endMutations = [];
|
|
1882
|
-
for (const { itemKey
|
|
1879
|
+
for (const { itemKey } of itemsKey) {
|
|
1883
1880
|
endMutations.push(
|
|
1884
1881
|
fetchItemOrquestrator?.get(itemKey).startMutation() || (() => {
|
|
1885
1882
|
})
|
|
1886
1883
|
);
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
)) {
|
|
1893
|
-
endMutations.push(
|
|
1894
|
-
fetchQueryOrquestrator.get(queryKey).startMutation()
|
|
1895
|
-
);
|
|
1896
|
-
}
|
|
1884
|
+
for (const [queryKey, query] of Object.entries(store.state.queries)) {
|
|
1885
|
+
if (query.items.includes(itemKey)) {
|
|
1886
|
+
endMutations.push(
|
|
1887
|
+
fetchQueryOrquestrator.get(queryKey).startMutation()
|
|
1888
|
+
);
|
|
1897
1889
|
}
|
|
1898
1890
|
}
|
|
1899
1891
|
}
|
|
@@ -1909,7 +1901,11 @@ function newTSDFListQueryStore({
|
|
|
1909
1901
|
function useMultipleItems(items, {
|
|
1910
1902
|
selector = defaultItemDataSelector,
|
|
1911
1903
|
loadFromStateOnly,
|
|
1912
|
-
selectorUsesExternalDeps
|
|
1904
|
+
selectorUsesExternalDeps,
|
|
1905
|
+
returnIdleStatus: allItemsReturnIdleStatus,
|
|
1906
|
+
returnRefetchingStatus: allItemsReturnRefetchingStatus,
|
|
1907
|
+
disableRefetchOnMount: allItemsDisableRefetchOnMount,
|
|
1908
|
+
isOffScreen: allItemsIsOffScreen
|
|
1913
1909
|
} = {}) {
|
|
1914
1910
|
const dataSelector = useCallback3(selector, [
|
|
1915
1911
|
selectorUsesExternalDeps ? selector : 0
|
|
@@ -1919,14 +1915,20 @@ function newTSDFListQueryStore({
|
|
|
1919
1915
|
(itemPayload) => ({
|
|
1920
1916
|
itemKey: getItemKey(itemPayload.payload),
|
|
1921
1917
|
payload: itemPayload.payload,
|
|
1922
|
-
disableRefetchOnMount: itemPayload.disableRefetchOnMount,
|
|
1923
|
-
returnIdleStatus: itemPayload.returnIdleStatus,
|
|
1924
|
-
returnRefetchingStatus: itemPayload.returnRefetchingStatus,
|
|
1925
|
-
isOffScreen: itemPayload.isOffScreen,
|
|
1918
|
+
disableRefetchOnMount: itemPayload.disableRefetchOnMount ?? allItemsDisableRefetchOnMount,
|
|
1919
|
+
returnIdleStatus: itemPayload.returnIdleStatus ?? allItemsReturnIdleStatus,
|
|
1920
|
+
returnRefetchingStatus: itemPayload.returnRefetchingStatus ?? allItemsReturnRefetchingStatus,
|
|
1921
|
+
isOffScreen: itemPayload.isOffScreen ?? allItemsIsOffScreen,
|
|
1926
1922
|
queryMetadata: itemPayload.queryMetadata
|
|
1927
1923
|
})
|
|
1928
1924
|
),
|
|
1929
|
-
[
|
|
1925
|
+
[
|
|
1926
|
+
allItemsDisableRefetchOnMount,
|
|
1927
|
+
allItemsIsOffScreen,
|
|
1928
|
+
allItemsReturnIdleStatus,
|
|
1929
|
+
allItemsReturnRefetchingStatus,
|
|
1930
|
+
items
|
|
1931
|
+
]
|
|
1930
1932
|
);
|
|
1931
1933
|
const resultSelector = useCallback3(
|
|
1932
1934
|
(state) => {
|
|
@@ -2241,7 +2243,10 @@ function newTSDFListQueryStore({
|
|
|
2241
2243
|
}
|
|
2242
2244
|
});
|
|
2243
2245
|
if (queriesToInvalidate.length)
|
|
2244
|
-
|
|
2246
|
+
invalidateQueryAndItems({
|
|
2247
|
+
queryPayload: queriesToInvalidate,
|
|
2248
|
+
itemPayload: false
|
|
2249
|
+
});
|
|
2245
2250
|
}
|
|
2246
2251
|
function addItemToState(itemPayload, data, {
|
|
2247
2252
|
addItemToQueries
|
|
@@ -2324,8 +2329,7 @@ function newTSDFListQueryStore({
|
|
|
2324
2329
|
deleteItemState,
|
|
2325
2330
|
getItemState,
|
|
2326
2331
|
loadMore,
|
|
2327
|
-
|
|
2328
|
-
invalidateItem,
|
|
2332
|
+
invalidateQueryAndItems,
|
|
2329
2333
|
scheduleItemFetch,
|
|
2330
2334
|
awaitItemFetch,
|
|
2331
2335
|
awaitListQueryFetch,
|