tsdf 12.6.2 → 12.8.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 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,
@@ -497,7 +498,8 @@ function newTSDFDocumentStore({
497
498
  }
498
499
  function useDocument({
499
500
  selector,
500
- disabled,
501
+ isOffScreen,
502
+ disabled = isOffScreen,
501
503
  returnRefetchingStatus,
502
504
  disableRefetchOnMount = globalDisableRefetchOnMount,
503
505
  returnIdleStatus = !!disabled,
@@ -527,6 +529,8 @@ function newTSDFDocumentStore({
527
529
  useExternalDeps: true
528
530
  });
529
531
  (0, import_react5.useOnEvtmitterEvent)(storeEvents, "invalidateData", (priority) => {
532
+ if (disabled)
533
+ return;
530
534
  if (!invalidationWasTriggered) {
531
535
  store.setKey("refetchOnMount", false);
532
536
  scheduleFetch(priority);
@@ -642,16 +646,46 @@ function isObject(value) {
642
646
  }
643
647
 
644
648
  // src/utils/getCacheId.ts
645
- function getCacheId(input) {
646
- return typeof input === "string" || typeof input === "number" ? String(input) : JSON.stringify(input && isObject(input) ? orderedProps(input) : input);
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));
647
655
  }
648
- function orderedProps(obj) {
649
- return filterAndMap(Object.keys(obj).sort(), (k, ignore) => {
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) => {
650
679
  const value = obj[k];
651
680
  if (value === void 0)
652
681
  return ignore;
653
- return { [k]: obj[k] };
682
+ return { [k]: mapValue(value) };
654
683
  });
684
+ if (mappedValues.length === 0)
685
+ return emptyObject;
686
+ if (mappedValues.length === 1)
687
+ return mappedValues[0];
688
+ return mappedValues;
655
689
  }
656
690
 
657
691
  // src/collectionStore.ts
@@ -849,7 +883,8 @@ function newTSDFCollectionStore({
849
883
  omitPayload,
850
884
  returnIdleStatus,
851
885
  returnRefetchingStatus,
852
- disableRefetchOnMount = globalDisableRefetchOnMount
886
+ disableRefetchOnMount = globalDisableRefetchOnMount,
887
+ isOffScreen
853
888
  } = {}) {
854
889
  const queriesWithId = useDeepMemo(() => {
855
890
  return queries.map((payload) => {
@@ -917,6 +952,8 @@ function newTSDFCollectionStore({
917
952
  useExternalDeps: true
918
953
  });
919
954
  (0, import_react6.useOnEvtmitterEvent)(storeEvents, "invalidateData", (event) => {
955
+ if (isOffScreen)
956
+ return;
920
957
  for (const { itemKey, payload } of queriesWithId) {
921
958
  if (itemKey !== event.itemKey)
922
959
  continue;
@@ -933,6 +970,8 @@ function newTSDFCollectionStore({
933
970
  }
934
971
  });
935
972
  (0, import_react7.useEffect)(() => {
973
+ if (isOffScreen)
974
+ return;
936
975
  for (const { itemKey: itemId, payload } of queriesWithId) {
937
976
  if (itemId) {
938
977
  const itemState = getItemState(payload);
@@ -948,7 +987,7 @@ function newTSDFCollectionStore({
948
987
  }
949
988
  }
950
989
  }
951
- }, [disableRefetchOnMount, queriesWithId]);
990
+ }, [disableRefetchOnMount, isOffScreen, queriesWithId]);
952
991
  return storeState;
953
992
  }
954
993
  function useItem(payload, options = {}) {
@@ -1469,7 +1508,8 @@ function newTSDFListQueryStore({
1469
1508
  returnIdleStatus,
1470
1509
  returnRefetchingStatus,
1471
1510
  loadSize,
1472
- disableRefetchOnMount = globalDisableRefetchOnMount
1511
+ disableRefetchOnMount = globalDisableRefetchOnMount,
1512
+ isOffScreen
1473
1513
  } = {}) {
1474
1514
  const queriesWithId = useDeepMemo(() => {
1475
1515
  return queries.map((payload) => {
@@ -1530,6 +1570,8 @@ function newTSDFListQueryStore({
1530
1570
  useExternalDeps: true
1531
1571
  });
1532
1572
  (0, import_react8.useOnEvtmitterEvent)(storeEvents, "invalidateQuery", (event) => {
1573
+ if (isOffScreen)
1574
+ return;
1533
1575
  for (const { key, payload } of queriesWithId) {
1534
1576
  if (key !== event.queryKey)
1535
1577
  continue;
@@ -1547,6 +1589,8 @@ function newTSDFListQueryStore({
1547
1589
  });
1548
1590
  const loadSizeConst = useConst(() => loadSize);
1549
1591
  (0, import_react9.useEffect)(() => {
1592
+ if (isOffScreen)
1593
+ return;
1550
1594
  for (const { key: itemId, payload: fetchParams } of queriesWithId) {
1551
1595
  if (itemId) {
1552
1596
  const itemState = getQueryState(fetchParams);
@@ -1562,7 +1606,7 @@ function newTSDFListQueryStore({
1562
1606
  }
1563
1607
  }
1564
1608
  }
1565
- }, [disableRefetchOnMount, loadSizeConst, queriesWithId]);
1609
+ }, [disableRefetchOnMount, isOffScreen, loadSizeConst, queriesWithId]);
1566
1610
  return storeState;
1567
1611
  }
1568
1612
  function useListQuery(payload, options = {}) {
@@ -1794,7 +1838,8 @@ function newTSDFListQueryStore({
1794
1838
  returnIdleStatus,
1795
1839
  returnRefetchingStatus,
1796
1840
  disableRefetchOnMount,
1797
- loadFromStateOnly
1841
+ loadFromStateOnly,
1842
+ isOffScreen
1798
1843
  } = {}) {
1799
1844
  const dataSelector = (0, import_react9.useCallback)(selector, []);
1800
1845
  const memoizedItemKeys = useDeepMemo(
@@ -1859,7 +1904,7 @@ function newTSDFListQueryStore({
1859
1904
  useExternalDeps: true
1860
1905
  });
1861
1906
  (0, import_react8.useOnEvtmitterEvent)(storeEvents, "invalidateItem", (event) => {
1862
- if (loadFromStateOnly)
1907
+ if (loadFromStateOnly || isOffScreen)
1863
1908
  return;
1864
1909
  for (const { payload, itemKey } of memoizedItemKeys) {
1865
1910
  if (itemKey !== event.itemKey)
@@ -1877,7 +1922,7 @@ function newTSDFListQueryStore({
1877
1922
  }
1878
1923
  });
1879
1924
  (0, import_react9.useEffect)(() => {
1880
- if (loadFromStateOnly)
1925
+ if (loadFromStateOnly || isOffScreen)
1881
1926
  return;
1882
1927
  for (const { payload, itemKey } of memoizedItemKeys) {
1883
1928
  if (itemKey) {
@@ -1894,7 +1939,12 @@ function newTSDFListQueryStore({
1894
1939
  }
1895
1940
  }
1896
1941
  }
1897
- }, [disableRefetchOnMount, loadFromStateOnly, memoizedItemKeys]);
1942
+ }, [
1943
+ disableRefetchOnMount,
1944
+ isOffScreen,
1945
+ loadFromStateOnly,
1946
+ memoizedItemKeys
1947
+ ]);
1898
1948
  return storeState;
1899
1949
  }
1900
1950
  function useItem(itemPayload, options = {}) {
@@ -2265,6 +2315,7 @@ function useListItemIsLoading({
2265
2315
  }
2266
2316
  // Annotate the CommonJS export names for ESM import in node:
2267
2317
  0 && (module.exports = {
2318
+ getCacheId,
2268
2319
  newTSDFCollectionStore,
2269
2320
  newTSDFDocumentStore,
2270
2321
  newTSDFListQueryStore,
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?: {
@@ -343,4 +350,6 @@ declare function useListItemIsLoading({ isLoading, isRefetching, isNotFound, loa
343
350
  loadItemFallback: () => void;
344
351
  }): boolean;
345
352
 
346
- export { CollectionInitialStateItem, FetchListFnReturn, FetchListFnReturnItem, ListQueryStoreInitialData, OnCollectionItemInvalidate, OnDocumentInvalidate, OnListQueryInvalidate, OnListQueryItemInvalidate, TSDFCollectionStore, TSDFDocumentStore, TSDFDocumentStoreState, TSDFItemQuery, TSDFStatus, TSDFUseDocumentReturn, TSFDCollectionItem, TSFDCollectionState, TSFDListQuery, TSFDListQueryState, TSFDListQueryStore, TSFDUseCollectionItemReturn, TSFDUseListItemReturn, TSFDUseListQueryReturn, ValidPayload, ValidStoreState, newTSDFCollectionStore, newTSDFDocumentStore, newTSDFListQueryStore, useListItemIsLoading };
353
+ declare function getCacheId(input: unknown, maxDepth?: number): string;
354
+
355
+ export { CollectionInitialStateItem, FetchListFnReturn, FetchListFnReturnItem, ListQueryStoreInitialData, OnCollectionItemInvalidate, OnDocumentInvalidate, OnListQueryInvalidate, OnListQueryItemInvalidate, TSDFCollectionStore, TSDFDocumentStore, TSDFDocumentStoreState, TSDFItemQuery, TSDFStatus, TSDFUseDocumentReturn, TSFDCollectionItem, TSFDCollectionState, TSFDListQuery, TSFDListQueryState, TSFDListQueryStore, TSFDUseCollectionItemReturn, TSFDUseListItemReturn, TSFDUseListQueryReturn, ValidPayload, ValidStoreState, getCacheId, newTSDFCollectionStore, newTSDFDocumentStore, newTSDFListQueryStore, useListItemIsLoading };
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?: {
@@ -343,4 +350,6 @@ declare function useListItemIsLoading({ isLoading, isRefetching, isNotFound, loa
343
350
  loadItemFallback: () => void;
344
351
  }): boolean;
345
352
 
346
- export { CollectionInitialStateItem, FetchListFnReturn, FetchListFnReturnItem, ListQueryStoreInitialData, OnCollectionItemInvalidate, OnDocumentInvalidate, OnListQueryInvalidate, OnListQueryItemInvalidate, TSDFCollectionStore, TSDFDocumentStore, TSDFDocumentStoreState, TSDFItemQuery, TSDFStatus, TSDFUseDocumentReturn, TSFDCollectionItem, TSFDCollectionState, TSFDListQuery, TSFDListQueryState, TSFDListQueryStore, TSFDUseCollectionItemReturn, TSFDUseListItemReturn, TSFDUseListQueryReturn, ValidPayload, ValidStoreState, newTSDFCollectionStore, newTSDFDocumentStore, newTSDFListQueryStore, useListItemIsLoading };
353
+ declare function getCacheId(input: unknown, maxDepth?: number): string;
354
+
355
+ export { CollectionInitialStateItem, FetchListFnReturn, FetchListFnReturnItem, ListQueryStoreInitialData, OnCollectionItemInvalidate, OnDocumentInvalidate, OnListQueryInvalidate, OnListQueryItemInvalidate, TSDFCollectionStore, TSDFDocumentStore, TSDFDocumentStoreState, TSDFItemQuery, TSDFStatus, TSDFUseDocumentReturn, TSFDCollectionItem, TSFDCollectionState, TSFDListQuery, TSFDListQueryState, TSFDListQueryStore, TSFDUseCollectionItemReturn, TSFDUseListItemReturn, TSFDUseListQueryReturn, ValidPayload, ValidStoreState, getCacheId, newTSDFCollectionStore, newTSDFDocumentStore, newTSDFListQueryStore, useListItemIsLoading };
package/dist/main.js CHANGED
@@ -468,7 +468,8 @@ function newTSDFDocumentStore({
468
468
  }
469
469
  function useDocument({
470
470
  selector,
471
- disabled,
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);
@@ -613,16 +616,46 @@ function isObject(value) {
613
616
  }
614
617
 
615
618
  // src/utils/getCacheId.ts
616
- function getCacheId(input) {
617
- return typeof input === "string" || typeof input === "number" ? String(input) : JSON.stringify(input && isObject(input) ? orderedProps(input) : input);
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));
618
625
  }
619
- function orderedProps(obj) {
620
- return filterAndMap(Object.keys(obj).sort(), (k, ignore) => {
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) => {
621
649
  const value = obj[k];
622
650
  if (value === void 0)
623
651
  return ignore;
624
- return { [k]: obj[k] };
652
+ return { [k]: mapValue(value) };
625
653
  });
654
+ if (mappedValues.length === 0)
655
+ return emptyObject;
656
+ if (mappedValues.length === 1)
657
+ return mappedValues[0];
658
+ return mappedValues;
626
659
  }
627
660
 
628
661
  // src/collectionStore.ts
@@ -820,7 +853,8 @@ function newTSDFCollectionStore({
820
853
  omitPayload,
821
854
  returnIdleStatus,
822
855
  returnRefetchingStatus,
823
- disableRefetchOnMount = globalDisableRefetchOnMount
856
+ disableRefetchOnMount = globalDisableRefetchOnMount,
857
+ isOffScreen
824
858
  } = {}) {
825
859
  const queriesWithId = useDeepMemo(() => {
826
860
  return queries.map((payload) => {
@@ -888,6 +922,8 @@ function newTSDFCollectionStore({
888
922
  useExternalDeps: true
889
923
  });
890
924
  useOnEvtmitterEvent3(storeEvents, "invalidateData", (event) => {
925
+ if (isOffScreen)
926
+ return;
891
927
  for (const { itemKey, payload } of queriesWithId) {
892
928
  if (itemKey !== event.itemKey)
893
929
  continue;
@@ -904,6 +940,8 @@ function newTSDFCollectionStore({
904
940
  }
905
941
  });
906
942
  useEffect3(() => {
943
+ if (isOffScreen)
944
+ return;
907
945
  for (const { itemKey: itemId, payload } of queriesWithId) {
908
946
  if (itemId) {
909
947
  const itemState = getItemState(payload);
@@ -919,7 +957,7 @@ function newTSDFCollectionStore({
919
957
  }
920
958
  }
921
959
  }
922
- }, [disableRefetchOnMount, queriesWithId]);
960
+ }, [disableRefetchOnMount, isOffScreen, queriesWithId]);
923
961
  return storeState;
924
962
  }
925
963
  function useItem(payload, options = {}) {
@@ -1440,7 +1478,8 @@ function newTSDFListQueryStore({
1440
1478
  returnIdleStatus,
1441
1479
  returnRefetchingStatus,
1442
1480
  loadSize,
1443
- disableRefetchOnMount = globalDisableRefetchOnMount
1481
+ disableRefetchOnMount = globalDisableRefetchOnMount,
1482
+ isOffScreen
1444
1483
  } = {}) {
1445
1484
  const queriesWithId = useDeepMemo(() => {
1446
1485
  return queries.map((payload) => {
@@ -1501,6 +1540,8 @@ function newTSDFListQueryStore({
1501
1540
  useExternalDeps: true
1502
1541
  });
1503
1542
  useOnEvtmitterEvent4(storeEvents, "invalidateQuery", (event) => {
1543
+ if (isOffScreen)
1544
+ return;
1504
1545
  for (const { key, payload } of queriesWithId) {
1505
1546
  if (key !== event.queryKey)
1506
1547
  continue;
@@ -1518,6 +1559,8 @@ function newTSDFListQueryStore({
1518
1559
  });
1519
1560
  const loadSizeConst = useConst(() => loadSize);
1520
1561
  useEffect4(() => {
1562
+ if (isOffScreen)
1563
+ return;
1521
1564
  for (const { key: itemId, payload: fetchParams } of queriesWithId) {
1522
1565
  if (itemId) {
1523
1566
  const itemState = getQueryState(fetchParams);
@@ -1533,7 +1576,7 @@ function newTSDFListQueryStore({
1533
1576
  }
1534
1577
  }
1535
1578
  }
1536
- }, [disableRefetchOnMount, loadSizeConst, queriesWithId]);
1579
+ }, [disableRefetchOnMount, isOffScreen, loadSizeConst, queriesWithId]);
1537
1580
  return storeState;
1538
1581
  }
1539
1582
  function useListQuery(payload, options = {}) {
@@ -1765,7 +1808,8 @@ function newTSDFListQueryStore({
1765
1808
  returnIdleStatus,
1766
1809
  returnRefetchingStatus,
1767
1810
  disableRefetchOnMount,
1768
- loadFromStateOnly
1811
+ loadFromStateOnly,
1812
+ isOffScreen
1769
1813
  } = {}) {
1770
1814
  const dataSelector = useCallback3(selector, []);
1771
1815
  const memoizedItemKeys = useDeepMemo(
@@ -1830,7 +1874,7 @@ function newTSDFListQueryStore({
1830
1874
  useExternalDeps: true
1831
1875
  });
1832
1876
  useOnEvtmitterEvent4(storeEvents, "invalidateItem", (event) => {
1833
- if (loadFromStateOnly)
1877
+ if (loadFromStateOnly || isOffScreen)
1834
1878
  return;
1835
1879
  for (const { payload, itemKey } of memoizedItemKeys) {
1836
1880
  if (itemKey !== event.itemKey)
@@ -1848,7 +1892,7 @@ function newTSDFListQueryStore({
1848
1892
  }
1849
1893
  });
1850
1894
  useEffect4(() => {
1851
- if (loadFromStateOnly)
1895
+ if (loadFromStateOnly || isOffScreen)
1852
1896
  return;
1853
1897
  for (const { payload, itemKey } of memoizedItemKeys) {
1854
1898
  if (itemKey) {
@@ -1865,7 +1909,12 @@ function newTSDFListQueryStore({
1865
1909
  }
1866
1910
  }
1867
1911
  }
1868
- }, [disableRefetchOnMount, loadFromStateOnly, memoizedItemKeys]);
1912
+ }, [
1913
+ disableRefetchOnMount,
1914
+ isOffScreen,
1915
+ loadFromStateOnly,
1916
+ memoizedItemKeys
1917
+ ]);
1869
1918
  return storeState;
1870
1919
  }
1871
1920
  function useItem(itemPayload, options = {}) {
@@ -2235,6 +2284,7 @@ function useListItemIsLoading({
2235
2284
  return isLoading || isNotFound && (isRefetching || !!willBeRefetched);
2236
2285
  }
2237
2286
  export {
2287
+ getCacheId,
2238
2288
  newTSDFCollectionStore,
2239
2289
  newTSDFDocumentStore,
2240
2290
  newTSDFListQueryStore,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdf",
3
- "version": "12.6.2",
3
+ "version": "12.8.0",
4
4
  "description": "A data fetching solution based on t-state",
5
5
  "license": "MIT",
6
6
  "author": "Lucas Santos",