tsdf 12.7.0 → 13.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 +300 -119
- package/dist/main.d.cts +55 -32
- package/dist/main.d.ts +55 -32
- package/dist/main.js +299 -119
- package/package.json +2 -2
package/dist/main.js
CHANGED
|
@@ -616,16 +616,46 @@ function isObject(value) {
|
|
|
616
616
|
}
|
|
617
617
|
|
|
618
618
|
// src/utils/getCacheId.ts
|
|
619
|
-
function getCacheId(input) {
|
|
620
|
-
|
|
619
|
+
function getCacheId(input, maxDepth = 3) {
|
|
620
|
+
if (typeof input === "string")
|
|
621
|
+
return String(input);
|
|
622
|
+
if (!input || typeof input !== "object")
|
|
623
|
+
return `#$${input}$#`;
|
|
624
|
+
return JSON.stringify(sortValues(input, maxDepth, 0));
|
|
621
625
|
}
|
|
622
|
-
function
|
|
623
|
-
|
|
626
|
+
function sortValues(input, maxDepth, depth) {
|
|
627
|
+
if (depth >= maxDepth)
|
|
628
|
+
return input;
|
|
629
|
+
if (Array.isArray(input)) {
|
|
630
|
+
return input.map((v) => sortValues(v, maxDepth, depth + 1));
|
|
631
|
+
}
|
|
632
|
+
if (isObject(input)) {
|
|
633
|
+
return orderedProps(input, (v) => sortValues(v, maxDepth, depth + 1));
|
|
634
|
+
}
|
|
635
|
+
return input;
|
|
636
|
+
}
|
|
637
|
+
var emptyObject = {};
|
|
638
|
+
function orderedProps(obj, mapValue) {
|
|
639
|
+
const keys = Object.keys(obj);
|
|
640
|
+
if (keys.length === 0)
|
|
641
|
+
return emptyObject;
|
|
642
|
+
if (keys.length === 1) {
|
|
643
|
+
const value = obj[keys[0]];
|
|
644
|
+
if (value === void 0)
|
|
645
|
+
return emptyObject;
|
|
646
|
+
return { [keys[0]]: mapValue(value) };
|
|
647
|
+
}
|
|
648
|
+
const mappedValues = filterAndMap(keys.sort(), (k, ignore) => {
|
|
624
649
|
const value = obj[k];
|
|
625
650
|
if (value === void 0)
|
|
626
651
|
return ignore;
|
|
627
|
-
return { [k]:
|
|
652
|
+
return { [k]: mapValue(value) };
|
|
628
653
|
});
|
|
654
|
+
if (mappedValues.length === 0)
|
|
655
|
+
return emptyObject;
|
|
656
|
+
if (mappedValues.length === 1)
|
|
657
|
+
return mappedValues[0];
|
|
658
|
+
return mappedValues;
|
|
629
659
|
}
|
|
630
660
|
|
|
631
661
|
// src/collectionStore.ts
|
|
@@ -818,30 +848,43 @@ function newTSDFCollectionStore({
|
|
|
818
848
|
}
|
|
819
849
|
return store.state[getItemKey(params)];
|
|
820
850
|
}
|
|
821
|
-
function useMultipleItems(
|
|
851
|
+
function useMultipleItems(items, {
|
|
822
852
|
selector,
|
|
823
|
-
|
|
824
|
-
returnIdleStatus,
|
|
825
|
-
returnRefetchingStatus,
|
|
826
|
-
disableRefetchOnMount = globalDisableRefetchOnMount,
|
|
827
|
-
isOffScreen
|
|
853
|
+
selectorUsesExternalDeps
|
|
828
854
|
} = {}) {
|
|
829
855
|
const queriesWithId = useDeepMemo(() => {
|
|
830
|
-
return
|
|
831
|
-
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
|
+
};
|
|
832
867
|
});
|
|
833
|
-
}, [
|
|
834
|
-
const dataSelector = useCallback2(
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
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
|
+
);
|
|
839
878
|
const resultSelector = useCallback2(
|
|
840
879
|
(state) => {
|
|
841
880
|
return queriesWithId.map(
|
|
842
881
|
({
|
|
843
882
|
itemKey,
|
|
844
|
-
payload
|
|
883
|
+
payload,
|
|
884
|
+
omitPayload,
|
|
885
|
+
returnIdleStatus,
|
|
886
|
+
returnRefetchingStatus,
|
|
887
|
+
queryMetadata
|
|
845
888
|
}) => {
|
|
846
889
|
const item = state[itemKey];
|
|
847
890
|
if (item === null) {
|
|
@@ -851,7 +894,8 @@ function newTSDFCollectionStore({
|
|
|
851
894
|
data: dataSelector(null),
|
|
852
895
|
error: null,
|
|
853
896
|
payload: omitPayload ? void 0 : payload,
|
|
854
|
-
isLoading: false
|
|
897
|
+
isLoading: false,
|
|
898
|
+
queryMetadata
|
|
855
899
|
};
|
|
856
900
|
}
|
|
857
901
|
if (!item) {
|
|
@@ -861,7 +905,8 @@ function newTSDFCollectionStore({
|
|
|
861
905
|
data: dataSelector(null),
|
|
862
906
|
error: null,
|
|
863
907
|
payload: omitPayload ? void 0 : payload,
|
|
864
|
-
isLoading: returnIdleStatus ? false : true
|
|
908
|
+
isLoading: returnIdleStatus ? false : true,
|
|
909
|
+
queryMetadata
|
|
865
910
|
};
|
|
866
911
|
}
|
|
867
912
|
let status = item.status;
|
|
@@ -874,27 +919,22 @@ function newTSDFCollectionStore({
|
|
|
874
919
|
data: dataSelector(item.data),
|
|
875
920
|
error: item.error,
|
|
876
921
|
isLoading: status === "loading",
|
|
877
|
-
payload: omitPayload ? void 0 : item.payload
|
|
922
|
+
payload: omitPayload ? void 0 : item.payload,
|
|
923
|
+
queryMetadata
|
|
878
924
|
};
|
|
879
925
|
}
|
|
880
926
|
);
|
|
881
927
|
},
|
|
882
|
-
[
|
|
883
|
-
dataSelector,
|
|
884
|
-
omitPayload,
|
|
885
|
-
queriesWithId,
|
|
886
|
-
returnIdleStatus,
|
|
887
|
-
returnRefetchingStatus
|
|
888
|
-
]
|
|
928
|
+
[dataSelector, queriesWithId]
|
|
889
929
|
);
|
|
890
930
|
const storeState = store.useSelector(resultSelector, {
|
|
891
931
|
equalityFn: deepEqual3,
|
|
892
932
|
useExternalDeps: true
|
|
893
933
|
});
|
|
894
934
|
useOnEvtmitterEvent3(storeEvents, "invalidateData", (event) => {
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
935
|
+
for (const { itemKey, payload, isOffScreen } of queriesWithId) {
|
|
936
|
+
if (isOffScreen)
|
|
937
|
+
continue;
|
|
898
938
|
if (itemKey !== event.itemKey)
|
|
899
939
|
continue;
|
|
900
940
|
if (!invalidationWasTriggered.has(itemKey)) {
|
|
@@ -909,15 +949,27 @@ function newTSDFCollectionStore({
|
|
|
909
949
|
}
|
|
910
950
|
}
|
|
911
951
|
});
|
|
952
|
+
const ignoreItemsInRefetchOnMount = useConst(() => /* @__PURE__ */ new Set());
|
|
912
953
|
useEffect3(() => {
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
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;
|
|
916
964
|
if (itemId) {
|
|
917
965
|
const itemState = getItemState(payload);
|
|
918
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);
|
|
919
972
|
if (disableRefetchOnMount) {
|
|
920
|
-
const shouldFetch = !itemState?.wasLoaded || itemState.refetchOnMount;
|
|
921
973
|
if (shouldFetch) {
|
|
922
974
|
scheduleFetch(fetchType, payload);
|
|
923
975
|
continue;
|
|
@@ -927,16 +979,46 @@ function newTSDFCollectionStore({
|
|
|
927
979
|
}
|
|
928
980
|
}
|
|
929
981
|
}
|
|
930
|
-
|
|
982
|
+
for (const itemId of removedQueries) {
|
|
983
|
+
ignoreItemsInRefetchOnMount.delete(itemId);
|
|
984
|
+
}
|
|
985
|
+
}, [ignoreItemsInRefetchOnMount, queriesWithId]);
|
|
931
986
|
return storeState;
|
|
932
987
|
}
|
|
933
|
-
function useItem(payload,
|
|
934
|
-
|
|
988
|
+
function useItem(payload, {
|
|
989
|
+
omitPayload,
|
|
990
|
+
selector,
|
|
991
|
+
selectorUsesExternalDeps,
|
|
992
|
+
ensureIsLoaded,
|
|
993
|
+
returnRefetchingStatus,
|
|
994
|
+
disableRefetchOnMount,
|
|
995
|
+
returnIdleStatus,
|
|
996
|
+
isOffScreen
|
|
997
|
+
} = {}) {
|
|
935
998
|
const query = useMemo3(
|
|
936
|
-
() => payload === false || payload === null || payload === void 0 ? [] : [
|
|
937
|
-
|
|
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
|
+
]
|
|
938
1017
|
);
|
|
939
|
-
const item = useMultipleItems(query,
|
|
1018
|
+
const item = useMultipleItems(query, {
|
|
1019
|
+
selector,
|
|
1020
|
+
selectorUsesExternalDeps
|
|
1021
|
+
});
|
|
940
1022
|
const result = useMemo3(
|
|
941
1023
|
() => item[0] ?? {
|
|
942
1024
|
payload: void 0,
|
|
@@ -944,7 +1026,8 @@ function newTSDFCollectionStore({
|
|
|
944
1026
|
error: null,
|
|
945
1027
|
status: "idle",
|
|
946
1028
|
itemStateKey: "",
|
|
947
|
-
isLoading: false
|
|
1029
|
+
isLoading: false,
|
|
1030
|
+
queryMetadata: void 0
|
|
948
1031
|
},
|
|
949
1032
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
950
1033
|
[item]
|
|
@@ -1444,28 +1527,36 @@ function newTSDFListQueryStore({
|
|
|
1444
1527
|
}
|
|
1445
1528
|
function useMultipleListQueries(queries, {
|
|
1446
1529
|
itemSelector = defaultItemSelector,
|
|
1447
|
-
|
|
1448
|
-
returnIdleStatus,
|
|
1449
|
-
returnRefetchingStatus,
|
|
1450
|
-
loadSize,
|
|
1451
|
-
disableRefetchOnMount = globalDisableRefetchOnMount,
|
|
1452
|
-
isOffScreen
|
|
1530
|
+
selectorUsesExternalDeps
|
|
1453
1531
|
} = {}) {
|
|
1454
1532
|
const queriesWithId = useDeepMemo(() => {
|
|
1455
|
-
return queries.map((
|
|
1533
|
+
return queries.map((item) => {
|
|
1456
1534
|
return {
|
|
1457
|
-
key: getQueryKey(payload),
|
|
1458
|
-
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
|
|
1459
1544
|
};
|
|
1460
1545
|
});
|
|
1461
1546
|
}, [queries]);
|
|
1462
|
-
const dataSelector = useCallback3(itemSelector, [
|
|
1547
|
+
const dataSelector = useCallback3(itemSelector, [
|
|
1548
|
+
selectorUsesExternalDeps ? itemSelector : 0
|
|
1549
|
+
]);
|
|
1463
1550
|
const resultSelector = useCallback3(
|
|
1464
1551
|
(state) => {
|
|
1465
1552
|
return queriesWithId.map(
|
|
1466
1553
|
({
|
|
1467
1554
|
key: queryKey,
|
|
1468
|
-
payload
|
|
1555
|
+
payload,
|
|
1556
|
+
returnIdleStatus,
|
|
1557
|
+
returnRefetchingStatus,
|
|
1558
|
+
omitPayload,
|
|
1559
|
+
queryMetadata
|
|
1469
1560
|
}) => {
|
|
1470
1561
|
const query = state.queries[queryKey];
|
|
1471
1562
|
if (!query) {
|
|
@@ -1477,7 +1568,8 @@ function newTSDFListQueryStore({
|
|
|
1477
1568
|
hasMore: false,
|
|
1478
1569
|
payload: omitPayload ? void 0 : payload,
|
|
1479
1570
|
isLoading: returnIdleStatus ? false : true,
|
|
1480
|
-
isLoadingMore: false
|
|
1571
|
+
isLoadingMore: false,
|
|
1572
|
+
queryMetadata
|
|
1481
1573
|
};
|
|
1482
1574
|
}
|
|
1483
1575
|
let status = query.status;
|
|
@@ -1492,27 +1584,22 @@ function newTSDFListQueryStore({
|
|
|
1492
1584
|
hasMore: query.hasMore,
|
|
1493
1585
|
isLoading: status === "loading",
|
|
1494
1586
|
payload: omitPayload ? void 0 : query.payload,
|
|
1495
|
-
isLoadingMore: status === "loadingMore"
|
|
1587
|
+
isLoadingMore: status === "loadingMore",
|
|
1588
|
+
queryMetadata
|
|
1496
1589
|
};
|
|
1497
1590
|
}
|
|
1498
1591
|
);
|
|
1499
1592
|
},
|
|
1500
|
-
[
|
|
1501
|
-
dataSelector,
|
|
1502
|
-
omitPayload,
|
|
1503
|
-
queriesWithId,
|
|
1504
|
-
returnIdleStatus,
|
|
1505
|
-
returnRefetchingStatus
|
|
1506
|
-
]
|
|
1593
|
+
[dataSelector, queriesWithId]
|
|
1507
1594
|
);
|
|
1508
1595
|
const storeState = store.useSelector(resultSelector, {
|
|
1509
1596
|
equalityFn: deepEqual4,
|
|
1510
1597
|
useExternalDeps: true
|
|
1511
1598
|
});
|
|
1512
1599
|
useOnEvtmitterEvent4(storeEvents, "invalidateQuery", (event) => {
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1600
|
+
for (const { key, payload, isOffScreen } of queriesWithId) {
|
|
1601
|
+
if (isOffScreen)
|
|
1602
|
+
continue;
|
|
1516
1603
|
if (key !== event.queryKey)
|
|
1517
1604
|
continue;
|
|
1518
1605
|
if (!queryInvalidationWasTriggered.has(key)) {
|
|
@@ -1527,35 +1614,80 @@ function newTSDFListQueryStore({
|
|
|
1527
1614
|
}
|
|
1528
1615
|
}
|
|
1529
1616
|
});
|
|
1530
|
-
const
|
|
1617
|
+
const ignoreItemsInRefetchOnMount = useConst(() => /* @__PURE__ */ new Set());
|
|
1531
1618
|
useEffect4(() => {
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
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;
|
|
1535
1630
|
if (itemId) {
|
|
1536
1631
|
const itemState = getQueryState(fetchParams);
|
|
1537
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);
|
|
1538
1638
|
if (disableRefetchOnMount) {
|
|
1539
|
-
const shouldFetch = !itemState || !itemState.wasLoaded || itemState.refetchOnMount;
|
|
1540
1639
|
if (shouldFetch) {
|
|
1541
|
-
scheduleListQueryFetch(fetchType, fetchParams,
|
|
1640
|
+
scheduleListQueryFetch(fetchType, fetchParams, loadSize);
|
|
1542
1641
|
continue;
|
|
1543
1642
|
}
|
|
1544
1643
|
} else {
|
|
1545
|
-
scheduleListQueryFetch(fetchType, fetchParams,
|
|
1644
|
+
scheduleListQueryFetch(fetchType, fetchParams, loadSize);
|
|
1546
1645
|
}
|
|
1547
1646
|
}
|
|
1548
1647
|
}
|
|
1549
|
-
|
|
1648
|
+
for (const itemKey of removedItems) {
|
|
1649
|
+
ignoreItemsInRefetchOnMount.delete(itemKey);
|
|
1650
|
+
}
|
|
1651
|
+
}, [ignoreItemsInRefetchOnMount, queriesWithId]);
|
|
1550
1652
|
return storeState;
|
|
1551
1653
|
}
|
|
1552
|
-
function useListQuery(payload,
|
|
1553
|
-
|
|
1654
|
+
function useListQuery(payload, {
|
|
1655
|
+
isOffScreen,
|
|
1656
|
+
itemSelector,
|
|
1657
|
+
disableRefetchOnMount,
|
|
1658
|
+
returnIdleStatus,
|
|
1659
|
+
returnRefetchingStatus,
|
|
1660
|
+
loadSize,
|
|
1661
|
+
omitPayload,
|
|
1662
|
+
ensureIsLoaded,
|
|
1663
|
+
selectorUsesExternalDeps
|
|
1664
|
+
} = {}) {
|
|
1554
1665
|
const query = useMemo4(
|
|
1555
|
-
() => payload === false || payload === null || payload === void 0 ? [] : [
|
|
1556
|
-
|
|
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
|
+
]
|
|
1557
1686
|
);
|
|
1558
|
-
const queryResult = useMultipleListQueries(query,
|
|
1687
|
+
const queryResult = useMultipleListQueries(query, {
|
|
1688
|
+
itemSelector,
|
|
1689
|
+
selectorUsesExternalDeps
|
|
1690
|
+
});
|
|
1559
1691
|
const result = useMemo4(
|
|
1560
1692
|
() => queryResult[0] ?? {
|
|
1561
1693
|
payload: void 0,
|
|
@@ -1565,7 +1697,8 @@ function newTSDFListQueryStore({
|
|
|
1565
1697
|
status: "idle",
|
|
1566
1698
|
queryKey: "",
|
|
1567
1699
|
items: [],
|
|
1568
|
-
isLoadingMore: false
|
|
1700
|
+
isLoadingMore: false,
|
|
1701
|
+
queryMetadata: void 0
|
|
1569
1702
|
},
|
|
1570
1703
|
[queryResult]
|
|
1571
1704
|
);
|
|
@@ -1773,30 +1906,37 @@ function newTSDFListQueryStore({
|
|
|
1773
1906
|
function defaultItemDataSelector(data) {
|
|
1774
1907
|
return data;
|
|
1775
1908
|
}
|
|
1776
|
-
function useMultipleItems(
|
|
1909
|
+
function useMultipleItems(items, {
|
|
1777
1910
|
selector = defaultItemDataSelector,
|
|
1778
|
-
returnIdleStatus,
|
|
1779
|
-
returnRefetchingStatus,
|
|
1780
|
-
disableRefetchOnMount,
|
|
1781
1911
|
loadFromStateOnly,
|
|
1782
|
-
|
|
1912
|
+
selectorUsesExternalDeps
|
|
1783
1913
|
} = {}) {
|
|
1784
|
-
const dataSelector = useCallback3(selector, [
|
|
1914
|
+
const dataSelector = useCallback3(selector, [
|
|
1915
|
+
selectorUsesExternalDeps ? selector : 0
|
|
1916
|
+
]);
|
|
1785
1917
|
const memoizedItemKeys = useDeepMemo(
|
|
1786
|
-
() =>
|
|
1918
|
+
() => items.map(
|
|
1787
1919
|
(itemPayload) => ({
|
|
1788
|
-
|
|
1789
|
-
|
|
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
|
|
1790
1927
|
})
|
|
1791
1928
|
),
|
|
1792
|
-
[
|
|
1929
|
+
[items]
|
|
1793
1930
|
);
|
|
1794
1931
|
const resultSelector = useCallback3(
|
|
1795
1932
|
(state) => {
|
|
1796
1933
|
return memoizedItemKeys.map(
|
|
1797
1934
|
({
|
|
1798
1935
|
itemKey,
|
|
1799
|
-
payload
|
|
1936
|
+
payload,
|
|
1937
|
+
queryMetadata,
|
|
1938
|
+
returnRefetchingStatus,
|
|
1939
|
+
returnIdleStatus
|
|
1800
1940
|
}) => {
|
|
1801
1941
|
const itemQuery = state.itemQueries[itemKey];
|
|
1802
1942
|
const itemState = state.items[itemKey];
|
|
@@ -1806,7 +1946,8 @@ function newTSDFListQueryStore({
|
|
|
1806
1946
|
error: null,
|
|
1807
1947
|
isLoading: false,
|
|
1808
1948
|
payload,
|
|
1809
|
-
data: dataSelector(null, null)
|
|
1949
|
+
data: dataSelector(null, null),
|
|
1950
|
+
queryMetadata
|
|
1810
1951
|
};
|
|
1811
1952
|
}
|
|
1812
1953
|
if (!itemQuery) {
|
|
@@ -1815,7 +1956,8 @@ function newTSDFListQueryStore({
|
|
|
1815
1956
|
error: null,
|
|
1816
1957
|
isLoading: returnIdleStatus ? false : true,
|
|
1817
1958
|
payload,
|
|
1818
|
-
data: dataSelector(null, null)
|
|
1959
|
+
data: dataSelector(null, null),
|
|
1960
|
+
queryMetadata
|
|
1819
1961
|
};
|
|
1820
1962
|
}
|
|
1821
1963
|
let status = itemQuery.status;
|
|
@@ -1827,26 +1969,24 @@ function newTSDFListQueryStore({
|
|
|
1827
1969
|
error: itemQuery.error,
|
|
1828
1970
|
isLoading: status === "loading",
|
|
1829
1971
|
data: dataSelector(itemState ?? null, itemQuery.payload),
|
|
1830
|
-
payload
|
|
1972
|
+
payload,
|
|
1973
|
+
queryMetadata
|
|
1831
1974
|
};
|
|
1832
1975
|
}
|
|
1833
1976
|
);
|
|
1834
1977
|
},
|
|
1835
|
-
[
|
|
1836
|
-
dataSelector,
|
|
1837
|
-
memoizedItemKeys,
|
|
1838
|
-
returnIdleStatus,
|
|
1839
|
-
returnRefetchingStatus
|
|
1840
|
-
]
|
|
1978
|
+
[dataSelector, memoizedItemKeys]
|
|
1841
1979
|
);
|
|
1842
1980
|
const storeState = store.useSelector(resultSelector, {
|
|
1843
1981
|
equalityFn: deepEqual4,
|
|
1844
1982
|
useExternalDeps: true
|
|
1845
1983
|
});
|
|
1846
1984
|
useOnEvtmitterEvent4(storeEvents, "invalidateItem", (event) => {
|
|
1847
|
-
if (loadFromStateOnly
|
|
1985
|
+
if (loadFromStateOnly)
|
|
1848
1986
|
return;
|
|
1849
|
-
for (const { payload, itemKey } of memoizedItemKeys) {
|
|
1987
|
+
for (const { payload, itemKey, isOffScreen } of memoizedItemKeys) {
|
|
1988
|
+
if (isOffScreen)
|
|
1989
|
+
continue;
|
|
1850
1990
|
if (itemKey !== event.itemKey)
|
|
1851
1991
|
continue;
|
|
1852
1992
|
if (!itemInvalidationWasTriggered.has(itemKey)) {
|
|
@@ -1861,15 +2001,29 @@ function newTSDFListQueryStore({
|
|
|
1861
2001
|
}
|
|
1862
2002
|
}
|
|
1863
2003
|
});
|
|
2004
|
+
const ignoreItemsInRefetchOnMount = useConst(() => /* @__PURE__ */ new Set());
|
|
1864
2005
|
useEffect4(() => {
|
|
1865
|
-
if (loadFromStateOnly
|
|
2006
|
+
if (loadFromStateOnly)
|
|
1866
2007
|
return;
|
|
1867
|
-
|
|
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;
|
|
1868
2018
|
if (itemKey) {
|
|
1869
2019
|
const itemState = store.state.itemQueries[itemKey];
|
|
1870
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);
|
|
1871
2026
|
if (disableRefetchOnMount) {
|
|
1872
|
-
const shouldFetch = !itemState || !itemState.wasLoaded || itemState.refetchOnMount;
|
|
1873
2027
|
if (shouldFetch) {
|
|
1874
2028
|
scheduleItemFetch(fetchType, payload);
|
|
1875
2029
|
return;
|
|
@@ -1879,23 +2033,47 @@ function newTSDFListQueryStore({
|
|
|
1879
2033
|
}
|
|
1880
2034
|
}
|
|
1881
2035
|
}
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
memoizedItemKeys
|
|
1887
|
-
]);
|
|
2036
|
+
for (const itemKey of removedItems) {
|
|
2037
|
+
ignoreItemsInRefetchOnMount.delete(itemKey);
|
|
2038
|
+
}
|
|
2039
|
+
}, [ignoreItemsInRefetchOnMount, loadFromStateOnly, memoizedItemKeys]);
|
|
1888
2040
|
return storeState;
|
|
1889
2041
|
}
|
|
1890
|
-
function useItem(itemPayload,
|
|
1891
|
-
|
|
2042
|
+
function useItem(itemPayload, {
|
|
2043
|
+
selector,
|
|
2044
|
+
selectorUsesExternalDeps,
|
|
2045
|
+
disableRefetchOnMount,
|
|
2046
|
+
returnIdleStatus,
|
|
2047
|
+
returnRefetchingStatus,
|
|
2048
|
+
ensureIsLoaded,
|
|
2049
|
+
loadFromStateOnly,
|
|
2050
|
+
isOffScreen
|
|
2051
|
+
} = {}) {
|
|
1892
2052
|
const query = useMemo4(
|
|
1893
|
-
() => itemPayload === false || itemPayload === null || itemPayload === void 0 ? [] : [
|
|
1894
|
-
|
|
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
|
+
]
|
|
1895
2069
|
);
|
|
1896
|
-
const queryResult = useMultipleItems(query,
|
|
2070
|
+
const queryResult = useMultipleItems(query, {
|
|
2071
|
+
selector,
|
|
2072
|
+
selectorUsesExternalDeps,
|
|
2073
|
+
loadFromStateOnly
|
|
2074
|
+
});
|
|
1897
2075
|
const memoizedSelector = useCallback3(
|
|
1898
|
-
|
|
2076
|
+
selector ?? defaultItemDataSelector,
|
|
1899
2077
|
[]
|
|
1900
2078
|
);
|
|
1901
2079
|
const result = useMemo4(
|
|
@@ -1904,7 +2082,8 @@ function newTSDFListQueryStore({
|
|
|
1904
2082
|
isLoading: false,
|
|
1905
2083
|
status: "idle",
|
|
1906
2084
|
data: memoizedSelector(null, null),
|
|
1907
|
-
payload: itemPayload || null
|
|
2085
|
+
payload: itemPayload || null,
|
|
2086
|
+
queryMetadata: void 0
|
|
1908
2087
|
},
|
|
1909
2088
|
[itemPayload, memoizedSelector, queryResult]
|
|
1910
2089
|
);
|
|
@@ -2254,6 +2433,7 @@ function useListItemIsLoading({
|
|
|
2254
2433
|
return isLoading || isNotFound && (isRefetching || !!willBeRefetched);
|
|
2255
2434
|
}
|
|
2256
2435
|
export {
|
|
2436
|
+
getCacheId,
|
|
2257
2437
|
newTSDFCollectionStore,
|
|
2258
2438
|
newTSDFDocumentStore,
|
|
2259
2439
|
newTSDFListQueryStore,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdf",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.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",
|