tsdf 12.8.0 → 14.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 +263 -114
- package/dist/main.d.cts +53 -32
- package/dist/main.d.ts +53 -32
- package/dist/main.js +263 -114
- package/package.json +2 -2
package/dist/main.js
CHANGED
|
@@ -848,30 +848,43 @@ function newTSDFCollectionStore({
|
|
|
848
848
|
}
|
|
849
849
|
return store.state[getItemKey(params)];
|
|
850
850
|
}
|
|
851
|
-
function useMultipleItems(
|
|
851
|
+
function useMultipleItems(items, {
|
|
852
852
|
selector,
|
|
853
|
-
|
|
854
|
-
returnIdleStatus,
|
|
855
|
-
returnRefetchingStatus,
|
|
856
|
-
disableRefetchOnMount = globalDisableRefetchOnMount,
|
|
857
|
-
isOffScreen
|
|
853
|
+
selectorUsesExternalDeps
|
|
858
854
|
} = {}) {
|
|
859
855
|
const queriesWithId = useDeepMemo(() => {
|
|
860
|
-
return
|
|
861
|
-
return {
|
|
856
|
+
return items.map((queryProps) => {
|
|
857
|
+
return {
|
|
858
|
+
itemKey: getItemKey(queryProps.payload),
|
|
859
|
+
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
|
+
queryMetadata: queryProps.queryMetadata
|
|
866
|
+
};
|
|
862
867
|
});
|
|
863
|
-
}, [
|
|
864
|
-
const dataSelector = useCallback2(
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
868
|
+
}, [items]);
|
|
869
|
+
const dataSelector = useCallback2(
|
|
870
|
+
(itemState) => {
|
|
871
|
+
if (selector)
|
|
872
|
+
return selector(itemState);
|
|
873
|
+
return itemState;
|
|
874
|
+
},
|
|
875
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
876
|
+
[selectorUsesExternalDeps ? selector : 0]
|
|
877
|
+
);
|
|
869
878
|
const resultSelector = useCallback2(
|
|
870
879
|
(state) => {
|
|
871
880
|
return queriesWithId.map(
|
|
872
881
|
({
|
|
873
882
|
itemKey,
|
|
874
|
-
payload
|
|
883
|
+
payload,
|
|
884
|
+
omitPayload,
|
|
885
|
+
returnIdleStatus,
|
|
886
|
+
returnRefetchingStatus,
|
|
887
|
+
queryMetadata
|
|
875
888
|
}) => {
|
|
876
889
|
const item = state[itemKey];
|
|
877
890
|
if (item === null) {
|
|
@@ -881,7 +894,8 @@ function newTSDFCollectionStore({
|
|
|
881
894
|
data: dataSelector(null),
|
|
882
895
|
error: null,
|
|
883
896
|
payload: omitPayload ? void 0 : payload,
|
|
884
|
-
isLoading: false
|
|
897
|
+
isLoading: false,
|
|
898
|
+
queryMetadata
|
|
885
899
|
};
|
|
886
900
|
}
|
|
887
901
|
if (!item) {
|
|
@@ -891,7 +905,8 @@ function newTSDFCollectionStore({
|
|
|
891
905
|
data: dataSelector(null),
|
|
892
906
|
error: null,
|
|
893
907
|
payload: omitPayload ? void 0 : payload,
|
|
894
|
-
isLoading: returnIdleStatus ? false : true
|
|
908
|
+
isLoading: returnIdleStatus ? false : true,
|
|
909
|
+
queryMetadata
|
|
895
910
|
};
|
|
896
911
|
}
|
|
897
912
|
let status = item.status;
|
|
@@ -904,27 +919,22 @@ function newTSDFCollectionStore({
|
|
|
904
919
|
data: dataSelector(item.data),
|
|
905
920
|
error: item.error,
|
|
906
921
|
isLoading: status === "loading",
|
|
907
|
-
payload: omitPayload ? void 0 : item.payload
|
|
922
|
+
payload: omitPayload ? void 0 : item.payload,
|
|
923
|
+
queryMetadata
|
|
908
924
|
};
|
|
909
925
|
}
|
|
910
926
|
);
|
|
911
927
|
},
|
|
912
|
-
[
|
|
913
|
-
dataSelector,
|
|
914
|
-
omitPayload,
|
|
915
|
-
queriesWithId,
|
|
916
|
-
returnIdleStatus,
|
|
917
|
-
returnRefetchingStatus
|
|
918
|
-
]
|
|
928
|
+
[dataSelector, queriesWithId]
|
|
919
929
|
);
|
|
920
930
|
const storeState = store.useSelector(resultSelector, {
|
|
921
931
|
equalityFn: deepEqual3,
|
|
922
932
|
useExternalDeps: true
|
|
923
933
|
});
|
|
924
934
|
useOnEvtmitterEvent3(storeEvents, "invalidateData", (event) => {
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
935
|
+
for (const { itemKey, payload, isOffScreen } of queriesWithId) {
|
|
936
|
+
if (isOffScreen)
|
|
937
|
+
continue;
|
|
928
938
|
if (itemKey !== event.itemKey)
|
|
929
939
|
continue;
|
|
930
940
|
if (!invalidationWasTriggered.has(itemKey)) {
|
|
@@ -939,15 +949,27 @@ function newTSDFCollectionStore({
|
|
|
939
949
|
}
|
|
940
950
|
}
|
|
941
951
|
});
|
|
952
|
+
const ignoreItemsInRefetchOnMount = useConst(() => /* @__PURE__ */ new Set());
|
|
942
953
|
useEffect3(() => {
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
954
|
+
const removedQueries = new Set(ignoreItemsInRefetchOnMount);
|
|
955
|
+
for (const {
|
|
956
|
+
itemKey: itemId,
|
|
957
|
+
payload,
|
|
958
|
+
isOffScreen,
|
|
959
|
+
disableRefetchOnMount
|
|
960
|
+
} of queriesWithId) {
|
|
961
|
+
removedQueries.delete(itemId);
|
|
962
|
+
if (isOffScreen)
|
|
963
|
+
continue;
|
|
946
964
|
if (itemId) {
|
|
947
965
|
const itemState = getItemState(payload);
|
|
948
966
|
const fetchType = itemState?.refetchOnMount || "lowPriority";
|
|
967
|
+
const shouldFetch = !itemState?.wasLoaded || itemState.refetchOnMount;
|
|
968
|
+
if (!shouldFetch && ignoreItemsInRefetchOnMount.has(itemId)) {
|
|
969
|
+
continue;
|
|
970
|
+
}
|
|
971
|
+
ignoreItemsInRefetchOnMount.add(itemId);
|
|
949
972
|
if (disableRefetchOnMount) {
|
|
950
|
-
const shouldFetch = !itemState?.wasLoaded || itemState.refetchOnMount;
|
|
951
973
|
if (shouldFetch) {
|
|
952
974
|
scheduleFetch(fetchType, payload);
|
|
953
975
|
continue;
|
|
@@ -957,16 +979,46 @@ function newTSDFCollectionStore({
|
|
|
957
979
|
}
|
|
958
980
|
}
|
|
959
981
|
}
|
|
960
|
-
|
|
982
|
+
for (const itemId of removedQueries) {
|
|
983
|
+
ignoreItemsInRefetchOnMount.delete(itemId);
|
|
984
|
+
}
|
|
985
|
+
}, [ignoreItemsInRefetchOnMount, queriesWithId]);
|
|
961
986
|
return storeState;
|
|
962
987
|
}
|
|
963
|
-
function useItem(payload,
|
|
964
|
-
|
|
988
|
+
function useItem(payload, {
|
|
989
|
+
omitPayload,
|
|
990
|
+
selector,
|
|
991
|
+
selectorUsesExternalDeps,
|
|
992
|
+
ensureIsLoaded,
|
|
993
|
+
returnRefetchingStatus,
|
|
994
|
+
disableRefetchOnMount,
|
|
995
|
+
returnIdleStatus,
|
|
996
|
+
isOffScreen
|
|
997
|
+
} = {}) {
|
|
965
998
|
const query = useMemo3(
|
|
966
|
-
() => payload === false || payload === null || payload === void 0 ? [] : [
|
|
967
|
-
|
|
999
|
+
() => payload === false || payload === null || payload === void 0 ? [] : [
|
|
1000
|
+
{
|
|
1001
|
+
payload,
|
|
1002
|
+
omitPayload,
|
|
1003
|
+
returnRefetchingStatus,
|
|
1004
|
+
disableRefetchOnMount,
|
|
1005
|
+
returnIdleStatus,
|
|
1006
|
+
isOffScreen
|
|
1007
|
+
}
|
|
1008
|
+
],
|
|
1009
|
+
[
|
|
1010
|
+
disableRefetchOnMount,
|
|
1011
|
+
isOffScreen,
|
|
1012
|
+
omitPayload,
|
|
1013
|
+
returnIdleStatus,
|
|
1014
|
+
returnRefetchingStatus,
|
|
1015
|
+
payload
|
|
1016
|
+
]
|
|
968
1017
|
);
|
|
969
|
-
const item = useMultipleItems(query,
|
|
1018
|
+
const item = useMultipleItems(query, {
|
|
1019
|
+
selector,
|
|
1020
|
+
selectorUsesExternalDeps
|
|
1021
|
+
});
|
|
970
1022
|
const result = useMemo3(
|
|
971
1023
|
() => item[0] ?? {
|
|
972
1024
|
payload: void 0,
|
|
@@ -974,7 +1026,8 @@ function newTSDFCollectionStore({
|
|
|
974
1026
|
error: null,
|
|
975
1027
|
status: "idle",
|
|
976
1028
|
itemStateKey: "",
|
|
977
|
-
isLoading: false
|
|
1029
|
+
isLoading: false,
|
|
1030
|
+
queryMetadata: void 0
|
|
978
1031
|
},
|
|
979
1032
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
980
1033
|
[item]
|
|
@@ -1474,28 +1527,36 @@ function newTSDFListQueryStore({
|
|
|
1474
1527
|
}
|
|
1475
1528
|
function useMultipleListQueries(queries, {
|
|
1476
1529
|
itemSelector = defaultItemSelector,
|
|
1477
|
-
|
|
1478
|
-
returnIdleStatus,
|
|
1479
|
-
returnRefetchingStatus,
|
|
1480
|
-
loadSize,
|
|
1481
|
-
disableRefetchOnMount = globalDisableRefetchOnMount,
|
|
1482
|
-
isOffScreen
|
|
1530
|
+
selectorUsesExternalDeps
|
|
1483
1531
|
} = {}) {
|
|
1484
1532
|
const queriesWithId = useDeepMemo(() => {
|
|
1485
|
-
return queries.map((
|
|
1533
|
+
return queries.map((item) => {
|
|
1486
1534
|
return {
|
|
1487
|
-
key: getQueryKey(payload),
|
|
1488
|
-
payload
|
|
1535
|
+
key: getQueryKey(item.payload),
|
|
1536
|
+
payload: item.payload,
|
|
1537
|
+
disableRefetchOnMount: item.disableRefetchOnMount ?? globalDisableRefetchOnMount,
|
|
1538
|
+
returnIdleStatus: item.returnIdleStatus,
|
|
1539
|
+
returnRefetchingStatus: item.returnRefetchingStatus,
|
|
1540
|
+
queryMetadata: item.queryMetadata,
|
|
1541
|
+
isOffScreen: item.isOffScreen,
|
|
1542
|
+
omitPayload: item.omitPayload,
|
|
1543
|
+
loadSize: item.loadSize
|
|
1489
1544
|
};
|
|
1490
1545
|
});
|
|
1491
1546
|
}, [queries]);
|
|
1492
|
-
const dataSelector = useCallback3(itemSelector, [
|
|
1547
|
+
const dataSelector = useCallback3(itemSelector, [
|
|
1548
|
+
selectorUsesExternalDeps ? itemSelector : 0
|
|
1549
|
+
]);
|
|
1493
1550
|
const resultSelector = useCallback3(
|
|
1494
1551
|
(state) => {
|
|
1495
1552
|
return queriesWithId.map(
|
|
1496
1553
|
({
|
|
1497
1554
|
key: queryKey,
|
|
1498
|
-
payload
|
|
1555
|
+
payload,
|
|
1556
|
+
returnIdleStatus,
|
|
1557
|
+
returnRefetchingStatus,
|
|
1558
|
+
omitPayload,
|
|
1559
|
+
queryMetadata
|
|
1499
1560
|
}) => {
|
|
1500
1561
|
const query = state.queries[queryKey];
|
|
1501
1562
|
if (!query) {
|
|
@@ -1507,7 +1568,8 @@ function newTSDFListQueryStore({
|
|
|
1507
1568
|
hasMore: false,
|
|
1508
1569
|
payload: omitPayload ? void 0 : payload,
|
|
1509
1570
|
isLoading: returnIdleStatus ? false : true,
|
|
1510
|
-
isLoadingMore: false
|
|
1571
|
+
isLoadingMore: false,
|
|
1572
|
+
queryMetadata
|
|
1511
1573
|
};
|
|
1512
1574
|
}
|
|
1513
1575
|
let status = query.status;
|
|
@@ -1522,27 +1584,22 @@ function newTSDFListQueryStore({
|
|
|
1522
1584
|
hasMore: query.hasMore,
|
|
1523
1585
|
isLoading: status === "loading",
|
|
1524
1586
|
payload: omitPayload ? void 0 : query.payload,
|
|
1525
|
-
isLoadingMore: status === "loadingMore"
|
|
1587
|
+
isLoadingMore: status === "loadingMore",
|
|
1588
|
+
queryMetadata
|
|
1526
1589
|
};
|
|
1527
1590
|
}
|
|
1528
1591
|
);
|
|
1529
1592
|
},
|
|
1530
|
-
[
|
|
1531
|
-
dataSelector,
|
|
1532
|
-
omitPayload,
|
|
1533
|
-
queriesWithId,
|
|
1534
|
-
returnIdleStatus,
|
|
1535
|
-
returnRefetchingStatus
|
|
1536
|
-
]
|
|
1593
|
+
[dataSelector, queriesWithId]
|
|
1537
1594
|
);
|
|
1538
1595
|
const storeState = store.useSelector(resultSelector, {
|
|
1539
1596
|
equalityFn: deepEqual4,
|
|
1540
1597
|
useExternalDeps: true
|
|
1541
1598
|
});
|
|
1542
1599
|
useOnEvtmitterEvent4(storeEvents, "invalidateQuery", (event) => {
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1600
|
+
for (const { key, payload, isOffScreen } of queriesWithId) {
|
|
1601
|
+
if (isOffScreen)
|
|
1602
|
+
continue;
|
|
1546
1603
|
if (key !== event.queryKey)
|
|
1547
1604
|
continue;
|
|
1548
1605
|
if (!queryInvalidationWasTriggered.has(key)) {
|
|
@@ -1557,35 +1614,80 @@ function newTSDFListQueryStore({
|
|
|
1557
1614
|
}
|
|
1558
1615
|
}
|
|
1559
1616
|
});
|
|
1560
|
-
const
|
|
1617
|
+
const ignoreItemsInRefetchOnMount = useConst(() => /* @__PURE__ */ new Set());
|
|
1561
1618
|
useEffect4(() => {
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1619
|
+
const removedItems = new Set(ignoreItemsInRefetchOnMount);
|
|
1620
|
+
for (const {
|
|
1621
|
+
key: itemId,
|
|
1622
|
+
payload: fetchParams,
|
|
1623
|
+
isOffScreen,
|
|
1624
|
+
loadSize,
|
|
1625
|
+
disableRefetchOnMount
|
|
1626
|
+
} of queriesWithId) {
|
|
1627
|
+
removedItems.delete(itemId);
|
|
1628
|
+
if (isOffScreen)
|
|
1629
|
+
continue;
|
|
1565
1630
|
if (itemId) {
|
|
1566
1631
|
const itemState = getQueryState(fetchParams);
|
|
1567
1632
|
const fetchType = itemState?.refetchOnMount || "lowPriority";
|
|
1633
|
+
const shouldFetch = !itemState || !itemState.wasLoaded || itemState.refetchOnMount;
|
|
1634
|
+
if (!shouldFetch && ignoreItemsInRefetchOnMount.has(itemId)) {
|
|
1635
|
+
continue;
|
|
1636
|
+
}
|
|
1637
|
+
ignoreItemsInRefetchOnMount.add(itemId);
|
|
1568
1638
|
if (disableRefetchOnMount) {
|
|
1569
|
-
const shouldFetch = !itemState || !itemState.wasLoaded || itemState.refetchOnMount;
|
|
1570
1639
|
if (shouldFetch) {
|
|
1571
|
-
scheduleListQueryFetch(fetchType, fetchParams,
|
|
1640
|
+
scheduleListQueryFetch(fetchType, fetchParams, loadSize);
|
|
1572
1641
|
continue;
|
|
1573
1642
|
}
|
|
1574
1643
|
} else {
|
|
1575
|
-
scheduleListQueryFetch(fetchType, fetchParams,
|
|
1644
|
+
scheduleListQueryFetch(fetchType, fetchParams, loadSize);
|
|
1576
1645
|
}
|
|
1577
1646
|
}
|
|
1578
1647
|
}
|
|
1579
|
-
|
|
1648
|
+
for (const itemKey of removedItems) {
|
|
1649
|
+
ignoreItemsInRefetchOnMount.delete(itemKey);
|
|
1650
|
+
}
|
|
1651
|
+
}, [ignoreItemsInRefetchOnMount, queriesWithId]);
|
|
1580
1652
|
return storeState;
|
|
1581
1653
|
}
|
|
1582
|
-
function useListQuery(payload,
|
|
1583
|
-
|
|
1654
|
+
function useListQuery(payload, {
|
|
1655
|
+
isOffScreen,
|
|
1656
|
+
itemSelector,
|
|
1657
|
+
disableRefetchOnMount,
|
|
1658
|
+
returnIdleStatus,
|
|
1659
|
+
returnRefetchingStatus,
|
|
1660
|
+
loadSize,
|
|
1661
|
+
omitPayload,
|
|
1662
|
+
ensureIsLoaded,
|
|
1663
|
+
selectorUsesExternalDeps
|
|
1664
|
+
} = {}) {
|
|
1584
1665
|
const query = useMemo4(
|
|
1585
|
-
() => payload === false || payload === null || payload === void 0 ? [] : [
|
|
1586
|
-
|
|
1666
|
+
() => payload === false || payload === null || payload === void 0 ? [] : [
|
|
1667
|
+
{
|
|
1668
|
+
payload,
|
|
1669
|
+
disableRefetchOnMount,
|
|
1670
|
+
returnIdleStatus,
|
|
1671
|
+
returnRefetchingStatus,
|
|
1672
|
+
omitPayload,
|
|
1673
|
+
isOffScreen,
|
|
1674
|
+
loadSize
|
|
1675
|
+
}
|
|
1676
|
+
],
|
|
1677
|
+
[
|
|
1678
|
+
disableRefetchOnMount,
|
|
1679
|
+
isOffScreen,
|
|
1680
|
+
loadSize,
|
|
1681
|
+
omitPayload,
|
|
1682
|
+
payload,
|
|
1683
|
+
returnIdleStatus,
|
|
1684
|
+
returnRefetchingStatus
|
|
1685
|
+
]
|
|
1587
1686
|
);
|
|
1588
|
-
const queryResult = useMultipleListQueries(query,
|
|
1687
|
+
const queryResult = useMultipleListQueries(query, {
|
|
1688
|
+
itemSelector,
|
|
1689
|
+
selectorUsesExternalDeps
|
|
1690
|
+
});
|
|
1589
1691
|
const result = useMemo4(
|
|
1590
1692
|
() => queryResult[0] ?? {
|
|
1591
1693
|
payload: void 0,
|
|
@@ -1595,7 +1697,8 @@ function newTSDFListQueryStore({
|
|
|
1595
1697
|
status: "idle",
|
|
1596
1698
|
queryKey: "",
|
|
1597
1699
|
items: [],
|
|
1598
|
-
isLoadingMore: false
|
|
1700
|
+
isLoadingMore: false,
|
|
1701
|
+
queryMetadata: void 0
|
|
1599
1702
|
},
|
|
1600
1703
|
[queryResult]
|
|
1601
1704
|
);
|
|
@@ -1803,30 +1906,37 @@ function newTSDFListQueryStore({
|
|
|
1803
1906
|
function defaultItemDataSelector(data) {
|
|
1804
1907
|
return data;
|
|
1805
1908
|
}
|
|
1806
|
-
function useMultipleItems(
|
|
1909
|
+
function useMultipleItems(items, {
|
|
1807
1910
|
selector = defaultItemDataSelector,
|
|
1808
|
-
returnIdleStatus,
|
|
1809
|
-
returnRefetchingStatus,
|
|
1810
|
-
disableRefetchOnMount,
|
|
1811
1911
|
loadFromStateOnly,
|
|
1812
|
-
|
|
1912
|
+
selectorUsesExternalDeps
|
|
1813
1913
|
} = {}) {
|
|
1814
|
-
const dataSelector = useCallback3(selector, [
|
|
1914
|
+
const dataSelector = useCallback3(selector, [
|
|
1915
|
+
selectorUsesExternalDeps ? selector : 0
|
|
1916
|
+
]);
|
|
1815
1917
|
const memoizedItemKeys = useDeepMemo(
|
|
1816
|
-
() =>
|
|
1918
|
+
() => items.map(
|
|
1817
1919
|
(itemPayload) => ({
|
|
1818
|
-
|
|
1819
|
-
|
|
1920
|
+
itemKey: getItemKey(itemPayload.payload),
|
|
1921
|
+
payload: itemPayload.payload,
|
|
1922
|
+
disableRefetchOnMount: itemPayload.disableRefetchOnMount,
|
|
1923
|
+
returnIdleStatus: itemPayload.returnIdleStatus,
|
|
1924
|
+
returnRefetchingStatus: itemPayload.returnRefetchingStatus,
|
|
1925
|
+
isOffScreen: itemPayload.isOffScreen,
|
|
1926
|
+
queryMetadata: itemPayload.queryMetadata
|
|
1820
1927
|
})
|
|
1821
1928
|
),
|
|
1822
|
-
[
|
|
1929
|
+
[items]
|
|
1823
1930
|
);
|
|
1824
1931
|
const resultSelector = useCallback3(
|
|
1825
1932
|
(state) => {
|
|
1826
1933
|
return memoizedItemKeys.map(
|
|
1827
1934
|
({
|
|
1828
1935
|
itemKey,
|
|
1829
|
-
payload
|
|
1936
|
+
payload,
|
|
1937
|
+
queryMetadata,
|
|
1938
|
+
returnRefetchingStatus,
|
|
1939
|
+
returnIdleStatus
|
|
1830
1940
|
}) => {
|
|
1831
1941
|
const itemQuery = state.itemQueries[itemKey];
|
|
1832
1942
|
const itemState = state.items[itemKey];
|
|
@@ -1836,7 +1946,8 @@ function newTSDFListQueryStore({
|
|
|
1836
1946
|
error: null,
|
|
1837
1947
|
isLoading: false,
|
|
1838
1948
|
payload,
|
|
1839
|
-
data: dataSelector(null, null)
|
|
1949
|
+
data: dataSelector(null, null),
|
|
1950
|
+
queryMetadata
|
|
1840
1951
|
};
|
|
1841
1952
|
}
|
|
1842
1953
|
if (!itemQuery) {
|
|
@@ -1845,7 +1956,8 @@ function newTSDFListQueryStore({
|
|
|
1845
1956
|
error: null,
|
|
1846
1957
|
isLoading: returnIdleStatus ? false : true,
|
|
1847
1958
|
payload,
|
|
1848
|
-
data: dataSelector(null, null)
|
|
1959
|
+
data: dataSelector(null, null),
|
|
1960
|
+
queryMetadata
|
|
1849
1961
|
};
|
|
1850
1962
|
}
|
|
1851
1963
|
let status = itemQuery.status;
|
|
@@ -1857,26 +1969,24 @@ function newTSDFListQueryStore({
|
|
|
1857
1969
|
error: itemQuery.error,
|
|
1858
1970
|
isLoading: status === "loading",
|
|
1859
1971
|
data: dataSelector(itemState ?? null, itemQuery.payload),
|
|
1860
|
-
payload
|
|
1972
|
+
payload,
|
|
1973
|
+
queryMetadata
|
|
1861
1974
|
};
|
|
1862
1975
|
}
|
|
1863
1976
|
);
|
|
1864
1977
|
},
|
|
1865
|
-
[
|
|
1866
|
-
dataSelector,
|
|
1867
|
-
memoizedItemKeys,
|
|
1868
|
-
returnIdleStatus,
|
|
1869
|
-
returnRefetchingStatus
|
|
1870
|
-
]
|
|
1978
|
+
[dataSelector, memoizedItemKeys]
|
|
1871
1979
|
);
|
|
1872
1980
|
const storeState = store.useSelector(resultSelector, {
|
|
1873
1981
|
equalityFn: deepEqual4,
|
|
1874
1982
|
useExternalDeps: true
|
|
1875
1983
|
});
|
|
1876
1984
|
useOnEvtmitterEvent4(storeEvents, "invalidateItem", (event) => {
|
|
1877
|
-
if (loadFromStateOnly
|
|
1985
|
+
if (loadFromStateOnly)
|
|
1878
1986
|
return;
|
|
1879
|
-
for (const { payload, itemKey } of memoizedItemKeys) {
|
|
1987
|
+
for (const { payload, itemKey, isOffScreen } of memoizedItemKeys) {
|
|
1988
|
+
if (isOffScreen)
|
|
1989
|
+
continue;
|
|
1880
1990
|
if (itemKey !== event.itemKey)
|
|
1881
1991
|
continue;
|
|
1882
1992
|
if (!itemInvalidationWasTriggered.has(itemKey)) {
|
|
@@ -1891,15 +2001,29 @@ function newTSDFListQueryStore({
|
|
|
1891
2001
|
}
|
|
1892
2002
|
}
|
|
1893
2003
|
});
|
|
2004
|
+
const ignoreItemsInRefetchOnMount = useConst(() => /* @__PURE__ */ new Set());
|
|
1894
2005
|
useEffect4(() => {
|
|
1895
|
-
if (loadFromStateOnly
|
|
2006
|
+
if (loadFromStateOnly)
|
|
1896
2007
|
return;
|
|
1897
|
-
|
|
2008
|
+
const removedItems = new Set(ignoreItemsInRefetchOnMount);
|
|
2009
|
+
for (const {
|
|
2010
|
+
payload,
|
|
2011
|
+
itemKey,
|
|
2012
|
+
isOffScreen,
|
|
2013
|
+
disableRefetchOnMount
|
|
2014
|
+
} of memoizedItemKeys) {
|
|
2015
|
+
removedItems.delete(itemKey);
|
|
2016
|
+
if (isOffScreen)
|
|
2017
|
+
continue;
|
|
1898
2018
|
if (itemKey) {
|
|
1899
2019
|
const itemState = store.state.itemQueries[itemKey];
|
|
1900
2020
|
const fetchType = itemState?.refetchOnMount || "lowPriority";
|
|
2021
|
+
const shouldFetch = !itemState || !itemState.wasLoaded || itemState.refetchOnMount;
|
|
2022
|
+
if (!shouldFetch && ignoreItemsInRefetchOnMount.has(itemKey)) {
|
|
2023
|
+
continue;
|
|
2024
|
+
}
|
|
2025
|
+
ignoreItemsInRefetchOnMount.add(itemKey);
|
|
1901
2026
|
if (disableRefetchOnMount) {
|
|
1902
|
-
const shouldFetch = !itemState || !itemState.wasLoaded || itemState.refetchOnMount;
|
|
1903
2027
|
if (shouldFetch) {
|
|
1904
2028
|
scheduleItemFetch(fetchType, payload);
|
|
1905
2029
|
return;
|
|
@@ -1909,23 +2033,47 @@ function newTSDFListQueryStore({
|
|
|
1909
2033
|
}
|
|
1910
2034
|
}
|
|
1911
2035
|
}
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
memoizedItemKeys
|
|
1917
|
-
]);
|
|
2036
|
+
for (const itemKey of removedItems) {
|
|
2037
|
+
ignoreItemsInRefetchOnMount.delete(itemKey);
|
|
2038
|
+
}
|
|
2039
|
+
}, [ignoreItemsInRefetchOnMount, loadFromStateOnly, memoizedItemKeys]);
|
|
1918
2040
|
return storeState;
|
|
1919
2041
|
}
|
|
1920
|
-
function useItem(itemPayload,
|
|
1921
|
-
|
|
2042
|
+
function useItem(itemPayload, {
|
|
2043
|
+
selector,
|
|
2044
|
+
selectorUsesExternalDeps,
|
|
2045
|
+
disableRefetchOnMount,
|
|
2046
|
+
returnIdleStatus,
|
|
2047
|
+
returnRefetchingStatus,
|
|
2048
|
+
ensureIsLoaded,
|
|
2049
|
+
loadFromStateOnly,
|
|
2050
|
+
isOffScreen
|
|
2051
|
+
} = {}) {
|
|
1922
2052
|
const query = useMemo4(
|
|
1923
|
-
() => itemPayload === false || itemPayload === null || itemPayload === void 0 ? [] : [
|
|
1924
|
-
|
|
2053
|
+
() => itemPayload === false || itemPayload === null || itemPayload === void 0 ? [] : [
|
|
2054
|
+
{
|
|
2055
|
+
payload: itemPayload,
|
|
2056
|
+
disableRefetchOnMount,
|
|
2057
|
+
isOffScreen,
|
|
2058
|
+
returnIdleStatus,
|
|
2059
|
+
returnRefetchingStatus
|
|
2060
|
+
}
|
|
2061
|
+
],
|
|
2062
|
+
[
|
|
2063
|
+
itemPayload,
|
|
2064
|
+
disableRefetchOnMount,
|
|
2065
|
+
isOffScreen,
|
|
2066
|
+
returnIdleStatus,
|
|
2067
|
+
returnRefetchingStatus
|
|
2068
|
+
]
|
|
1925
2069
|
);
|
|
1926
|
-
const queryResult = useMultipleItems(query,
|
|
2070
|
+
const queryResult = useMultipleItems(query, {
|
|
2071
|
+
selector,
|
|
2072
|
+
selectorUsesExternalDeps,
|
|
2073
|
+
loadFromStateOnly
|
|
2074
|
+
});
|
|
1927
2075
|
const memoizedSelector = useCallback3(
|
|
1928
|
-
|
|
2076
|
+
selector ?? defaultItemDataSelector,
|
|
1929
2077
|
[]
|
|
1930
2078
|
);
|
|
1931
2079
|
const result = useMemo4(
|
|
@@ -1934,7 +2082,8 @@ function newTSDFListQueryStore({
|
|
|
1934
2082
|
isLoading: false,
|
|
1935
2083
|
status: "idle",
|
|
1936
2084
|
data: memoizedSelector(null, null),
|
|
1937
|
-
payload: itemPayload || null
|
|
2085
|
+
payload: itemPayload || null,
|
|
2086
|
+
queryMetadata: void 0
|
|
1938
2087
|
},
|
|
1939
2088
|
[itemPayload, memoizedSelector, queryResult]
|
|
1940
2089
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdf",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"description": "A data fetching solution based on t-state",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Lucas Santos",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"evtmitter": "^0.3.3",
|
|
55
55
|
"immer": "^10.0.3",
|
|
56
56
|
"klona": "^2.0.6",
|
|
57
|
-
"t-state": "^8.10.
|
|
57
|
+
"t-state": "^8.10.1"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"react": "^18.0.0",
|