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.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/main.ts
|
|
21
21
|
var main_exports = {};
|
|
22
22
|
__export(main_exports, {
|
|
23
|
+
getCacheId: () => getCacheId,
|
|
23
24
|
newTSDFCollectionStore: () => newTSDFCollectionStore,
|
|
24
25
|
newTSDFDocumentStore: () => newTSDFDocumentStore,
|
|
25
26
|
newTSDFListQueryStore: () => newTSDFListQueryStore,
|
|
@@ -645,16 +646,46 @@ function isObject(value) {
|
|
|
645
646
|
}
|
|
646
647
|
|
|
647
648
|
// src/utils/getCacheId.ts
|
|
648
|
-
function getCacheId(input) {
|
|
649
|
-
|
|
649
|
+
function getCacheId(input, maxDepth = 3) {
|
|
650
|
+
if (typeof input === "string")
|
|
651
|
+
return String(input);
|
|
652
|
+
if (!input || typeof input !== "object")
|
|
653
|
+
return `#$${input}$#`;
|
|
654
|
+
return JSON.stringify(sortValues(input, maxDepth, 0));
|
|
650
655
|
}
|
|
651
|
-
function
|
|
652
|
-
|
|
656
|
+
function sortValues(input, maxDepth, depth) {
|
|
657
|
+
if (depth >= maxDepth)
|
|
658
|
+
return input;
|
|
659
|
+
if (Array.isArray(input)) {
|
|
660
|
+
return input.map((v) => sortValues(v, maxDepth, depth + 1));
|
|
661
|
+
}
|
|
662
|
+
if (isObject(input)) {
|
|
663
|
+
return orderedProps(input, (v) => sortValues(v, maxDepth, depth + 1));
|
|
664
|
+
}
|
|
665
|
+
return input;
|
|
666
|
+
}
|
|
667
|
+
var emptyObject = {};
|
|
668
|
+
function orderedProps(obj, mapValue) {
|
|
669
|
+
const keys = Object.keys(obj);
|
|
670
|
+
if (keys.length === 0)
|
|
671
|
+
return emptyObject;
|
|
672
|
+
if (keys.length === 1) {
|
|
673
|
+
const value = obj[keys[0]];
|
|
674
|
+
if (value === void 0)
|
|
675
|
+
return emptyObject;
|
|
676
|
+
return { [keys[0]]: mapValue(value) };
|
|
677
|
+
}
|
|
678
|
+
const mappedValues = filterAndMap(keys.sort(), (k, ignore) => {
|
|
653
679
|
const value = obj[k];
|
|
654
680
|
if (value === void 0)
|
|
655
681
|
return ignore;
|
|
656
|
-
return { [k]:
|
|
682
|
+
return { [k]: mapValue(value) };
|
|
657
683
|
});
|
|
684
|
+
if (mappedValues.length === 0)
|
|
685
|
+
return emptyObject;
|
|
686
|
+
if (mappedValues.length === 1)
|
|
687
|
+
return mappedValues[0];
|
|
688
|
+
return mappedValues;
|
|
658
689
|
}
|
|
659
690
|
|
|
660
691
|
// src/collectionStore.ts
|
|
@@ -847,30 +878,43 @@ function newTSDFCollectionStore({
|
|
|
847
878
|
}
|
|
848
879
|
return store.state[getItemKey(params)];
|
|
849
880
|
}
|
|
850
|
-
function useMultipleItems(
|
|
881
|
+
function useMultipleItems(items, {
|
|
851
882
|
selector,
|
|
852
|
-
|
|
853
|
-
returnIdleStatus,
|
|
854
|
-
returnRefetchingStatus,
|
|
855
|
-
disableRefetchOnMount = globalDisableRefetchOnMount,
|
|
856
|
-
isOffScreen
|
|
883
|
+
selectorUsesExternalDeps
|
|
857
884
|
} = {}) {
|
|
858
885
|
const queriesWithId = useDeepMemo(() => {
|
|
859
|
-
return
|
|
860
|
-
return {
|
|
886
|
+
return items.map((queryProps) => {
|
|
887
|
+
return {
|
|
888
|
+
itemKey: getItemKey(queryProps.payload),
|
|
889
|
+
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
|
+
queryMetadata: queryProps.queryMetadata
|
|
896
|
+
};
|
|
861
897
|
});
|
|
862
|
-
}, [
|
|
863
|
-
const dataSelector = (0, import_react7.useCallback)(
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
898
|
+
}, [items]);
|
|
899
|
+
const dataSelector = (0, import_react7.useCallback)(
|
|
900
|
+
(itemState) => {
|
|
901
|
+
if (selector)
|
|
902
|
+
return selector(itemState);
|
|
903
|
+
return itemState;
|
|
904
|
+
},
|
|
905
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
906
|
+
[selectorUsesExternalDeps ? selector : 0]
|
|
907
|
+
);
|
|
868
908
|
const resultSelector = (0, import_react7.useCallback)(
|
|
869
909
|
(state) => {
|
|
870
910
|
return queriesWithId.map(
|
|
871
911
|
({
|
|
872
912
|
itemKey,
|
|
873
|
-
payload
|
|
913
|
+
payload,
|
|
914
|
+
omitPayload,
|
|
915
|
+
returnIdleStatus,
|
|
916
|
+
returnRefetchingStatus,
|
|
917
|
+
queryMetadata
|
|
874
918
|
}) => {
|
|
875
919
|
const item = state[itemKey];
|
|
876
920
|
if (item === null) {
|
|
@@ -880,7 +924,8 @@ function newTSDFCollectionStore({
|
|
|
880
924
|
data: dataSelector(null),
|
|
881
925
|
error: null,
|
|
882
926
|
payload: omitPayload ? void 0 : payload,
|
|
883
|
-
isLoading: false
|
|
927
|
+
isLoading: false,
|
|
928
|
+
queryMetadata
|
|
884
929
|
};
|
|
885
930
|
}
|
|
886
931
|
if (!item) {
|
|
@@ -890,7 +935,8 @@ function newTSDFCollectionStore({
|
|
|
890
935
|
data: dataSelector(null),
|
|
891
936
|
error: null,
|
|
892
937
|
payload: omitPayload ? void 0 : payload,
|
|
893
|
-
isLoading: returnIdleStatus ? false : true
|
|
938
|
+
isLoading: returnIdleStatus ? false : true,
|
|
939
|
+
queryMetadata
|
|
894
940
|
};
|
|
895
941
|
}
|
|
896
942
|
let status = item.status;
|
|
@@ -903,27 +949,22 @@ function newTSDFCollectionStore({
|
|
|
903
949
|
data: dataSelector(item.data),
|
|
904
950
|
error: item.error,
|
|
905
951
|
isLoading: status === "loading",
|
|
906
|
-
payload: omitPayload ? void 0 : item.payload
|
|
952
|
+
payload: omitPayload ? void 0 : item.payload,
|
|
953
|
+
queryMetadata
|
|
907
954
|
};
|
|
908
955
|
}
|
|
909
956
|
);
|
|
910
957
|
},
|
|
911
|
-
[
|
|
912
|
-
dataSelector,
|
|
913
|
-
omitPayload,
|
|
914
|
-
queriesWithId,
|
|
915
|
-
returnIdleStatus,
|
|
916
|
-
returnRefetchingStatus
|
|
917
|
-
]
|
|
958
|
+
[dataSelector, queriesWithId]
|
|
918
959
|
);
|
|
919
960
|
const storeState = store.useSelector(resultSelector, {
|
|
920
961
|
equalityFn: import_t_state4.deepEqual,
|
|
921
962
|
useExternalDeps: true
|
|
922
963
|
});
|
|
923
964
|
(0, import_react6.useOnEvtmitterEvent)(storeEvents, "invalidateData", (event) => {
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
965
|
+
for (const { itemKey, payload, isOffScreen } of queriesWithId) {
|
|
966
|
+
if (isOffScreen)
|
|
967
|
+
continue;
|
|
927
968
|
if (itemKey !== event.itemKey)
|
|
928
969
|
continue;
|
|
929
970
|
if (!invalidationWasTriggered.has(itemKey)) {
|
|
@@ -938,15 +979,27 @@ function newTSDFCollectionStore({
|
|
|
938
979
|
}
|
|
939
980
|
}
|
|
940
981
|
});
|
|
982
|
+
const ignoreItemsInRefetchOnMount = useConst(() => /* @__PURE__ */ new Set());
|
|
941
983
|
(0, import_react7.useEffect)(() => {
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
984
|
+
const removedQueries = new Set(ignoreItemsInRefetchOnMount);
|
|
985
|
+
for (const {
|
|
986
|
+
itemKey: itemId,
|
|
987
|
+
payload,
|
|
988
|
+
isOffScreen,
|
|
989
|
+
disableRefetchOnMount
|
|
990
|
+
} of queriesWithId) {
|
|
991
|
+
removedQueries.delete(itemId);
|
|
992
|
+
if (isOffScreen)
|
|
993
|
+
continue;
|
|
945
994
|
if (itemId) {
|
|
946
995
|
const itemState = getItemState(payload);
|
|
947
996
|
const fetchType = itemState?.refetchOnMount || "lowPriority";
|
|
997
|
+
const shouldFetch = !itemState?.wasLoaded || itemState.refetchOnMount;
|
|
998
|
+
if (!shouldFetch && ignoreItemsInRefetchOnMount.has(itemId)) {
|
|
999
|
+
continue;
|
|
1000
|
+
}
|
|
1001
|
+
ignoreItemsInRefetchOnMount.add(itemId);
|
|
948
1002
|
if (disableRefetchOnMount) {
|
|
949
|
-
const shouldFetch = !itemState?.wasLoaded || itemState.refetchOnMount;
|
|
950
1003
|
if (shouldFetch) {
|
|
951
1004
|
scheduleFetch(fetchType, payload);
|
|
952
1005
|
continue;
|
|
@@ -956,16 +1009,46 @@ function newTSDFCollectionStore({
|
|
|
956
1009
|
}
|
|
957
1010
|
}
|
|
958
1011
|
}
|
|
959
|
-
|
|
1012
|
+
for (const itemId of removedQueries) {
|
|
1013
|
+
ignoreItemsInRefetchOnMount.delete(itemId);
|
|
1014
|
+
}
|
|
1015
|
+
}, [ignoreItemsInRefetchOnMount, queriesWithId]);
|
|
960
1016
|
return storeState;
|
|
961
1017
|
}
|
|
962
|
-
function useItem(payload,
|
|
963
|
-
|
|
1018
|
+
function useItem(payload, {
|
|
1019
|
+
omitPayload,
|
|
1020
|
+
selector,
|
|
1021
|
+
selectorUsesExternalDeps,
|
|
1022
|
+
ensureIsLoaded,
|
|
1023
|
+
returnRefetchingStatus,
|
|
1024
|
+
disableRefetchOnMount,
|
|
1025
|
+
returnIdleStatus,
|
|
1026
|
+
isOffScreen
|
|
1027
|
+
} = {}) {
|
|
964
1028
|
const query = (0, import_react7.useMemo)(
|
|
965
|
-
() => payload === false || payload === null || payload === void 0 ? [] : [
|
|
966
|
-
|
|
1029
|
+
() => payload === false || payload === null || payload === void 0 ? [] : [
|
|
1030
|
+
{
|
|
1031
|
+
payload,
|
|
1032
|
+
omitPayload,
|
|
1033
|
+
returnRefetchingStatus,
|
|
1034
|
+
disableRefetchOnMount,
|
|
1035
|
+
returnIdleStatus,
|
|
1036
|
+
isOffScreen
|
|
1037
|
+
}
|
|
1038
|
+
],
|
|
1039
|
+
[
|
|
1040
|
+
disableRefetchOnMount,
|
|
1041
|
+
isOffScreen,
|
|
1042
|
+
omitPayload,
|
|
1043
|
+
returnIdleStatus,
|
|
1044
|
+
returnRefetchingStatus,
|
|
1045
|
+
payload
|
|
1046
|
+
]
|
|
967
1047
|
);
|
|
968
|
-
const item = useMultipleItems(query,
|
|
1048
|
+
const item = useMultipleItems(query, {
|
|
1049
|
+
selector,
|
|
1050
|
+
selectorUsesExternalDeps
|
|
1051
|
+
});
|
|
969
1052
|
const result = (0, import_react7.useMemo)(
|
|
970
1053
|
() => item[0] ?? {
|
|
971
1054
|
payload: void 0,
|
|
@@ -973,7 +1056,8 @@ function newTSDFCollectionStore({
|
|
|
973
1056
|
error: null,
|
|
974
1057
|
status: "idle",
|
|
975
1058
|
itemStateKey: "",
|
|
976
|
-
isLoading: false
|
|
1059
|
+
isLoading: false,
|
|
1060
|
+
queryMetadata: void 0
|
|
977
1061
|
},
|
|
978
1062
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
979
1063
|
[item]
|
|
@@ -1473,28 +1557,36 @@ function newTSDFListQueryStore({
|
|
|
1473
1557
|
}
|
|
1474
1558
|
function useMultipleListQueries(queries, {
|
|
1475
1559
|
itemSelector = defaultItemSelector,
|
|
1476
|
-
|
|
1477
|
-
returnIdleStatus,
|
|
1478
|
-
returnRefetchingStatus,
|
|
1479
|
-
loadSize,
|
|
1480
|
-
disableRefetchOnMount = globalDisableRefetchOnMount,
|
|
1481
|
-
isOffScreen
|
|
1560
|
+
selectorUsesExternalDeps
|
|
1482
1561
|
} = {}) {
|
|
1483
1562
|
const queriesWithId = useDeepMemo(() => {
|
|
1484
|
-
return queries.map((
|
|
1563
|
+
return queries.map((item) => {
|
|
1485
1564
|
return {
|
|
1486
|
-
key: getQueryKey(payload),
|
|
1487
|
-
payload
|
|
1565
|
+
key: getQueryKey(item.payload),
|
|
1566
|
+
payload: item.payload,
|
|
1567
|
+
disableRefetchOnMount: item.disableRefetchOnMount ?? globalDisableRefetchOnMount,
|
|
1568
|
+
returnIdleStatus: item.returnIdleStatus,
|
|
1569
|
+
returnRefetchingStatus: item.returnRefetchingStatus,
|
|
1570
|
+
queryMetadata: item.queryMetadata,
|
|
1571
|
+
isOffScreen: item.isOffScreen,
|
|
1572
|
+
omitPayload: item.omitPayload,
|
|
1573
|
+
loadSize: item.loadSize
|
|
1488
1574
|
};
|
|
1489
1575
|
});
|
|
1490
1576
|
}, [queries]);
|
|
1491
|
-
const dataSelector = (0, import_react9.useCallback)(itemSelector, [
|
|
1577
|
+
const dataSelector = (0, import_react9.useCallback)(itemSelector, [
|
|
1578
|
+
selectorUsesExternalDeps ? itemSelector : 0
|
|
1579
|
+
]);
|
|
1492
1580
|
const resultSelector = (0, import_react9.useCallback)(
|
|
1493
1581
|
(state) => {
|
|
1494
1582
|
return queriesWithId.map(
|
|
1495
1583
|
({
|
|
1496
1584
|
key: queryKey,
|
|
1497
|
-
payload
|
|
1585
|
+
payload,
|
|
1586
|
+
returnIdleStatus,
|
|
1587
|
+
returnRefetchingStatus,
|
|
1588
|
+
omitPayload,
|
|
1589
|
+
queryMetadata
|
|
1498
1590
|
}) => {
|
|
1499
1591
|
const query = state.queries[queryKey];
|
|
1500
1592
|
if (!query) {
|
|
@@ -1506,7 +1598,8 @@ function newTSDFListQueryStore({
|
|
|
1506
1598
|
hasMore: false,
|
|
1507
1599
|
payload: omitPayload ? void 0 : payload,
|
|
1508
1600
|
isLoading: returnIdleStatus ? false : true,
|
|
1509
|
-
isLoadingMore: false
|
|
1601
|
+
isLoadingMore: false,
|
|
1602
|
+
queryMetadata
|
|
1510
1603
|
};
|
|
1511
1604
|
}
|
|
1512
1605
|
let status = query.status;
|
|
@@ -1521,27 +1614,22 @@ function newTSDFListQueryStore({
|
|
|
1521
1614
|
hasMore: query.hasMore,
|
|
1522
1615
|
isLoading: status === "loading",
|
|
1523
1616
|
payload: omitPayload ? void 0 : query.payload,
|
|
1524
|
-
isLoadingMore: status === "loadingMore"
|
|
1617
|
+
isLoadingMore: status === "loadingMore",
|
|
1618
|
+
queryMetadata
|
|
1525
1619
|
};
|
|
1526
1620
|
}
|
|
1527
1621
|
);
|
|
1528
1622
|
},
|
|
1529
|
-
[
|
|
1530
|
-
dataSelector,
|
|
1531
|
-
omitPayload,
|
|
1532
|
-
queriesWithId,
|
|
1533
|
-
returnIdleStatus,
|
|
1534
|
-
returnRefetchingStatus
|
|
1535
|
-
]
|
|
1623
|
+
[dataSelector, queriesWithId]
|
|
1536
1624
|
);
|
|
1537
1625
|
const storeState = store.useSelector(resultSelector, {
|
|
1538
1626
|
equalityFn: import_t_state5.deepEqual,
|
|
1539
1627
|
useExternalDeps: true
|
|
1540
1628
|
});
|
|
1541
1629
|
(0, import_react8.useOnEvtmitterEvent)(storeEvents, "invalidateQuery", (event) => {
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1630
|
+
for (const { key, payload, isOffScreen } of queriesWithId) {
|
|
1631
|
+
if (isOffScreen)
|
|
1632
|
+
continue;
|
|
1545
1633
|
if (key !== event.queryKey)
|
|
1546
1634
|
continue;
|
|
1547
1635
|
if (!queryInvalidationWasTriggered.has(key)) {
|
|
@@ -1556,35 +1644,80 @@ function newTSDFListQueryStore({
|
|
|
1556
1644
|
}
|
|
1557
1645
|
}
|
|
1558
1646
|
});
|
|
1559
|
-
const
|
|
1647
|
+
const ignoreItemsInRefetchOnMount = useConst(() => /* @__PURE__ */ new Set());
|
|
1560
1648
|
(0, import_react9.useEffect)(() => {
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1649
|
+
const removedItems = new Set(ignoreItemsInRefetchOnMount);
|
|
1650
|
+
for (const {
|
|
1651
|
+
key: itemId,
|
|
1652
|
+
payload: fetchParams,
|
|
1653
|
+
isOffScreen,
|
|
1654
|
+
loadSize,
|
|
1655
|
+
disableRefetchOnMount
|
|
1656
|
+
} of queriesWithId) {
|
|
1657
|
+
removedItems.delete(itemId);
|
|
1658
|
+
if (isOffScreen)
|
|
1659
|
+
continue;
|
|
1564
1660
|
if (itemId) {
|
|
1565
1661
|
const itemState = getQueryState(fetchParams);
|
|
1566
1662
|
const fetchType = itemState?.refetchOnMount || "lowPriority";
|
|
1663
|
+
const shouldFetch = !itemState || !itemState.wasLoaded || itemState.refetchOnMount;
|
|
1664
|
+
if (!shouldFetch && ignoreItemsInRefetchOnMount.has(itemId)) {
|
|
1665
|
+
continue;
|
|
1666
|
+
}
|
|
1667
|
+
ignoreItemsInRefetchOnMount.add(itemId);
|
|
1567
1668
|
if (disableRefetchOnMount) {
|
|
1568
|
-
const shouldFetch = !itemState || !itemState.wasLoaded || itemState.refetchOnMount;
|
|
1569
1669
|
if (shouldFetch) {
|
|
1570
|
-
scheduleListQueryFetch(fetchType, fetchParams,
|
|
1670
|
+
scheduleListQueryFetch(fetchType, fetchParams, loadSize);
|
|
1571
1671
|
continue;
|
|
1572
1672
|
}
|
|
1573
1673
|
} else {
|
|
1574
|
-
scheduleListQueryFetch(fetchType, fetchParams,
|
|
1674
|
+
scheduleListQueryFetch(fetchType, fetchParams, loadSize);
|
|
1575
1675
|
}
|
|
1576
1676
|
}
|
|
1577
1677
|
}
|
|
1578
|
-
|
|
1678
|
+
for (const itemKey of removedItems) {
|
|
1679
|
+
ignoreItemsInRefetchOnMount.delete(itemKey);
|
|
1680
|
+
}
|
|
1681
|
+
}, [ignoreItemsInRefetchOnMount, queriesWithId]);
|
|
1579
1682
|
return storeState;
|
|
1580
1683
|
}
|
|
1581
|
-
function useListQuery(payload,
|
|
1582
|
-
|
|
1684
|
+
function useListQuery(payload, {
|
|
1685
|
+
isOffScreen,
|
|
1686
|
+
itemSelector,
|
|
1687
|
+
disableRefetchOnMount,
|
|
1688
|
+
returnIdleStatus,
|
|
1689
|
+
returnRefetchingStatus,
|
|
1690
|
+
loadSize,
|
|
1691
|
+
omitPayload,
|
|
1692
|
+
ensureIsLoaded,
|
|
1693
|
+
selectorUsesExternalDeps
|
|
1694
|
+
} = {}) {
|
|
1583
1695
|
const query = (0, import_react9.useMemo)(
|
|
1584
|
-
() => payload === false || payload === null || payload === void 0 ? [] : [
|
|
1585
|
-
|
|
1696
|
+
() => payload === false || payload === null || payload === void 0 ? [] : [
|
|
1697
|
+
{
|
|
1698
|
+
payload,
|
|
1699
|
+
disableRefetchOnMount,
|
|
1700
|
+
returnIdleStatus,
|
|
1701
|
+
returnRefetchingStatus,
|
|
1702
|
+
omitPayload,
|
|
1703
|
+
isOffScreen,
|
|
1704
|
+
loadSize
|
|
1705
|
+
}
|
|
1706
|
+
],
|
|
1707
|
+
[
|
|
1708
|
+
disableRefetchOnMount,
|
|
1709
|
+
isOffScreen,
|
|
1710
|
+
loadSize,
|
|
1711
|
+
omitPayload,
|
|
1712
|
+
payload,
|
|
1713
|
+
returnIdleStatus,
|
|
1714
|
+
returnRefetchingStatus
|
|
1715
|
+
]
|
|
1586
1716
|
);
|
|
1587
|
-
const queryResult = useMultipleListQueries(query,
|
|
1717
|
+
const queryResult = useMultipleListQueries(query, {
|
|
1718
|
+
itemSelector,
|
|
1719
|
+
selectorUsesExternalDeps
|
|
1720
|
+
});
|
|
1588
1721
|
const result = (0, import_react9.useMemo)(
|
|
1589
1722
|
() => queryResult[0] ?? {
|
|
1590
1723
|
payload: void 0,
|
|
@@ -1594,7 +1727,8 @@ function newTSDFListQueryStore({
|
|
|
1594
1727
|
status: "idle",
|
|
1595
1728
|
queryKey: "",
|
|
1596
1729
|
items: [],
|
|
1597
|
-
isLoadingMore: false
|
|
1730
|
+
isLoadingMore: false,
|
|
1731
|
+
queryMetadata: void 0
|
|
1598
1732
|
},
|
|
1599
1733
|
[queryResult]
|
|
1600
1734
|
);
|
|
@@ -1802,30 +1936,37 @@ function newTSDFListQueryStore({
|
|
|
1802
1936
|
function defaultItemDataSelector(data) {
|
|
1803
1937
|
return data;
|
|
1804
1938
|
}
|
|
1805
|
-
function useMultipleItems(
|
|
1939
|
+
function useMultipleItems(items, {
|
|
1806
1940
|
selector = defaultItemDataSelector,
|
|
1807
|
-
returnIdleStatus,
|
|
1808
|
-
returnRefetchingStatus,
|
|
1809
|
-
disableRefetchOnMount,
|
|
1810
1941
|
loadFromStateOnly,
|
|
1811
|
-
|
|
1942
|
+
selectorUsesExternalDeps
|
|
1812
1943
|
} = {}) {
|
|
1813
|
-
const dataSelector = (0, import_react9.useCallback)(selector, [
|
|
1944
|
+
const dataSelector = (0, import_react9.useCallback)(selector, [
|
|
1945
|
+
selectorUsesExternalDeps ? selector : 0
|
|
1946
|
+
]);
|
|
1814
1947
|
const memoizedItemKeys = useDeepMemo(
|
|
1815
|
-
() =>
|
|
1948
|
+
() => items.map(
|
|
1816
1949
|
(itemPayload) => ({
|
|
1817
|
-
|
|
1818
|
-
|
|
1950
|
+
itemKey: getItemKey(itemPayload.payload),
|
|
1951
|
+
payload: itemPayload.payload,
|
|
1952
|
+
disableRefetchOnMount: itemPayload.disableRefetchOnMount,
|
|
1953
|
+
returnIdleStatus: itemPayload.returnIdleStatus,
|
|
1954
|
+
returnRefetchingStatus: itemPayload.returnRefetchingStatus,
|
|
1955
|
+
isOffScreen: itemPayload.isOffScreen,
|
|
1956
|
+
queryMetadata: itemPayload.queryMetadata
|
|
1819
1957
|
})
|
|
1820
1958
|
),
|
|
1821
|
-
[
|
|
1959
|
+
[items]
|
|
1822
1960
|
);
|
|
1823
1961
|
const resultSelector = (0, import_react9.useCallback)(
|
|
1824
1962
|
(state) => {
|
|
1825
1963
|
return memoizedItemKeys.map(
|
|
1826
1964
|
({
|
|
1827
1965
|
itemKey,
|
|
1828
|
-
payload
|
|
1966
|
+
payload,
|
|
1967
|
+
queryMetadata,
|
|
1968
|
+
returnRefetchingStatus,
|
|
1969
|
+
returnIdleStatus
|
|
1829
1970
|
}) => {
|
|
1830
1971
|
const itemQuery = state.itemQueries[itemKey];
|
|
1831
1972
|
const itemState = state.items[itemKey];
|
|
@@ -1835,7 +1976,8 @@ function newTSDFListQueryStore({
|
|
|
1835
1976
|
error: null,
|
|
1836
1977
|
isLoading: false,
|
|
1837
1978
|
payload,
|
|
1838
|
-
data: dataSelector(null, null)
|
|
1979
|
+
data: dataSelector(null, null),
|
|
1980
|
+
queryMetadata
|
|
1839
1981
|
};
|
|
1840
1982
|
}
|
|
1841
1983
|
if (!itemQuery) {
|
|
@@ -1844,7 +1986,8 @@ function newTSDFListQueryStore({
|
|
|
1844
1986
|
error: null,
|
|
1845
1987
|
isLoading: returnIdleStatus ? false : true,
|
|
1846
1988
|
payload,
|
|
1847
|
-
data: dataSelector(null, null)
|
|
1989
|
+
data: dataSelector(null, null),
|
|
1990
|
+
queryMetadata
|
|
1848
1991
|
};
|
|
1849
1992
|
}
|
|
1850
1993
|
let status = itemQuery.status;
|
|
@@ -1856,26 +1999,24 @@ function newTSDFListQueryStore({
|
|
|
1856
1999
|
error: itemQuery.error,
|
|
1857
2000
|
isLoading: status === "loading",
|
|
1858
2001
|
data: dataSelector(itemState ?? null, itemQuery.payload),
|
|
1859
|
-
payload
|
|
2002
|
+
payload,
|
|
2003
|
+
queryMetadata
|
|
1860
2004
|
};
|
|
1861
2005
|
}
|
|
1862
2006
|
);
|
|
1863
2007
|
},
|
|
1864
|
-
[
|
|
1865
|
-
dataSelector,
|
|
1866
|
-
memoizedItemKeys,
|
|
1867
|
-
returnIdleStatus,
|
|
1868
|
-
returnRefetchingStatus
|
|
1869
|
-
]
|
|
2008
|
+
[dataSelector, memoizedItemKeys]
|
|
1870
2009
|
);
|
|
1871
2010
|
const storeState = store.useSelector(resultSelector, {
|
|
1872
2011
|
equalityFn: import_t_state5.deepEqual,
|
|
1873
2012
|
useExternalDeps: true
|
|
1874
2013
|
});
|
|
1875
2014
|
(0, import_react8.useOnEvtmitterEvent)(storeEvents, "invalidateItem", (event) => {
|
|
1876
|
-
if (loadFromStateOnly
|
|
2015
|
+
if (loadFromStateOnly)
|
|
1877
2016
|
return;
|
|
1878
|
-
for (const { payload, itemKey } of memoizedItemKeys) {
|
|
2017
|
+
for (const { payload, itemKey, isOffScreen } of memoizedItemKeys) {
|
|
2018
|
+
if (isOffScreen)
|
|
2019
|
+
continue;
|
|
1879
2020
|
if (itemKey !== event.itemKey)
|
|
1880
2021
|
continue;
|
|
1881
2022
|
if (!itemInvalidationWasTriggered.has(itemKey)) {
|
|
@@ -1890,15 +2031,29 @@ function newTSDFListQueryStore({
|
|
|
1890
2031
|
}
|
|
1891
2032
|
}
|
|
1892
2033
|
});
|
|
2034
|
+
const ignoreItemsInRefetchOnMount = useConst(() => /* @__PURE__ */ new Set());
|
|
1893
2035
|
(0, import_react9.useEffect)(() => {
|
|
1894
|
-
if (loadFromStateOnly
|
|
2036
|
+
if (loadFromStateOnly)
|
|
1895
2037
|
return;
|
|
1896
|
-
|
|
2038
|
+
const removedItems = new Set(ignoreItemsInRefetchOnMount);
|
|
2039
|
+
for (const {
|
|
2040
|
+
payload,
|
|
2041
|
+
itemKey,
|
|
2042
|
+
isOffScreen,
|
|
2043
|
+
disableRefetchOnMount
|
|
2044
|
+
} of memoizedItemKeys) {
|
|
2045
|
+
removedItems.delete(itemKey);
|
|
2046
|
+
if (isOffScreen)
|
|
2047
|
+
continue;
|
|
1897
2048
|
if (itemKey) {
|
|
1898
2049
|
const itemState = store.state.itemQueries[itemKey];
|
|
1899
2050
|
const fetchType = itemState?.refetchOnMount || "lowPriority";
|
|
2051
|
+
const shouldFetch = !itemState || !itemState.wasLoaded || itemState.refetchOnMount;
|
|
2052
|
+
if (!shouldFetch && ignoreItemsInRefetchOnMount.has(itemKey)) {
|
|
2053
|
+
continue;
|
|
2054
|
+
}
|
|
2055
|
+
ignoreItemsInRefetchOnMount.add(itemKey);
|
|
1900
2056
|
if (disableRefetchOnMount) {
|
|
1901
|
-
const shouldFetch = !itemState || !itemState.wasLoaded || itemState.refetchOnMount;
|
|
1902
2057
|
if (shouldFetch) {
|
|
1903
2058
|
scheduleItemFetch(fetchType, payload);
|
|
1904
2059
|
return;
|
|
@@ -1908,23 +2063,47 @@ function newTSDFListQueryStore({
|
|
|
1908
2063
|
}
|
|
1909
2064
|
}
|
|
1910
2065
|
}
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
memoizedItemKeys
|
|
1916
|
-
]);
|
|
2066
|
+
for (const itemKey of removedItems) {
|
|
2067
|
+
ignoreItemsInRefetchOnMount.delete(itemKey);
|
|
2068
|
+
}
|
|
2069
|
+
}, [ignoreItemsInRefetchOnMount, loadFromStateOnly, memoizedItemKeys]);
|
|
1917
2070
|
return storeState;
|
|
1918
2071
|
}
|
|
1919
|
-
function useItem(itemPayload,
|
|
1920
|
-
|
|
2072
|
+
function useItem(itemPayload, {
|
|
2073
|
+
selector,
|
|
2074
|
+
selectorUsesExternalDeps,
|
|
2075
|
+
disableRefetchOnMount,
|
|
2076
|
+
returnIdleStatus,
|
|
2077
|
+
returnRefetchingStatus,
|
|
2078
|
+
ensureIsLoaded,
|
|
2079
|
+
loadFromStateOnly,
|
|
2080
|
+
isOffScreen
|
|
2081
|
+
} = {}) {
|
|
1921
2082
|
const query = (0, import_react9.useMemo)(
|
|
1922
|
-
() => itemPayload === false || itemPayload === null || itemPayload === void 0 ? [] : [
|
|
1923
|
-
|
|
2083
|
+
() => itemPayload === false || itemPayload === null || itemPayload === void 0 ? [] : [
|
|
2084
|
+
{
|
|
2085
|
+
payload: itemPayload,
|
|
2086
|
+
disableRefetchOnMount,
|
|
2087
|
+
isOffScreen,
|
|
2088
|
+
returnIdleStatus,
|
|
2089
|
+
returnRefetchingStatus
|
|
2090
|
+
}
|
|
2091
|
+
],
|
|
2092
|
+
[
|
|
2093
|
+
itemPayload,
|
|
2094
|
+
disableRefetchOnMount,
|
|
2095
|
+
isOffScreen,
|
|
2096
|
+
returnIdleStatus,
|
|
2097
|
+
returnRefetchingStatus
|
|
2098
|
+
]
|
|
1924
2099
|
);
|
|
1925
|
-
const queryResult = useMultipleItems(query,
|
|
2100
|
+
const queryResult = useMultipleItems(query, {
|
|
2101
|
+
selector,
|
|
2102
|
+
selectorUsesExternalDeps,
|
|
2103
|
+
loadFromStateOnly
|
|
2104
|
+
});
|
|
1926
2105
|
const memoizedSelector = (0, import_react9.useCallback)(
|
|
1927
|
-
|
|
2106
|
+
selector ?? defaultItemDataSelector,
|
|
1928
2107
|
[]
|
|
1929
2108
|
);
|
|
1930
2109
|
const result = (0, import_react9.useMemo)(
|
|
@@ -1933,7 +2112,8 @@ function newTSDFListQueryStore({
|
|
|
1933
2112
|
isLoading: false,
|
|
1934
2113
|
status: "idle",
|
|
1935
2114
|
data: memoizedSelector(null, null),
|
|
1936
|
-
payload: itemPayload || null
|
|
2115
|
+
payload: itemPayload || null,
|
|
2116
|
+
queryMetadata: void 0
|
|
1937
2117
|
},
|
|
1938
2118
|
[itemPayload, memoizedSelector, queryResult]
|
|
1939
2119
|
);
|
|
@@ -2284,6 +2464,7 @@ function useListItemIsLoading({
|
|
|
2284
2464
|
}
|
|
2285
2465
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2286
2466
|
0 && (module.exports = {
|
|
2467
|
+
getCacheId,
|
|
2287
2468
|
newTSDFCollectionStore,
|
|
2288
2469
|
newTSDFDocumentStore,
|
|
2289
2470
|
newTSDFListQueryStore,
|