tsdf 8.0.0-beta.11 → 8.0.0-beta.13

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.
Files changed (3) hide show
  1. package/dist/main.cjs +50 -24
  2. package/dist/main.js +50 -24
  3. package/package.json +1 -1
package/dist/main.cjs CHANGED
@@ -269,6 +269,13 @@ function getAutoIncrementId() {
269
269
  return ++autoIncrementId;
270
270
  }
271
271
 
272
+ // src/storeShared.ts
273
+ var fetchTypePriority = {
274
+ lowPriority: 0,
275
+ realtimeUpdate: 1,
276
+ highPriority: 2
277
+ };
278
+
272
279
  // src/useEnsureIsLoaded.ts
273
280
  var import_mitt = __toESM(require("mitt"), 1);
274
281
  var import_react2 = require("react");
@@ -465,6 +472,10 @@ function newTSDFDocumentStore({
465
472
  const storeEvents = (0, import_mitt2.default)();
466
473
  let invalidationWasTriggered = false;
467
474
  function invalidateData(priority = "highPriority") {
475
+ const currentInvalidationPriority = store.state.refetchOnMount ? fetchTypePriority[store.state.refetchOnMount] : -1;
476
+ const newInvalidationPriority = fetchTypePriority[priority];
477
+ if (currentInvalidationPriority >= newInvalidationPriority)
478
+ return;
468
479
  store.setKey("refetchOnMount", priority, { action: "invalidate-data" });
469
480
  invalidationWasTriggered = false;
470
481
  storeEvents.emit("invalidateData", priority);
@@ -509,13 +520,14 @@ function newTSDFDocumentStore({
509
520
  (0, import_react3.useEffect)(() => {
510
521
  if (disabled)
511
522
  return;
523
+ const fetchType = store.state.refetchOnMount || "lowPriority";
512
524
  if (disableRefetchOnMount) {
513
525
  const shouldFetch = store.state.refetchOnMount || store.state.status === "idle";
514
526
  if (shouldFetch) {
515
- scheduleFetch(store.state.refetchOnMount || "lowPriority");
527
+ scheduleFetch(fetchType);
516
528
  }
517
529
  } else {
518
- scheduleFetch("lowPriority");
530
+ scheduleFetch(fetchType);
519
531
  }
520
532
  }, [disableRefetchOnMount, disabled]);
521
533
  const [useModifyResult, emitIsLoadedEvt] = useEnsureIsLoaded(
@@ -765,12 +777,19 @@ function newTSDFCollectionStore({
765
777
  function invalidateItem(itemPayload, priority = "highPriority") {
766
778
  const itemsKey = getItemsKeyArray(itemPayload);
767
779
  for (const itemKey of itemsKey) {
780
+ const item = store.state[itemKey];
781
+ if (!item)
782
+ continue;
783
+ const currentInvalidationPriority = item.refetchOnMount ? fetchTypePriority[item.refetchOnMount] : -1;
784
+ const newInvalidationPriority = fetchTypePriority[priority];
785
+ if (currentInvalidationPriority >= newInvalidationPriority)
786
+ return;
768
787
  store.produceState(
769
788
  (draft) => {
770
- const item = draft[itemKey];
771
- if (!item)
789
+ const draftItem = draft[itemKey];
790
+ if (!draftItem)
772
791
  return;
773
- item.refetchOnMount = priority;
792
+ draftItem.refetchOnMount = priority;
774
793
  },
775
794
  { action: { type: "invalidate-data", itemKey } }
776
795
  );
@@ -872,18 +891,16 @@ function newTSDFCollectionStore({
872
891
  (0, import_react4.useEffect)(() => {
873
892
  for (const { itemKey: itemId, payload } of queriesWithId) {
874
893
  if (itemId) {
894
+ const itemState = getItemState(payload);
895
+ const fetchType = itemState?.refetchOnMount || "lowPriority";
875
896
  if (disableRefetchOnMount) {
876
- const itemState = getItemState(payload);
877
897
  const shouldFetch = !itemState?.wasLoaded || itemState.refetchOnMount;
878
898
  if (shouldFetch) {
879
- scheduleFetch(
880
- itemState?.refetchOnMount || "lowPriority",
881
- payload
882
- );
899
+ scheduleFetch(fetchType, payload);
883
900
  return;
884
901
  }
885
902
  } else {
886
- scheduleFetch("lowPriority", payload);
903
+ scheduleFetch(fetchType, payload);
887
904
  }
888
905
  }
889
906
  }
@@ -1282,6 +1299,13 @@ function newTSDFListQueryStore({
1282
1299
  function invalidateQuery(queryPayload, priority = "highPriority", ignoreInvalidationSync = false) {
1283
1300
  const queriesKey = getQueriesKeyArray(queryPayload);
1284
1301
  for (const { key } of queriesKey) {
1302
+ const queryState = store.state.queries[key];
1303
+ if (!queryState)
1304
+ continue;
1305
+ const currentInvalidationPriority = queryState.refetchOnMount ? fetchTypePriority[queryState.refetchOnMount] : -1;
1306
+ const newInvalidationPriority = fetchTypePriority[priority];
1307
+ if (currentInvalidationPriority >= newInvalidationPriority)
1308
+ return;
1285
1309
  store.produceState(
1286
1310
  (draft) => {
1287
1311
  const query = draft.queries[key];
@@ -1398,19 +1422,16 @@ function newTSDFListQueryStore({
1398
1422
  (0, import_react5.useEffect)(() => {
1399
1423
  for (const { key: itemId, payload: fetchParams } of queriesWithId) {
1400
1424
  if (itemId) {
1425
+ const itemState = getQueryState(fetchParams);
1426
+ const fetchType = itemState?.refetchOnMount || "lowPriority";
1401
1427
  if (disableRefetchOnMount) {
1402
- const itemState = getQueryState(fetchParams);
1403
1428
  const shouldFetch = !itemState || !itemState.wasLoaded || itemState.refetchOnMount;
1404
1429
  if (shouldFetch) {
1405
- scheduleListQueryFetch(
1406
- itemState?.refetchOnMount || "lowPriority",
1407
- fetchParams,
1408
- loadSizeConst
1409
- );
1430
+ scheduleListQueryFetch(fetchType, fetchParams, loadSizeConst);
1410
1431
  return;
1411
1432
  }
1412
1433
  } else {
1413
- scheduleListQueryFetch("lowPriority", fetchParams, loadSizeConst);
1434
+ scheduleListQueryFetch(fetchType, fetchParams, loadSizeConst);
1414
1435
  }
1415
1436
  }
1416
1437
  }
@@ -1571,6 +1592,13 @@ function newTSDFListQueryStore({
1571
1592
  }
1572
1593
  const itemsKey = getItemsKeyArray(itemId);
1573
1594
  for (const { itemKey } of itemsKey) {
1595
+ const item = store.state.itemQueries[itemKey];
1596
+ if (!item)
1597
+ continue;
1598
+ const currentInvalidationPriority = item.refetchOnMount ? fetchTypePriority[item.refetchOnMount] : -1;
1599
+ const newInvalidationPriority = fetchTypePriority[priority];
1600
+ if (currentInvalidationPriority >= newInvalidationPriority)
1601
+ return;
1574
1602
  store.produceState(
1575
1603
  (draft) => {
1576
1604
  const query = draft.itemQueries[itemKey];
@@ -1703,18 +1731,16 @@ function newTSDFListQueryStore({
1703
1731
  (0, import_react5.useEffect)(() => {
1704
1732
  for (const { payload, itemKey } of memoizedItemKeys) {
1705
1733
  if (itemKey) {
1734
+ const itemState = store.state.itemQueries[itemKey];
1735
+ const fetchType = itemState?.refetchOnMount || "lowPriority";
1706
1736
  if (disableRefetchOnMount) {
1707
- const itemState = store.state.itemQueries[itemKey];
1708
1737
  const shouldFetch = !itemState || !itemState.wasLoaded || itemState.refetchOnMount;
1709
1738
  if (shouldFetch) {
1710
- scheduleItemFetch(
1711
- itemState?.refetchOnMount || "lowPriority",
1712
- payload
1713
- );
1739
+ scheduleItemFetch(fetchType, payload);
1714
1740
  return;
1715
1741
  }
1716
1742
  } else {
1717
- scheduleItemFetch("lowPriority", payload);
1743
+ scheduleItemFetch(fetchType, payload);
1718
1744
  }
1719
1745
  }
1720
1746
  }
package/dist/main.js CHANGED
@@ -235,6 +235,13 @@ function getAutoIncrementId() {
235
235
  return ++autoIncrementId;
236
236
  }
237
237
 
238
+ // src/storeShared.ts
239
+ var fetchTypePriority = {
240
+ lowPriority: 0,
241
+ realtimeUpdate: 1,
242
+ highPriority: 2
243
+ };
244
+
238
245
  // src/useEnsureIsLoaded.ts
239
246
  import mitt from "mitt";
240
247
  import { useMemo as useMemo2, useState } from "react";
@@ -431,6 +438,10 @@ function newTSDFDocumentStore({
431
438
  const storeEvents = mitt2();
432
439
  let invalidationWasTriggered = false;
433
440
  function invalidateData(priority = "highPriority") {
441
+ const currentInvalidationPriority = store.state.refetchOnMount ? fetchTypePriority[store.state.refetchOnMount] : -1;
442
+ const newInvalidationPriority = fetchTypePriority[priority];
443
+ if (currentInvalidationPriority >= newInvalidationPriority)
444
+ return;
434
445
  store.setKey("refetchOnMount", priority, { action: "invalidate-data" });
435
446
  invalidationWasTriggered = false;
436
447
  storeEvents.emit("invalidateData", priority);
@@ -475,13 +486,14 @@ function newTSDFDocumentStore({
475
486
  useEffect2(() => {
476
487
  if (disabled)
477
488
  return;
489
+ const fetchType = store.state.refetchOnMount || "lowPriority";
478
490
  if (disableRefetchOnMount) {
479
491
  const shouldFetch = store.state.refetchOnMount || store.state.status === "idle";
480
492
  if (shouldFetch) {
481
- scheduleFetch(store.state.refetchOnMount || "lowPriority");
493
+ scheduleFetch(fetchType);
482
494
  }
483
495
  } else {
484
- scheduleFetch("lowPriority");
496
+ scheduleFetch(fetchType);
485
497
  }
486
498
  }, [disableRefetchOnMount, disabled]);
487
499
  const [useModifyResult, emitIsLoadedEvt] = useEnsureIsLoaded(
@@ -731,12 +743,19 @@ function newTSDFCollectionStore({
731
743
  function invalidateItem(itemPayload, priority = "highPriority") {
732
744
  const itemsKey = getItemsKeyArray(itemPayload);
733
745
  for (const itemKey of itemsKey) {
746
+ const item = store.state[itemKey];
747
+ if (!item)
748
+ continue;
749
+ const currentInvalidationPriority = item.refetchOnMount ? fetchTypePriority[item.refetchOnMount] : -1;
750
+ const newInvalidationPriority = fetchTypePriority[priority];
751
+ if (currentInvalidationPriority >= newInvalidationPriority)
752
+ return;
734
753
  store.produceState(
735
754
  (draft) => {
736
- const item = draft[itemKey];
737
- if (!item)
755
+ const draftItem = draft[itemKey];
756
+ if (!draftItem)
738
757
  return;
739
- item.refetchOnMount = priority;
758
+ draftItem.refetchOnMount = priority;
740
759
  },
741
760
  { action: { type: "invalidate-data", itemKey } }
742
761
  );
@@ -838,18 +857,16 @@ function newTSDFCollectionStore({
838
857
  useEffect3(() => {
839
858
  for (const { itemKey: itemId, payload } of queriesWithId) {
840
859
  if (itemId) {
860
+ const itemState = getItemState(payload);
861
+ const fetchType = itemState?.refetchOnMount || "lowPriority";
841
862
  if (disableRefetchOnMount) {
842
- const itemState = getItemState(payload);
843
863
  const shouldFetch = !itemState?.wasLoaded || itemState.refetchOnMount;
844
864
  if (shouldFetch) {
845
- scheduleFetch(
846
- itemState?.refetchOnMount || "lowPriority",
847
- payload
848
- );
865
+ scheduleFetch(fetchType, payload);
849
866
  return;
850
867
  }
851
868
  } else {
852
- scheduleFetch("lowPriority", payload);
869
+ scheduleFetch(fetchType, payload);
853
870
  }
854
871
  }
855
872
  }
@@ -1248,6 +1265,13 @@ function newTSDFListQueryStore({
1248
1265
  function invalidateQuery(queryPayload, priority = "highPriority", ignoreInvalidationSync = false) {
1249
1266
  const queriesKey = getQueriesKeyArray(queryPayload);
1250
1267
  for (const { key } of queriesKey) {
1268
+ const queryState = store.state.queries[key];
1269
+ if (!queryState)
1270
+ continue;
1271
+ const currentInvalidationPriority = queryState.refetchOnMount ? fetchTypePriority[queryState.refetchOnMount] : -1;
1272
+ const newInvalidationPriority = fetchTypePriority[priority];
1273
+ if (currentInvalidationPriority >= newInvalidationPriority)
1274
+ return;
1251
1275
  store.produceState(
1252
1276
  (draft) => {
1253
1277
  const query = draft.queries[key];
@@ -1364,19 +1388,16 @@ function newTSDFListQueryStore({
1364
1388
  useEffect4(() => {
1365
1389
  for (const { key: itemId, payload: fetchParams } of queriesWithId) {
1366
1390
  if (itemId) {
1391
+ const itemState = getQueryState(fetchParams);
1392
+ const fetchType = itemState?.refetchOnMount || "lowPriority";
1367
1393
  if (disableRefetchOnMount) {
1368
- const itemState = getQueryState(fetchParams);
1369
1394
  const shouldFetch = !itemState || !itemState.wasLoaded || itemState.refetchOnMount;
1370
1395
  if (shouldFetch) {
1371
- scheduleListQueryFetch(
1372
- itemState?.refetchOnMount || "lowPriority",
1373
- fetchParams,
1374
- loadSizeConst
1375
- );
1396
+ scheduleListQueryFetch(fetchType, fetchParams, loadSizeConst);
1376
1397
  return;
1377
1398
  }
1378
1399
  } else {
1379
- scheduleListQueryFetch("lowPriority", fetchParams, loadSizeConst);
1400
+ scheduleListQueryFetch(fetchType, fetchParams, loadSizeConst);
1380
1401
  }
1381
1402
  }
1382
1403
  }
@@ -1537,6 +1558,13 @@ function newTSDFListQueryStore({
1537
1558
  }
1538
1559
  const itemsKey = getItemsKeyArray(itemId);
1539
1560
  for (const { itemKey } of itemsKey) {
1561
+ const item = store.state.itemQueries[itemKey];
1562
+ if (!item)
1563
+ continue;
1564
+ const currentInvalidationPriority = item.refetchOnMount ? fetchTypePriority[item.refetchOnMount] : -1;
1565
+ const newInvalidationPriority = fetchTypePriority[priority];
1566
+ if (currentInvalidationPriority >= newInvalidationPriority)
1567
+ return;
1540
1568
  store.produceState(
1541
1569
  (draft) => {
1542
1570
  const query = draft.itemQueries[itemKey];
@@ -1669,18 +1697,16 @@ function newTSDFListQueryStore({
1669
1697
  useEffect4(() => {
1670
1698
  for (const { payload, itemKey } of memoizedItemKeys) {
1671
1699
  if (itemKey) {
1700
+ const itemState = store.state.itemQueries[itemKey];
1701
+ const fetchType = itemState?.refetchOnMount || "lowPriority";
1672
1702
  if (disableRefetchOnMount) {
1673
- const itemState = store.state.itemQueries[itemKey];
1674
1703
  const shouldFetch = !itemState || !itemState.wasLoaded || itemState.refetchOnMount;
1675
1704
  if (shouldFetch) {
1676
- scheduleItemFetch(
1677
- itemState?.refetchOnMount || "lowPriority",
1678
- payload
1679
- );
1705
+ scheduleItemFetch(fetchType, payload);
1680
1706
  return;
1681
1707
  }
1682
1708
  } else {
1683
- scheduleItemFetch("lowPriority", payload);
1709
+ scheduleItemFetch(fetchType, payload);
1684
1710
  }
1685
1711
  }
1686
1712
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdf",
3
- "version": "8.0.0-beta.11",
3
+ "version": "8.0.0-beta.13",
4
4
  "description": "A data fetching solution based on t-state",
5
5
  "license": "MIT",
6
6
  "author": "Lucas Santos",