tsdf 10.1.0 → 11.1.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
@@ -397,7 +397,6 @@ function newTSDFDocumentStore({
397
397
  debugName,
398
398
  fetchFn,
399
399
  initialData,
400
- disableRefetchOnWindowFocus,
401
400
  disableRefetchOnMount: globalDisableRefetchOnMount,
402
401
  lowPriorityThrottleMs,
403
402
  mediumPriorityThrottleMs,
@@ -513,6 +512,7 @@ function newTSDFDocumentStore({
513
512
  });
514
513
  useOnMittEvent(storeEvents, "invalidateData", (priority) => {
515
514
  if (!invalidationWasTriggered) {
515
+ store.setKey("refetchOnMount", false);
516
516
  scheduleFetch(priority);
517
517
  invalidationWasTriggered = true;
518
518
  }
@@ -557,14 +557,6 @@ function newTSDFDocumentStore({
557
557
  { action: "update-state" }
558
558
  );
559
559
  }
560
- if (!disableRefetchOnWindowFocus) {
561
- let handleFocus2 = function() {
562
- invalidateData("lowPriority");
563
- };
564
- var handleFocus = handleFocus2;
565
- window.addEventListener("focus", handleFocus2);
566
- window.addEventListener("visibilitychange", handleFocus2);
567
- }
568
560
  return {
569
561
  store,
570
562
  awaitFetch,
@@ -632,7 +624,6 @@ var import_json = require("klona/json");
632
624
  function newTSDFCollectionStore({
633
625
  debugName,
634
626
  fetchFn,
635
- disableRefetchOnWindowFocus,
636
627
  lowPriorityThrottleMs,
637
628
  errorNormalizer,
638
629
  disableInitialDataInvalidation,
@@ -882,6 +873,12 @@ function newTSDFCollectionStore({
882
873
  if (itemKey !== event.itemKey)
883
874
  continue;
884
875
  if (!invalidationWasTriggered.has(itemKey)) {
876
+ store.produceState((draft) => {
877
+ const draftItem = draft[itemKey];
878
+ if (!draftItem)
879
+ return;
880
+ draftItem.refetchOnMount = false;
881
+ });
885
882
  scheduleFetch(event.priority, payload);
886
883
  invalidationWasTriggered.add(itemKey);
887
884
  }
@@ -1010,14 +1007,6 @@ function newTSDFCollectionStore({
1010
1007
  );
1011
1008
  return someItemWasUpdated;
1012
1009
  }
1013
- if (!disableRefetchOnWindowFocus) {
1014
- let handleFocus2 = function() {
1015
- invalidateItem(() => true, "lowPriority");
1016
- };
1017
- var handleFocus = handleFocus2;
1018
- window.addEventListener("focus", handleFocus2);
1019
- window.addEventListener("visibilitychange", handleFocus2);
1020
- }
1021
1010
  return {
1022
1011
  store,
1023
1012
  scheduleFetch,
@@ -1062,7 +1051,6 @@ function newTSDFListQueryStore({
1062
1051
  errorNormalizer,
1063
1052
  defaultQuerySize = 50,
1064
1053
  initialData,
1065
- disableRefetchOnWindowFocus,
1066
1054
  disableRefetchOnMount: globalDisableRefetchOnMount,
1067
1055
  lowPriorityThrottleMs,
1068
1056
  disableInitialDataInvalidation,
@@ -1449,6 +1437,12 @@ function newTSDFListQueryStore({
1449
1437
  if (key !== event.queryKey)
1450
1438
  continue;
1451
1439
  if (!queryInvalidationWasTriggered.has(key)) {
1440
+ store.produceState((draft) => {
1441
+ const query = draft.queries[key];
1442
+ if (!query?.refetchOnMount)
1443
+ return;
1444
+ query.refetchOnMount = false;
1445
+ });
1452
1446
  scheduleListQueryFetch(event.priority, payload);
1453
1447
  queryInvalidationWasTriggered.add(key);
1454
1448
  }
@@ -1764,6 +1758,12 @@ function newTSDFListQueryStore({
1764
1758
  if (itemKey !== event.itemKey)
1765
1759
  continue;
1766
1760
  if (!itemInvalidationWasTriggered.has(itemKey)) {
1761
+ store.produceState((draft) => {
1762
+ const query = draft.itemQueries[itemKey];
1763
+ if (!query?.refetchOnMount)
1764
+ return;
1765
+ query.refetchOnMount = false;
1766
+ });
1767
1767
  scheduleItemFetch(event.priority, payload);
1768
1768
  itemInvalidationWasTriggered.add(itemKey);
1769
1769
  }
@@ -1941,17 +1941,6 @@ function newTSDFListQueryStore({
1941
1941
  { action: { type: "delete-item-state", itemId } }
1942
1942
  );
1943
1943
  }
1944
- if (!disableRefetchOnWindowFocus) {
1945
- let handleFocus2 = function() {
1946
- invalidateQuery(() => true, "lowPriority");
1947
- if (fetchItemFn) {
1948
- invalidateItem(() => true, "lowPriority");
1949
- }
1950
- };
1951
- var handleFocus = handleFocus2;
1952
- window.addEventListener("focus", handleFocus2);
1953
- window.addEventListener("visibilitychange", handleFocus2);
1954
- }
1955
1944
  return {
1956
1945
  store,
1957
1946
  scheduleListQueryFetch,
package/dist/main.d.ts CHANGED
@@ -20,13 +20,12 @@ type TSDFUseDocumentReturn<Selected, NError> = {
20
20
  error: NError | null;
21
21
  isLoading: boolean;
22
22
  };
23
- declare function newTSDFDocumentStore<State extends ValidStoreState, NError>({ debugName, fetchFn, initialData, disableRefetchOnWindowFocus, disableRefetchOnMount: globalDisableRefetchOnMount, lowPriorityThrottleMs, mediumPriorityThrottleMs, dynamicRealtimeThrottleMs, disableInitialDataInvalidation, errorNormalizer, }: {
23
+ declare function newTSDFDocumentStore<State extends ValidStoreState, NError>({ debugName, fetchFn, initialData, disableRefetchOnMount: globalDisableRefetchOnMount, lowPriorityThrottleMs, mediumPriorityThrottleMs, dynamicRealtimeThrottleMs, disableInitialDataInvalidation, errorNormalizer, }: {
24
24
  debugName?: string;
25
25
  fetchFn: () => Promise<State>;
26
26
  initialData?: State;
27
27
  disableInitialDataInvalidation?: boolean;
28
28
  errorNormalizer: (exception: unknown) => NError;
29
- disableRefetchOnWindowFocus?: boolean;
30
29
  disableRefetchOnMount?: boolean;
31
30
  lowPriorityThrottleMs?: number;
32
31
  mediumPriorityThrottleMs?: number;
@@ -77,12 +76,11 @@ type CollectionInitialStateItem<ItemPayload extends ValidPayload, ItemState exte
77
76
  payload: ItemPayload;
78
77
  data: ItemState;
79
78
  };
80
- declare function newTSDFCollectionStore<ItemState extends ValidStoreState, NError, ItemPayload extends ValidPayload>({ debugName, fetchFn, disableRefetchOnWindowFocus, lowPriorityThrottleMs, errorNormalizer, disableInitialDataInvalidation, mediumPriorityThrottleMs, initialStateItems, disableRefetchOnMount: globalDisableRefetchOnMount, dynamicRealtimeThrottleMs, getCollectionItemKey: filterCollectionItemObjKey, }: {
79
+ declare function newTSDFCollectionStore<ItemState extends ValidStoreState, NError, ItemPayload extends ValidPayload>({ debugName, fetchFn, lowPriorityThrottleMs, errorNormalizer, disableInitialDataInvalidation, mediumPriorityThrottleMs, initialStateItems, disableRefetchOnMount: globalDisableRefetchOnMount, dynamicRealtimeThrottleMs, getCollectionItemKey: filterCollectionItemObjKey, }: {
81
80
  debugName?: string;
82
81
  fetchFn: (params: ItemPayload) => Promise<ItemState>;
83
82
  getCollectionItemKey?: (params: ItemPayload) => ValidPayload | any[];
84
83
  errorNormalizer: (exception: unknown) => NError;
85
- disableRefetchOnWindowFocus?: boolean;
86
84
  disableRefetchOnMount?: boolean;
87
85
  initialStateItems?: CollectionInitialStateItem<ItemPayload, ItemState>[];
88
86
  disableInitialDataInvalidation?: boolean;
@@ -187,7 +185,7 @@ type ListQueryStoreInitialData<ItemState extends ValidStoreState, QueryPayload e
187
185
  hasMore: boolean;
188
186
  }[];
189
187
  };
190
- declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload>({ debugName, fetchListFn, fetchItemFn, errorNormalizer, defaultQuerySize, initialData, disableRefetchOnWindowFocus, disableRefetchOnMount: globalDisableRefetchOnMount, lowPriorityThrottleMs, disableInitialDataInvalidation, mediumPriorityThrottleMs, dynamicRealtimeThrottleMs, syncMutationsAndInvalidations, }: {
188
+ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload>({ debugName, fetchListFn, fetchItemFn, errorNormalizer, defaultQuerySize, initialData, disableRefetchOnMount: globalDisableRefetchOnMount, lowPriorityThrottleMs, disableInitialDataInvalidation, mediumPriorityThrottleMs, dynamicRealtimeThrottleMs, syncMutationsAndInvalidations, }: {
191
189
  debugName?: string;
192
190
  fetchListFn: (payload: QueryPayload, size: number) => Promise<FetchListFnReturn<ItemState, ItemPayload>>;
193
191
  fetchItemFn?: (itemId: ItemPayload) => Promise<ItemState>;
@@ -195,7 +193,6 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
195
193
  defaultQuerySize?: number;
196
194
  initialData?: ListQueryStoreInitialData<ItemState, QueryPayload, ItemPayload>;
197
195
  disableInitialDataInvalidation?: boolean;
198
- disableRefetchOnWindowFocus?: boolean;
199
196
  syncMutationsAndInvalidations?: {
200
197
  syncQueries: (query1: QueryPayload, query2: QueryPayload) => boolean;
201
198
  syncItemAndQuery: (itemPayload: ItemPayload, query: QueryPayload) => boolean;
package/dist/main.js CHANGED
@@ -363,7 +363,6 @@ function newTSDFDocumentStore({
363
363
  debugName,
364
364
  fetchFn,
365
365
  initialData,
366
- disableRefetchOnWindowFocus,
367
366
  disableRefetchOnMount: globalDisableRefetchOnMount,
368
367
  lowPriorityThrottleMs,
369
368
  mediumPriorityThrottleMs,
@@ -479,6 +478,7 @@ function newTSDFDocumentStore({
479
478
  });
480
479
  useOnMittEvent(storeEvents, "invalidateData", (priority) => {
481
480
  if (!invalidationWasTriggered) {
481
+ store.setKey("refetchOnMount", false);
482
482
  scheduleFetch(priority);
483
483
  invalidationWasTriggered = true;
484
484
  }
@@ -523,14 +523,6 @@ function newTSDFDocumentStore({
523
523
  { action: "update-state" }
524
524
  );
525
525
  }
526
- if (!disableRefetchOnWindowFocus) {
527
- let handleFocus2 = function() {
528
- invalidateData("lowPriority");
529
- };
530
- var handleFocus = handleFocus2;
531
- window.addEventListener("focus", handleFocus2);
532
- window.addEventListener("visibilitychange", handleFocus2);
533
- }
534
526
  return {
535
527
  store,
536
528
  awaitFetch,
@@ -598,7 +590,6 @@ import { klona } from "klona/json";
598
590
  function newTSDFCollectionStore({
599
591
  debugName,
600
592
  fetchFn,
601
- disableRefetchOnWindowFocus,
602
593
  lowPriorityThrottleMs,
603
594
  errorNormalizer,
604
595
  disableInitialDataInvalidation,
@@ -848,6 +839,12 @@ function newTSDFCollectionStore({
848
839
  if (itemKey !== event.itemKey)
849
840
  continue;
850
841
  if (!invalidationWasTriggered.has(itemKey)) {
842
+ store.produceState((draft) => {
843
+ const draftItem = draft[itemKey];
844
+ if (!draftItem)
845
+ return;
846
+ draftItem.refetchOnMount = false;
847
+ });
851
848
  scheduleFetch(event.priority, payload);
852
849
  invalidationWasTriggered.add(itemKey);
853
850
  }
@@ -976,14 +973,6 @@ function newTSDFCollectionStore({
976
973
  );
977
974
  return someItemWasUpdated;
978
975
  }
979
- if (!disableRefetchOnWindowFocus) {
980
- let handleFocus2 = function() {
981
- invalidateItem(() => true, "lowPriority");
982
- };
983
- var handleFocus = handleFocus2;
984
- window.addEventListener("focus", handleFocus2);
985
- window.addEventListener("visibilitychange", handleFocus2);
986
- }
987
976
  return {
988
977
  store,
989
978
  scheduleFetch,
@@ -1028,7 +1017,6 @@ function newTSDFListQueryStore({
1028
1017
  errorNormalizer,
1029
1018
  defaultQuerySize = 50,
1030
1019
  initialData,
1031
- disableRefetchOnWindowFocus,
1032
1020
  disableRefetchOnMount: globalDisableRefetchOnMount,
1033
1021
  lowPriorityThrottleMs,
1034
1022
  disableInitialDataInvalidation,
@@ -1415,6 +1403,12 @@ function newTSDFListQueryStore({
1415
1403
  if (key !== event.queryKey)
1416
1404
  continue;
1417
1405
  if (!queryInvalidationWasTriggered.has(key)) {
1406
+ store.produceState((draft) => {
1407
+ const query = draft.queries[key];
1408
+ if (!query?.refetchOnMount)
1409
+ return;
1410
+ query.refetchOnMount = false;
1411
+ });
1418
1412
  scheduleListQueryFetch(event.priority, payload);
1419
1413
  queryInvalidationWasTriggered.add(key);
1420
1414
  }
@@ -1730,6 +1724,12 @@ function newTSDFListQueryStore({
1730
1724
  if (itemKey !== event.itemKey)
1731
1725
  continue;
1732
1726
  if (!itemInvalidationWasTriggered.has(itemKey)) {
1727
+ store.produceState((draft) => {
1728
+ const query = draft.itemQueries[itemKey];
1729
+ if (!query?.refetchOnMount)
1730
+ return;
1731
+ query.refetchOnMount = false;
1732
+ });
1733
1733
  scheduleItemFetch(event.priority, payload);
1734
1734
  itemInvalidationWasTriggered.add(itemKey);
1735
1735
  }
@@ -1907,17 +1907,6 @@ function newTSDFListQueryStore({
1907
1907
  { action: { type: "delete-item-state", itemId } }
1908
1908
  );
1909
1909
  }
1910
- if (!disableRefetchOnWindowFocus) {
1911
- let handleFocus2 = function() {
1912
- invalidateQuery(() => true, "lowPriority");
1913
- if (fetchItemFn) {
1914
- invalidateItem(() => true, "lowPriority");
1915
- }
1916
- };
1917
- var handleFocus = handleFocus2;
1918
- window.addEventListener("focus", handleFocus2);
1919
- window.addEventListener("visibilitychange", handleFocus2);
1920
- }
1921
1910
  return {
1922
1911
  store,
1923
1912
  scheduleListQueryFetch,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdf",
3
- "version": "10.1.0",
3
+ "version": "11.1.0",
4
4
  "description": "A data fetching solution based on t-state",
5
5
  "license": "MIT",
6
6
  "author": "Lucas Santos",
@@ -61,7 +61,7 @@
61
61
  "tsup": "^6.5.0",
62
62
  "typescript": "^4.9.4",
63
63
  "vite": "^4.0.4",
64
- "vitest": "^0.27.1"
64
+ "vitest": "^0.29.3"
65
65
  },
66
66
  "dependencies": {
67
67
  "immer": "^9.0.17",