tsdf 12.6.1 → 12.7.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 +34 -15
- package/dist/main.d.cts +11 -4
- package/dist/main.d.ts +11 -4
- package/dist/main.js +34 -15
- package/package.json +1 -1
package/dist/main.cjs
CHANGED
|
@@ -50,7 +50,7 @@ function createFetchOrquestrator({
|
|
|
50
50
|
let mutationIsInProgress = false;
|
|
51
51
|
let lastFetchStartTime = 0;
|
|
52
52
|
let lastFetchDuration = 0;
|
|
53
|
-
let onMutationEnd =
|
|
53
|
+
let onMutationEnd = null;
|
|
54
54
|
let lastFetchWasAborted = false;
|
|
55
55
|
let abortFetchsBeforeOrEqual = 0;
|
|
56
56
|
function setLastFetchDurantion(duration) {
|
|
@@ -78,9 +78,9 @@ function createFetchOrquestrator({
|
|
|
78
78
|
function endMutation(id) {
|
|
79
79
|
if (id === lastMutationIdStarted) {
|
|
80
80
|
mutationIsInProgress = false;
|
|
81
|
-
if (onMutationEnd
|
|
82
|
-
onMutationEnd
|
|
83
|
-
onMutationEnd =
|
|
81
|
+
if (onMutationEnd) {
|
|
82
|
+
onMutationEnd();
|
|
83
|
+
onMutationEnd = null;
|
|
84
84
|
}
|
|
85
85
|
flushScheduledFetch();
|
|
86
86
|
return true;
|
|
@@ -222,13 +222,13 @@ function createFetchOrquestrator({
|
|
|
222
222
|
};
|
|
223
223
|
return true;
|
|
224
224
|
} else if (mutationIsInProgress) {
|
|
225
|
-
onMutationEnd
|
|
225
|
+
onMutationEnd = () => {
|
|
226
226
|
const added = addDelayedRTU(Date.now(), params);
|
|
227
227
|
if (!added) {
|
|
228
228
|
on?.("scheduled-rt-fetch-started");
|
|
229
229
|
scheduleFetch("highPriority", params);
|
|
230
230
|
}
|
|
231
|
-
}
|
|
231
|
+
};
|
|
232
232
|
return true;
|
|
233
233
|
} else {
|
|
234
234
|
if (!addDelayedRTU(startTime, params)) {
|
|
@@ -497,7 +497,8 @@ function newTSDFDocumentStore({
|
|
|
497
497
|
}
|
|
498
498
|
function useDocument({
|
|
499
499
|
selector,
|
|
500
|
-
|
|
500
|
+
isOffScreen,
|
|
501
|
+
disabled = isOffScreen,
|
|
501
502
|
returnRefetchingStatus,
|
|
502
503
|
disableRefetchOnMount = globalDisableRefetchOnMount,
|
|
503
504
|
returnIdleStatus = !!disabled,
|
|
@@ -527,6 +528,8 @@ function newTSDFDocumentStore({
|
|
|
527
528
|
useExternalDeps: true
|
|
528
529
|
});
|
|
529
530
|
(0, import_react5.useOnEvtmitterEvent)(storeEvents, "invalidateData", (priority) => {
|
|
531
|
+
if (disabled)
|
|
532
|
+
return;
|
|
530
533
|
if (!invalidationWasTriggered) {
|
|
531
534
|
store.setKey("refetchOnMount", false);
|
|
532
535
|
scheduleFetch(priority);
|
|
@@ -849,7 +852,8 @@ function newTSDFCollectionStore({
|
|
|
849
852
|
omitPayload,
|
|
850
853
|
returnIdleStatus,
|
|
851
854
|
returnRefetchingStatus,
|
|
852
|
-
disableRefetchOnMount = globalDisableRefetchOnMount
|
|
855
|
+
disableRefetchOnMount = globalDisableRefetchOnMount,
|
|
856
|
+
isOffScreen
|
|
853
857
|
} = {}) {
|
|
854
858
|
const queriesWithId = useDeepMemo(() => {
|
|
855
859
|
return queries.map((payload) => {
|
|
@@ -917,6 +921,8 @@ function newTSDFCollectionStore({
|
|
|
917
921
|
useExternalDeps: true
|
|
918
922
|
});
|
|
919
923
|
(0, import_react6.useOnEvtmitterEvent)(storeEvents, "invalidateData", (event) => {
|
|
924
|
+
if (isOffScreen)
|
|
925
|
+
return;
|
|
920
926
|
for (const { itemKey, payload } of queriesWithId) {
|
|
921
927
|
if (itemKey !== event.itemKey)
|
|
922
928
|
continue;
|
|
@@ -933,6 +939,8 @@ function newTSDFCollectionStore({
|
|
|
933
939
|
}
|
|
934
940
|
});
|
|
935
941
|
(0, import_react7.useEffect)(() => {
|
|
942
|
+
if (isOffScreen)
|
|
943
|
+
return;
|
|
936
944
|
for (const { itemKey: itemId, payload } of queriesWithId) {
|
|
937
945
|
if (itemId) {
|
|
938
946
|
const itemState = getItemState(payload);
|
|
@@ -948,7 +956,7 @@ function newTSDFCollectionStore({
|
|
|
948
956
|
}
|
|
949
957
|
}
|
|
950
958
|
}
|
|
951
|
-
}, [disableRefetchOnMount, queriesWithId]);
|
|
959
|
+
}, [disableRefetchOnMount, isOffScreen, queriesWithId]);
|
|
952
960
|
return storeState;
|
|
953
961
|
}
|
|
954
962
|
function useItem(payload, options = {}) {
|
|
@@ -1469,7 +1477,8 @@ function newTSDFListQueryStore({
|
|
|
1469
1477
|
returnIdleStatus,
|
|
1470
1478
|
returnRefetchingStatus,
|
|
1471
1479
|
loadSize,
|
|
1472
|
-
disableRefetchOnMount = globalDisableRefetchOnMount
|
|
1480
|
+
disableRefetchOnMount = globalDisableRefetchOnMount,
|
|
1481
|
+
isOffScreen
|
|
1473
1482
|
} = {}) {
|
|
1474
1483
|
const queriesWithId = useDeepMemo(() => {
|
|
1475
1484
|
return queries.map((payload) => {
|
|
@@ -1530,6 +1539,8 @@ function newTSDFListQueryStore({
|
|
|
1530
1539
|
useExternalDeps: true
|
|
1531
1540
|
});
|
|
1532
1541
|
(0, import_react8.useOnEvtmitterEvent)(storeEvents, "invalidateQuery", (event) => {
|
|
1542
|
+
if (isOffScreen)
|
|
1543
|
+
return;
|
|
1533
1544
|
for (const { key, payload } of queriesWithId) {
|
|
1534
1545
|
if (key !== event.queryKey)
|
|
1535
1546
|
continue;
|
|
@@ -1547,6 +1558,8 @@ function newTSDFListQueryStore({
|
|
|
1547
1558
|
});
|
|
1548
1559
|
const loadSizeConst = useConst(() => loadSize);
|
|
1549
1560
|
(0, import_react9.useEffect)(() => {
|
|
1561
|
+
if (isOffScreen)
|
|
1562
|
+
return;
|
|
1550
1563
|
for (const { key: itemId, payload: fetchParams } of queriesWithId) {
|
|
1551
1564
|
if (itemId) {
|
|
1552
1565
|
const itemState = getQueryState(fetchParams);
|
|
@@ -1562,7 +1575,7 @@ function newTSDFListQueryStore({
|
|
|
1562
1575
|
}
|
|
1563
1576
|
}
|
|
1564
1577
|
}
|
|
1565
|
-
}, [disableRefetchOnMount, loadSizeConst, queriesWithId]);
|
|
1578
|
+
}, [disableRefetchOnMount, isOffScreen, loadSizeConst, queriesWithId]);
|
|
1566
1579
|
return storeState;
|
|
1567
1580
|
}
|
|
1568
1581
|
function useListQuery(payload, options = {}) {
|
|
@@ -1794,7 +1807,8 @@ function newTSDFListQueryStore({
|
|
|
1794
1807
|
returnIdleStatus,
|
|
1795
1808
|
returnRefetchingStatus,
|
|
1796
1809
|
disableRefetchOnMount,
|
|
1797
|
-
loadFromStateOnly
|
|
1810
|
+
loadFromStateOnly,
|
|
1811
|
+
isOffScreen
|
|
1798
1812
|
} = {}) {
|
|
1799
1813
|
const dataSelector = (0, import_react9.useCallback)(selector, []);
|
|
1800
1814
|
const memoizedItemKeys = useDeepMemo(
|
|
@@ -1859,7 +1873,7 @@ function newTSDFListQueryStore({
|
|
|
1859
1873
|
useExternalDeps: true
|
|
1860
1874
|
});
|
|
1861
1875
|
(0, import_react8.useOnEvtmitterEvent)(storeEvents, "invalidateItem", (event) => {
|
|
1862
|
-
if (loadFromStateOnly)
|
|
1876
|
+
if (loadFromStateOnly || isOffScreen)
|
|
1863
1877
|
return;
|
|
1864
1878
|
for (const { payload, itemKey } of memoizedItemKeys) {
|
|
1865
1879
|
if (itemKey !== event.itemKey)
|
|
@@ -1877,7 +1891,7 @@ function newTSDFListQueryStore({
|
|
|
1877
1891
|
}
|
|
1878
1892
|
});
|
|
1879
1893
|
(0, import_react9.useEffect)(() => {
|
|
1880
|
-
if (loadFromStateOnly)
|
|
1894
|
+
if (loadFromStateOnly || isOffScreen)
|
|
1881
1895
|
return;
|
|
1882
1896
|
for (const { payload, itemKey } of memoizedItemKeys) {
|
|
1883
1897
|
if (itemKey) {
|
|
@@ -1894,7 +1908,12 @@ function newTSDFListQueryStore({
|
|
|
1894
1908
|
}
|
|
1895
1909
|
}
|
|
1896
1910
|
}
|
|
1897
|
-
}, [
|
|
1911
|
+
}, [
|
|
1912
|
+
disableRefetchOnMount,
|
|
1913
|
+
isOffScreen,
|
|
1914
|
+
loadFromStateOnly,
|
|
1915
|
+
memoizedItemKeys
|
|
1916
|
+
]);
|
|
1898
1917
|
return storeState;
|
|
1899
1918
|
}
|
|
1900
1919
|
function useItem(itemPayload, options = {}) {
|
package/dist/main.d.cts
CHANGED
|
@@ -44,9 +44,10 @@ declare function newTSDFDocumentStore<State extends ValidStoreState, NError>({ d
|
|
|
44
44
|
}>;
|
|
45
45
|
scheduleFetch: (fetchType: FetchType) => ScheduleFetchResults;
|
|
46
46
|
invalidateData: (priority?: FetchType) => void;
|
|
47
|
-
useDocument: <Selected = State | null>({ selector, disabled, returnRefetchingStatus, disableRefetchOnMount, returnIdleStatus, ensureIsLoaded, }?: {
|
|
47
|
+
useDocument: <Selected = State | null>({ selector, isOffScreen, disabled, returnRefetchingStatus, disableRefetchOnMount, returnIdleStatus, ensureIsLoaded, }?: {
|
|
48
48
|
selector?: ((data: State | null) => Selected) | undefined;
|
|
49
49
|
disabled?: boolean | undefined;
|
|
50
|
+
isOffScreen?: boolean | undefined;
|
|
50
51
|
disableRefetchOnMount?: boolean | undefined;
|
|
51
52
|
returnIdleStatus?: boolean | undefined;
|
|
52
53
|
ensureIsLoaded?: boolean | undefined;
|
|
@@ -109,12 +110,13 @@ declare function newTSDFCollectionStore<ItemState extends ValidStoreState, NErro
|
|
|
109
110
|
data: ItemState;
|
|
110
111
|
error: null;
|
|
111
112
|
}>;
|
|
112
|
-
useMultipleItems: <Selected = ItemState | null>(queries: readonly ItemPayload[], { selector, omitPayload, returnIdleStatus, returnRefetchingStatus, disableRefetchOnMount, }?: {
|
|
113
|
+
useMultipleItems: <Selected = ItemState | null>(queries: readonly ItemPayload[], { selector, omitPayload, returnIdleStatus, returnRefetchingStatus, disableRefetchOnMount, isOffScreen, }?: {
|
|
113
114
|
selector?: ((data: ItemState | null) => Selected) | undefined;
|
|
114
115
|
omitPayload?: boolean | undefined;
|
|
115
116
|
disableRefetchOnMount?: boolean | undefined;
|
|
116
117
|
returnIdleStatus?: boolean | undefined;
|
|
117
118
|
returnRefetchingStatus?: boolean | undefined;
|
|
119
|
+
isOffScreen?: boolean | undefined;
|
|
118
120
|
}) => readonly TSFDUseCollectionItemReturn<Selected, ItemPayload, NError>[];
|
|
119
121
|
useItem: <Selected_1 = ItemState | null>(payload: ItemPayload | undefined | false | null, options?: {
|
|
120
122
|
selector?: ((data: ItemState | null) => Selected_1) | undefined;
|
|
@@ -123,6 +125,7 @@ declare function newTSDFCollectionStore<ItemState extends ValidStoreState, NErro
|
|
|
123
125
|
disableRefetchOnMount?: boolean | undefined;
|
|
124
126
|
ensureIsLoaded?: boolean | undefined;
|
|
125
127
|
returnIdleStatus?: boolean | undefined;
|
|
128
|
+
isOffScreen?: boolean | undefined;
|
|
126
129
|
}) => TSFDUseCollectionItemReturn<Selected_1, ItemPayload, NError>;
|
|
127
130
|
reset: () => void;
|
|
128
131
|
getItemKey: (params: ItemPayload) => string;
|
|
@@ -276,13 +279,14 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
276
279
|
error: null;
|
|
277
280
|
hasMore: boolean;
|
|
278
281
|
}>;
|
|
279
|
-
useMultipleListQueries: <SelectedItem = ItemState>(queries: readonly QueryPayload[], { itemSelector, omitPayload, returnIdleStatus, returnRefetchingStatus, loadSize, disableRefetchOnMount, }?: {
|
|
282
|
+
useMultipleListQueries: <SelectedItem = ItemState>(queries: readonly QueryPayload[], { itemSelector, omitPayload, returnIdleStatus, returnRefetchingStatus, loadSize, disableRefetchOnMount, isOffScreen, }?: {
|
|
280
283
|
itemSelector?: ((data: ItemState, id: ItemPayload, itemKey: string) => SelectedItem) | undefined;
|
|
281
284
|
omitPayload?: boolean | undefined;
|
|
282
285
|
disableRefetchOnMount?: boolean | undefined;
|
|
283
286
|
returnIdleStatus?: boolean | undefined;
|
|
284
287
|
returnRefetchingStatus?: boolean | undefined;
|
|
285
288
|
loadSize?: number | undefined;
|
|
289
|
+
isOffScreen?: boolean | undefined;
|
|
286
290
|
}) => readonly TSFDUseListQueryReturn<SelectedItem, QueryPayload, NError>[];
|
|
287
291
|
useListQuery: <SelectedItem_1 = ItemState>(payload: QueryPayload | false | null | undefined, options?: {
|
|
288
292
|
itemSelector?: ((data: ItemState, id: ItemPayload, itemKey: string) => SelectedItem_1) | undefined;
|
|
@@ -292,6 +296,7 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
292
296
|
returnRefetchingStatus?: boolean | undefined;
|
|
293
297
|
ensureIsLoaded?: boolean | undefined;
|
|
294
298
|
loadSize?: number | undefined;
|
|
299
|
+
isOffScreen?: boolean | undefined;
|
|
295
300
|
}) => TSFDUseListQueryReturn<SelectedItem_1, QueryPayload, NError>;
|
|
296
301
|
getItemKey: (params: ItemPayload) => string;
|
|
297
302
|
useItem: <SelectedItem_2 = ItemState | null>(itemPayload: ItemPayload | false | null | undefined, options?: {
|
|
@@ -301,13 +306,15 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
301
306
|
returnRefetchingStatus?: boolean | undefined;
|
|
302
307
|
ensureIsLoaded?: boolean | undefined;
|
|
303
308
|
loadFromStateOnly?: boolean | undefined;
|
|
309
|
+
isOffScreen?: boolean | undefined;
|
|
304
310
|
}) => TSFDUseListItemReturn<SelectedItem_2, NError, ItemPayload>;
|
|
305
|
-
useMultipleItems: <SelectedItem_3 = ItemState | null>(itemsPayload_: ItemPayload[], { selector, returnIdleStatus, returnRefetchingStatus, disableRefetchOnMount, loadFromStateOnly, }?: {
|
|
311
|
+
useMultipleItems: <SelectedItem_3 = ItemState | null>(itemsPayload_: ItemPayload[], { selector, returnIdleStatus, returnRefetchingStatus, disableRefetchOnMount, loadFromStateOnly, isOffScreen, }?: {
|
|
306
312
|
selector?: ((data: ItemState | null, id: ItemPayload | null) => SelectedItem_3) | undefined;
|
|
307
313
|
disableRefetchOnMount?: boolean | undefined;
|
|
308
314
|
returnIdleStatus?: boolean | undefined;
|
|
309
315
|
returnRefetchingStatus?: boolean | undefined;
|
|
310
316
|
loadFromStateOnly?: boolean | undefined;
|
|
317
|
+
isOffScreen?: boolean | undefined;
|
|
311
318
|
}) => readonly TSFDUseListItemReturn<SelectedItem_3, NError, ItemPayload>[];
|
|
312
319
|
addItemToState: (itemPayload: ItemPayload, data: ItemState, { addItemToQueries, }?: {
|
|
313
320
|
addItemToQueries?: {
|
package/dist/main.d.ts
CHANGED
|
@@ -44,9 +44,10 @@ declare function newTSDFDocumentStore<State extends ValidStoreState, NError>({ d
|
|
|
44
44
|
}>;
|
|
45
45
|
scheduleFetch: (fetchType: FetchType) => ScheduleFetchResults;
|
|
46
46
|
invalidateData: (priority?: FetchType) => void;
|
|
47
|
-
useDocument: <Selected = State | null>({ selector, disabled, returnRefetchingStatus, disableRefetchOnMount, returnIdleStatus, ensureIsLoaded, }?: {
|
|
47
|
+
useDocument: <Selected = State | null>({ selector, isOffScreen, disabled, returnRefetchingStatus, disableRefetchOnMount, returnIdleStatus, ensureIsLoaded, }?: {
|
|
48
48
|
selector?: ((data: State | null) => Selected) | undefined;
|
|
49
49
|
disabled?: boolean | undefined;
|
|
50
|
+
isOffScreen?: boolean | undefined;
|
|
50
51
|
disableRefetchOnMount?: boolean | undefined;
|
|
51
52
|
returnIdleStatus?: boolean | undefined;
|
|
52
53
|
ensureIsLoaded?: boolean | undefined;
|
|
@@ -109,12 +110,13 @@ declare function newTSDFCollectionStore<ItemState extends ValidStoreState, NErro
|
|
|
109
110
|
data: ItemState;
|
|
110
111
|
error: null;
|
|
111
112
|
}>;
|
|
112
|
-
useMultipleItems: <Selected = ItemState | null>(queries: readonly ItemPayload[], { selector, omitPayload, returnIdleStatus, returnRefetchingStatus, disableRefetchOnMount, }?: {
|
|
113
|
+
useMultipleItems: <Selected = ItemState | null>(queries: readonly ItemPayload[], { selector, omitPayload, returnIdleStatus, returnRefetchingStatus, disableRefetchOnMount, isOffScreen, }?: {
|
|
113
114
|
selector?: ((data: ItemState | null) => Selected) | undefined;
|
|
114
115
|
omitPayload?: boolean | undefined;
|
|
115
116
|
disableRefetchOnMount?: boolean | undefined;
|
|
116
117
|
returnIdleStatus?: boolean | undefined;
|
|
117
118
|
returnRefetchingStatus?: boolean | undefined;
|
|
119
|
+
isOffScreen?: boolean | undefined;
|
|
118
120
|
}) => readonly TSFDUseCollectionItemReturn<Selected, ItemPayload, NError>[];
|
|
119
121
|
useItem: <Selected_1 = ItemState | null>(payload: ItemPayload | undefined | false | null, options?: {
|
|
120
122
|
selector?: ((data: ItemState | null) => Selected_1) | undefined;
|
|
@@ -123,6 +125,7 @@ declare function newTSDFCollectionStore<ItemState extends ValidStoreState, NErro
|
|
|
123
125
|
disableRefetchOnMount?: boolean | undefined;
|
|
124
126
|
ensureIsLoaded?: boolean | undefined;
|
|
125
127
|
returnIdleStatus?: boolean | undefined;
|
|
128
|
+
isOffScreen?: boolean | undefined;
|
|
126
129
|
}) => TSFDUseCollectionItemReturn<Selected_1, ItemPayload, NError>;
|
|
127
130
|
reset: () => void;
|
|
128
131
|
getItemKey: (params: ItemPayload) => string;
|
|
@@ -276,13 +279,14 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
276
279
|
error: null;
|
|
277
280
|
hasMore: boolean;
|
|
278
281
|
}>;
|
|
279
|
-
useMultipleListQueries: <SelectedItem = ItemState>(queries: readonly QueryPayload[], { itemSelector, omitPayload, returnIdleStatus, returnRefetchingStatus, loadSize, disableRefetchOnMount, }?: {
|
|
282
|
+
useMultipleListQueries: <SelectedItem = ItemState>(queries: readonly QueryPayload[], { itemSelector, omitPayload, returnIdleStatus, returnRefetchingStatus, loadSize, disableRefetchOnMount, isOffScreen, }?: {
|
|
280
283
|
itemSelector?: ((data: ItemState, id: ItemPayload, itemKey: string) => SelectedItem) | undefined;
|
|
281
284
|
omitPayload?: boolean | undefined;
|
|
282
285
|
disableRefetchOnMount?: boolean | undefined;
|
|
283
286
|
returnIdleStatus?: boolean | undefined;
|
|
284
287
|
returnRefetchingStatus?: boolean | undefined;
|
|
285
288
|
loadSize?: number | undefined;
|
|
289
|
+
isOffScreen?: boolean | undefined;
|
|
286
290
|
}) => readonly TSFDUseListQueryReturn<SelectedItem, QueryPayload, NError>[];
|
|
287
291
|
useListQuery: <SelectedItem_1 = ItemState>(payload: QueryPayload | false | null | undefined, options?: {
|
|
288
292
|
itemSelector?: ((data: ItemState, id: ItemPayload, itemKey: string) => SelectedItem_1) | undefined;
|
|
@@ -292,6 +296,7 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
292
296
|
returnRefetchingStatus?: boolean | undefined;
|
|
293
297
|
ensureIsLoaded?: boolean | undefined;
|
|
294
298
|
loadSize?: number | undefined;
|
|
299
|
+
isOffScreen?: boolean | undefined;
|
|
295
300
|
}) => TSFDUseListQueryReturn<SelectedItem_1, QueryPayload, NError>;
|
|
296
301
|
getItemKey: (params: ItemPayload) => string;
|
|
297
302
|
useItem: <SelectedItem_2 = ItemState | null>(itemPayload: ItemPayload | false | null | undefined, options?: {
|
|
@@ -301,13 +306,15 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
301
306
|
returnRefetchingStatus?: boolean | undefined;
|
|
302
307
|
ensureIsLoaded?: boolean | undefined;
|
|
303
308
|
loadFromStateOnly?: boolean | undefined;
|
|
309
|
+
isOffScreen?: boolean | undefined;
|
|
304
310
|
}) => TSFDUseListItemReturn<SelectedItem_2, NError, ItemPayload>;
|
|
305
|
-
useMultipleItems: <SelectedItem_3 = ItemState | null>(itemsPayload_: ItemPayload[], { selector, returnIdleStatus, returnRefetchingStatus, disableRefetchOnMount, loadFromStateOnly, }?: {
|
|
311
|
+
useMultipleItems: <SelectedItem_3 = ItemState | null>(itemsPayload_: ItemPayload[], { selector, returnIdleStatus, returnRefetchingStatus, disableRefetchOnMount, loadFromStateOnly, isOffScreen, }?: {
|
|
306
312
|
selector?: ((data: ItemState | null, id: ItemPayload | null) => SelectedItem_3) | undefined;
|
|
307
313
|
disableRefetchOnMount?: boolean | undefined;
|
|
308
314
|
returnIdleStatus?: boolean | undefined;
|
|
309
315
|
returnRefetchingStatus?: boolean | undefined;
|
|
310
316
|
loadFromStateOnly?: boolean | undefined;
|
|
317
|
+
isOffScreen?: boolean | undefined;
|
|
311
318
|
}) => readonly TSFDUseListItemReturn<SelectedItem_3, NError, ItemPayload>[];
|
|
312
319
|
addItemToState: (itemPayload: ItemPayload, data: ItemState, { addItemToQueries, }?: {
|
|
313
320
|
addItemToQueries?: {
|
package/dist/main.js
CHANGED
|
@@ -21,7 +21,7 @@ function createFetchOrquestrator({
|
|
|
21
21
|
let mutationIsInProgress = false;
|
|
22
22
|
let lastFetchStartTime = 0;
|
|
23
23
|
let lastFetchDuration = 0;
|
|
24
|
-
let onMutationEnd =
|
|
24
|
+
let onMutationEnd = null;
|
|
25
25
|
let lastFetchWasAborted = false;
|
|
26
26
|
let abortFetchsBeforeOrEqual = 0;
|
|
27
27
|
function setLastFetchDurantion(duration) {
|
|
@@ -49,9 +49,9 @@ function createFetchOrquestrator({
|
|
|
49
49
|
function endMutation(id) {
|
|
50
50
|
if (id === lastMutationIdStarted) {
|
|
51
51
|
mutationIsInProgress = false;
|
|
52
|
-
if (onMutationEnd
|
|
53
|
-
onMutationEnd
|
|
54
|
-
onMutationEnd =
|
|
52
|
+
if (onMutationEnd) {
|
|
53
|
+
onMutationEnd();
|
|
54
|
+
onMutationEnd = null;
|
|
55
55
|
}
|
|
56
56
|
flushScheduledFetch();
|
|
57
57
|
return true;
|
|
@@ -193,13 +193,13 @@ function createFetchOrquestrator({
|
|
|
193
193
|
};
|
|
194
194
|
return true;
|
|
195
195
|
} else if (mutationIsInProgress) {
|
|
196
|
-
onMutationEnd
|
|
196
|
+
onMutationEnd = () => {
|
|
197
197
|
const added = addDelayedRTU(Date.now(), params);
|
|
198
198
|
if (!added) {
|
|
199
199
|
on?.("scheduled-rt-fetch-started");
|
|
200
200
|
scheduleFetch("highPriority", params);
|
|
201
201
|
}
|
|
202
|
-
}
|
|
202
|
+
};
|
|
203
203
|
return true;
|
|
204
204
|
} else {
|
|
205
205
|
if (!addDelayedRTU(startTime, params)) {
|
|
@@ -468,7 +468,8 @@ function newTSDFDocumentStore({
|
|
|
468
468
|
}
|
|
469
469
|
function useDocument({
|
|
470
470
|
selector,
|
|
471
|
-
|
|
471
|
+
isOffScreen,
|
|
472
|
+
disabled = isOffScreen,
|
|
472
473
|
returnRefetchingStatus,
|
|
473
474
|
disableRefetchOnMount = globalDisableRefetchOnMount,
|
|
474
475
|
returnIdleStatus = !!disabled,
|
|
@@ -498,6 +499,8 @@ function newTSDFDocumentStore({
|
|
|
498
499
|
useExternalDeps: true
|
|
499
500
|
});
|
|
500
501
|
useOnEvtmitterEvent2(storeEvents, "invalidateData", (priority) => {
|
|
502
|
+
if (disabled)
|
|
503
|
+
return;
|
|
501
504
|
if (!invalidationWasTriggered) {
|
|
502
505
|
store.setKey("refetchOnMount", false);
|
|
503
506
|
scheduleFetch(priority);
|
|
@@ -820,7 +823,8 @@ function newTSDFCollectionStore({
|
|
|
820
823
|
omitPayload,
|
|
821
824
|
returnIdleStatus,
|
|
822
825
|
returnRefetchingStatus,
|
|
823
|
-
disableRefetchOnMount = globalDisableRefetchOnMount
|
|
826
|
+
disableRefetchOnMount = globalDisableRefetchOnMount,
|
|
827
|
+
isOffScreen
|
|
824
828
|
} = {}) {
|
|
825
829
|
const queriesWithId = useDeepMemo(() => {
|
|
826
830
|
return queries.map((payload) => {
|
|
@@ -888,6 +892,8 @@ function newTSDFCollectionStore({
|
|
|
888
892
|
useExternalDeps: true
|
|
889
893
|
});
|
|
890
894
|
useOnEvtmitterEvent3(storeEvents, "invalidateData", (event) => {
|
|
895
|
+
if (isOffScreen)
|
|
896
|
+
return;
|
|
891
897
|
for (const { itemKey, payload } of queriesWithId) {
|
|
892
898
|
if (itemKey !== event.itemKey)
|
|
893
899
|
continue;
|
|
@@ -904,6 +910,8 @@ function newTSDFCollectionStore({
|
|
|
904
910
|
}
|
|
905
911
|
});
|
|
906
912
|
useEffect3(() => {
|
|
913
|
+
if (isOffScreen)
|
|
914
|
+
return;
|
|
907
915
|
for (const { itemKey: itemId, payload } of queriesWithId) {
|
|
908
916
|
if (itemId) {
|
|
909
917
|
const itemState = getItemState(payload);
|
|
@@ -919,7 +927,7 @@ function newTSDFCollectionStore({
|
|
|
919
927
|
}
|
|
920
928
|
}
|
|
921
929
|
}
|
|
922
|
-
}, [disableRefetchOnMount, queriesWithId]);
|
|
930
|
+
}, [disableRefetchOnMount, isOffScreen, queriesWithId]);
|
|
923
931
|
return storeState;
|
|
924
932
|
}
|
|
925
933
|
function useItem(payload, options = {}) {
|
|
@@ -1440,7 +1448,8 @@ function newTSDFListQueryStore({
|
|
|
1440
1448
|
returnIdleStatus,
|
|
1441
1449
|
returnRefetchingStatus,
|
|
1442
1450
|
loadSize,
|
|
1443
|
-
disableRefetchOnMount = globalDisableRefetchOnMount
|
|
1451
|
+
disableRefetchOnMount = globalDisableRefetchOnMount,
|
|
1452
|
+
isOffScreen
|
|
1444
1453
|
} = {}) {
|
|
1445
1454
|
const queriesWithId = useDeepMemo(() => {
|
|
1446
1455
|
return queries.map((payload) => {
|
|
@@ -1501,6 +1510,8 @@ function newTSDFListQueryStore({
|
|
|
1501
1510
|
useExternalDeps: true
|
|
1502
1511
|
});
|
|
1503
1512
|
useOnEvtmitterEvent4(storeEvents, "invalidateQuery", (event) => {
|
|
1513
|
+
if (isOffScreen)
|
|
1514
|
+
return;
|
|
1504
1515
|
for (const { key, payload } of queriesWithId) {
|
|
1505
1516
|
if (key !== event.queryKey)
|
|
1506
1517
|
continue;
|
|
@@ -1518,6 +1529,8 @@ function newTSDFListQueryStore({
|
|
|
1518
1529
|
});
|
|
1519
1530
|
const loadSizeConst = useConst(() => loadSize);
|
|
1520
1531
|
useEffect4(() => {
|
|
1532
|
+
if (isOffScreen)
|
|
1533
|
+
return;
|
|
1521
1534
|
for (const { key: itemId, payload: fetchParams } of queriesWithId) {
|
|
1522
1535
|
if (itemId) {
|
|
1523
1536
|
const itemState = getQueryState(fetchParams);
|
|
@@ -1533,7 +1546,7 @@ function newTSDFListQueryStore({
|
|
|
1533
1546
|
}
|
|
1534
1547
|
}
|
|
1535
1548
|
}
|
|
1536
|
-
}, [disableRefetchOnMount, loadSizeConst, queriesWithId]);
|
|
1549
|
+
}, [disableRefetchOnMount, isOffScreen, loadSizeConst, queriesWithId]);
|
|
1537
1550
|
return storeState;
|
|
1538
1551
|
}
|
|
1539
1552
|
function useListQuery(payload, options = {}) {
|
|
@@ -1765,7 +1778,8 @@ function newTSDFListQueryStore({
|
|
|
1765
1778
|
returnIdleStatus,
|
|
1766
1779
|
returnRefetchingStatus,
|
|
1767
1780
|
disableRefetchOnMount,
|
|
1768
|
-
loadFromStateOnly
|
|
1781
|
+
loadFromStateOnly,
|
|
1782
|
+
isOffScreen
|
|
1769
1783
|
} = {}) {
|
|
1770
1784
|
const dataSelector = useCallback3(selector, []);
|
|
1771
1785
|
const memoizedItemKeys = useDeepMemo(
|
|
@@ -1830,7 +1844,7 @@ function newTSDFListQueryStore({
|
|
|
1830
1844
|
useExternalDeps: true
|
|
1831
1845
|
});
|
|
1832
1846
|
useOnEvtmitterEvent4(storeEvents, "invalidateItem", (event) => {
|
|
1833
|
-
if (loadFromStateOnly)
|
|
1847
|
+
if (loadFromStateOnly || isOffScreen)
|
|
1834
1848
|
return;
|
|
1835
1849
|
for (const { payload, itemKey } of memoizedItemKeys) {
|
|
1836
1850
|
if (itemKey !== event.itemKey)
|
|
@@ -1848,7 +1862,7 @@ function newTSDFListQueryStore({
|
|
|
1848
1862
|
}
|
|
1849
1863
|
});
|
|
1850
1864
|
useEffect4(() => {
|
|
1851
|
-
if (loadFromStateOnly)
|
|
1865
|
+
if (loadFromStateOnly || isOffScreen)
|
|
1852
1866
|
return;
|
|
1853
1867
|
for (const { payload, itemKey } of memoizedItemKeys) {
|
|
1854
1868
|
if (itemKey) {
|
|
@@ -1865,7 +1879,12 @@ function newTSDFListQueryStore({
|
|
|
1865
1879
|
}
|
|
1866
1880
|
}
|
|
1867
1881
|
}
|
|
1868
|
-
}, [
|
|
1882
|
+
}, [
|
|
1883
|
+
disableRefetchOnMount,
|
|
1884
|
+
isOffScreen,
|
|
1885
|
+
loadFromStateOnly,
|
|
1886
|
+
memoizedItemKeys
|
|
1887
|
+
]);
|
|
1869
1888
|
return storeState;
|
|
1870
1889
|
}
|
|
1871
1890
|
function useItem(itemPayload, options = {}) {
|