tsdf 8.0.0-beta.10 → 8.0.0-beta.11
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 +42 -28
- package/dist/main.js +28 -14
- package/package.json +1 -1
package/dist/main.cjs
CHANGED
|
@@ -36,7 +36,7 @@ module.exports = __toCommonJS(main_exports);
|
|
|
36
36
|
var import_immer = require("immer");
|
|
37
37
|
var import_mitt2 = __toESM(require("mitt"), 1);
|
|
38
38
|
var import_react3 = require("react");
|
|
39
|
-
var
|
|
39
|
+
var import_t_state3 = require("t-state");
|
|
40
40
|
|
|
41
41
|
// src/fetchOrquestrator.ts
|
|
42
42
|
function createFetchOrquestrator({
|
|
@@ -370,6 +370,21 @@ function useEnsureIsLoaded(ensureIsLoaded, enabled, forceFetch) {
|
|
|
370
370
|
return [useModifyResult, isLoadedEvtEmitter.emit];
|
|
371
371
|
}
|
|
372
372
|
|
|
373
|
+
// src/utils/reuseRefIfEqual.ts
|
|
374
|
+
var import_t_state2 = require("t-state");
|
|
375
|
+
function reusePrevIfEqual({
|
|
376
|
+
prev,
|
|
377
|
+
current,
|
|
378
|
+
d: equalityFn_ = import_t_state2.deepEqual
|
|
379
|
+
}) {
|
|
380
|
+
if (prev === void 0)
|
|
381
|
+
return current;
|
|
382
|
+
if (equalityFn_(prev, current)) {
|
|
383
|
+
return prev;
|
|
384
|
+
}
|
|
385
|
+
return current;
|
|
386
|
+
}
|
|
387
|
+
|
|
373
388
|
// src/documentStore.ts
|
|
374
389
|
function newTSDFDocumentStore({
|
|
375
390
|
debugName,
|
|
@@ -383,7 +398,7 @@ function newTSDFDocumentStore({
|
|
|
383
398
|
disableInitialDataInvalidation,
|
|
384
399
|
errorNormalizer
|
|
385
400
|
}) {
|
|
386
|
-
const store = new
|
|
401
|
+
const store = new import_t_state3.Store({
|
|
387
402
|
debugName,
|
|
388
403
|
state: {
|
|
389
404
|
data: initialData ?? null,
|
|
@@ -400,7 +415,6 @@ function newTSDFDocumentStore({
|
|
|
400
415
|
refetchOnMount: false
|
|
401
416
|
},
|
|
402
417
|
{
|
|
403
|
-
equalityCheck: import_t_state2.deepEqual,
|
|
404
418
|
action: store.state.status === "success" ? "fetch-start-refetching" : "fetch-start-loading"
|
|
405
419
|
}
|
|
406
420
|
);
|
|
@@ -410,10 +424,10 @@ function newTSDFDocumentStore({
|
|
|
410
424
|
return false;
|
|
411
425
|
store.setPartialState(
|
|
412
426
|
{
|
|
413
|
-
data,
|
|
427
|
+
data: reusePrevIfEqual({ prev: store.state.data, current: data }),
|
|
414
428
|
status: "success"
|
|
415
429
|
},
|
|
416
|
-
{ action: "fetch-success"
|
|
430
|
+
{ action: "fetch-success" }
|
|
417
431
|
);
|
|
418
432
|
return true;
|
|
419
433
|
} catch (exception) {
|
|
@@ -511,7 +525,7 @@ function newTSDFDocumentStore({
|
|
|
511
525
|
scheduleFetch("highPriority");
|
|
512
526
|
}
|
|
513
527
|
);
|
|
514
|
-
(0,
|
|
528
|
+
(0, import_t_state3.useSubscribeToStore)(store, ({ observe }) => {
|
|
515
529
|
observe.ifSelector((state) => state.status).change.then(({ current }) => {
|
|
516
530
|
if (current === "success" || current === "error") {
|
|
517
531
|
emitIsLoadedEvt("isLoaded", true);
|
|
@@ -553,7 +567,7 @@ function newTSDFDocumentStore({
|
|
|
553
567
|
// src/collectionStore.ts
|
|
554
568
|
var import_mitt3 = __toESM(require("mitt"), 1);
|
|
555
569
|
var import_react4 = require("react");
|
|
556
|
-
var
|
|
570
|
+
var import_t_state4 = require("t-state");
|
|
557
571
|
|
|
558
572
|
// src/collectionFetchOrquestrator.ts
|
|
559
573
|
function createCollectionFetchOrquestrator(props) {
|
|
@@ -631,7 +645,7 @@ function newTSDFCollectionStore({
|
|
|
631
645
|
};
|
|
632
646
|
}
|
|
633
647
|
}
|
|
634
|
-
const store = new
|
|
648
|
+
const store = new import_t_state4.Store({
|
|
635
649
|
debugName,
|
|
636
650
|
state: initialState
|
|
637
651
|
});
|
|
@@ -664,7 +678,7 @@ function newTSDFCollectionStore({
|
|
|
664
678
|
item.refetchOnMount = false;
|
|
665
679
|
},
|
|
666
680
|
{
|
|
667
|
-
equalityCheck:
|
|
681
|
+
equalityCheck: import_t_state4.deepEqual,
|
|
668
682
|
action: {
|
|
669
683
|
type: !itemState?.data ? "fetch-start-loading" : "fetch-start-refetching",
|
|
670
684
|
payload
|
|
@@ -680,14 +694,11 @@ function newTSDFCollectionStore({
|
|
|
680
694
|
const item = draft[itemId];
|
|
681
695
|
if (!item)
|
|
682
696
|
return;
|
|
683
|
-
item.data = data;
|
|
697
|
+
item.data = reusePrevIfEqual({ current: data, prev: item.data });
|
|
684
698
|
item.status = "success";
|
|
685
699
|
item.wasLoaded = true;
|
|
686
700
|
},
|
|
687
|
-
{
|
|
688
|
-
action: { type: "fetch-success", payload },
|
|
689
|
-
equalityCheck: import_t_state3.deepEqual
|
|
690
|
-
}
|
|
701
|
+
{ action: { type: "fetch-success", payload } }
|
|
691
702
|
);
|
|
692
703
|
return true;
|
|
693
704
|
} catch (exception) {
|
|
@@ -845,7 +856,7 @@ function newTSDFCollectionStore({
|
|
|
845
856
|
]
|
|
846
857
|
);
|
|
847
858
|
const storeState = store.useSelector(resultSelector, {
|
|
848
|
-
equalityFn:
|
|
859
|
+
equalityFn: import_t_state4.deepEqual,
|
|
849
860
|
useExternalDeps: true
|
|
850
861
|
});
|
|
851
862
|
useOnMittEvent(storeEvents, "invalidateData", (event) => {
|
|
@@ -906,7 +917,7 @@ function newTSDFCollectionStore({
|
|
|
906
917
|
}
|
|
907
918
|
}
|
|
908
919
|
);
|
|
909
|
-
(0,
|
|
920
|
+
(0, import_t_state4.useSubscribeToStore)(store, ({ observe }) => {
|
|
910
921
|
if (!ensureIsLoaded)
|
|
911
922
|
return;
|
|
912
923
|
observe.ifSelector((state) => state[result.itemStateKey]?.status).change.then(({ current }) => {
|
|
@@ -1010,7 +1021,7 @@ function newTSDFCollectionStore({
|
|
|
1010
1021
|
// src/listQueryStore.ts
|
|
1011
1022
|
var import_mitt4 = __toESM(require("mitt"), 1);
|
|
1012
1023
|
var import_react5 = require("react");
|
|
1013
|
-
var
|
|
1024
|
+
var import_t_state5 = require("t-state");
|
|
1014
1025
|
var import_json2 = require("klona/json");
|
|
1015
1026
|
var noFetchFnError = "No fetchItemFn was provided";
|
|
1016
1027
|
function newTSDFListQueryStore({
|
|
@@ -1054,7 +1065,7 @@ function newTSDFListQueryStore({
|
|
|
1054
1065
|
};
|
|
1055
1066
|
}
|
|
1056
1067
|
}
|
|
1057
|
-
const store = new
|
|
1068
|
+
const store = new import_t_state5.Store({
|
|
1058
1069
|
debugName,
|
|
1059
1070
|
state: initialState
|
|
1060
1071
|
});
|
|
@@ -1089,7 +1100,7 @@ function newTSDFListQueryStore({
|
|
|
1089
1100
|
query.refetchOnMount = false;
|
|
1090
1101
|
},
|
|
1091
1102
|
{
|
|
1092
|
-
equalityCheck:
|
|
1103
|
+
equalityCheck: import_t_state5.deepEqual,
|
|
1093
1104
|
action: {
|
|
1094
1105
|
type: isLoading ? "fetch-query-start-loading" : fetchType === "loadMore" ? "fetch-query-loading-more" : "refetching-query-start",
|
|
1095
1106
|
payload
|
|
@@ -1120,7 +1131,10 @@ function newTSDFListQueryStore({
|
|
|
1120
1131
|
query.items = [];
|
|
1121
1132
|
for (const { data, itemPayload } of items) {
|
|
1122
1133
|
const itemKey = getItemKey(itemPayload);
|
|
1123
|
-
draft.items[itemKey] =
|
|
1134
|
+
draft.items[itemKey] = reusePrevIfEqual({
|
|
1135
|
+
current: data,
|
|
1136
|
+
prev: draft.items[itemKey] ?? void 0
|
|
1137
|
+
});
|
|
1124
1138
|
query.items.push(String(itemKey));
|
|
1125
1139
|
const itemQuery = draft.itemQueries[itemKey];
|
|
1126
1140
|
if (!itemQuery || itemQuery.status !== "loading" && itemQuery.status !== "refetching") {
|
|
@@ -1135,7 +1149,6 @@ function newTSDFListQueryStore({
|
|
|
1135
1149
|
}
|
|
1136
1150
|
},
|
|
1137
1151
|
{
|
|
1138
|
-
equalityCheck: import_t_state4.deepEqual,
|
|
1139
1152
|
action: { type: "fetch-query-success", payload }
|
|
1140
1153
|
}
|
|
1141
1154
|
);
|
|
@@ -1368,7 +1381,7 @@ function newTSDFListQueryStore({
|
|
|
1368
1381
|
]
|
|
1369
1382
|
);
|
|
1370
1383
|
const storeState = store.useSelector(resultSelector, {
|
|
1371
|
-
equalityFn:
|
|
1384
|
+
equalityFn: import_t_state5.deepEqual,
|
|
1372
1385
|
useExternalDeps: true
|
|
1373
1386
|
});
|
|
1374
1387
|
useOnMittEvent(storeEvents, "invalidateQuery", (event) => {
|
|
@@ -1432,7 +1445,7 @@ function newTSDFListQueryStore({
|
|
|
1432
1445
|
}
|
|
1433
1446
|
}
|
|
1434
1447
|
);
|
|
1435
|
-
(0,
|
|
1448
|
+
(0, import_t_state5.useSubscribeToStore)(store, ({ observe }) => {
|
|
1436
1449
|
if (!ensureIsLoaded)
|
|
1437
1450
|
return;
|
|
1438
1451
|
observe.ifSelector((state) => state.queries[result.queryKey]?.status).change.then(({ current }) => {
|
|
@@ -1467,7 +1480,6 @@ function newTSDFListQueryStore({
|
|
|
1467
1480
|
itemQuery.refetchOnMount = false;
|
|
1468
1481
|
},
|
|
1469
1482
|
{
|
|
1470
|
-
equalityCheck: import_t_state4.deepEqual,
|
|
1471
1483
|
action: {
|
|
1472
1484
|
type: isLoaded ? "fetch-item-start" : "fetch-item-refetch-start",
|
|
1473
1485
|
itemPayload
|
|
@@ -1485,10 +1497,12 @@ function newTSDFListQueryStore({
|
|
|
1485
1497
|
return;
|
|
1486
1498
|
itemQuery.status = "success";
|
|
1487
1499
|
itemQuery.wasLoaded = true;
|
|
1488
|
-
draft.items[itemKey] =
|
|
1500
|
+
draft.items[itemKey] = reusePrevIfEqual({
|
|
1501
|
+
current: item,
|
|
1502
|
+
prev: draft.items[itemKey] ?? void 0
|
|
1503
|
+
});
|
|
1489
1504
|
},
|
|
1490
1505
|
{
|
|
1491
|
-
equalityCheck: import_t_state4.deepEqual,
|
|
1492
1506
|
action: { type: "fetch-item-success", itemPayload }
|
|
1493
1507
|
}
|
|
1494
1508
|
);
|
|
@@ -1673,7 +1687,7 @@ function newTSDFListQueryStore({
|
|
|
1673
1687
|
]
|
|
1674
1688
|
);
|
|
1675
1689
|
const storeState = store.useSelector(resultSelector, {
|
|
1676
|
-
equalityFn:
|
|
1690
|
+
equalityFn: import_t_state5.deepEqual,
|
|
1677
1691
|
useExternalDeps: true
|
|
1678
1692
|
});
|
|
1679
1693
|
useOnMittEvent(storeEvents, "invalidateItem", (event) => {
|
|
@@ -1737,7 +1751,7 @@ function newTSDFListQueryStore({
|
|
|
1737
1751
|
}
|
|
1738
1752
|
}
|
|
1739
1753
|
);
|
|
1740
|
-
(0,
|
|
1754
|
+
(0, import_t_state5.useSubscribeToStore)(store, ({ observe }) => {
|
|
1741
1755
|
if (!ensureIsLoaded || !itemPayload)
|
|
1742
1756
|
return;
|
|
1743
1757
|
observe.ifSelector((state) => state.itemQueries[itemPayload]?.status).change.then(({ current }) => {
|
package/dist/main.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { produce } from "immer";
|
|
3
3
|
import mitt2 from "mitt";
|
|
4
4
|
import { useCallback, useEffect as useEffect2 } from "react";
|
|
5
|
-
import {
|
|
5
|
+
import { Store, useSubscribeToStore } from "t-state";
|
|
6
6
|
|
|
7
7
|
// src/fetchOrquestrator.ts
|
|
8
8
|
function createFetchOrquestrator({
|
|
@@ -336,6 +336,21 @@ function useEnsureIsLoaded(ensureIsLoaded, enabled, forceFetch) {
|
|
|
336
336
|
return [useModifyResult, isLoadedEvtEmitter.emit];
|
|
337
337
|
}
|
|
338
338
|
|
|
339
|
+
// src/utils/reuseRefIfEqual.ts
|
|
340
|
+
import { deepEqual as deepEqual2 } from "t-state";
|
|
341
|
+
function reusePrevIfEqual({
|
|
342
|
+
prev,
|
|
343
|
+
current,
|
|
344
|
+
d: equalityFn_ = deepEqual2
|
|
345
|
+
}) {
|
|
346
|
+
if (prev === void 0)
|
|
347
|
+
return current;
|
|
348
|
+
if (equalityFn_(prev, current)) {
|
|
349
|
+
return prev;
|
|
350
|
+
}
|
|
351
|
+
return current;
|
|
352
|
+
}
|
|
353
|
+
|
|
339
354
|
// src/documentStore.ts
|
|
340
355
|
function newTSDFDocumentStore({
|
|
341
356
|
debugName,
|
|
@@ -366,7 +381,6 @@ function newTSDFDocumentStore({
|
|
|
366
381
|
refetchOnMount: false
|
|
367
382
|
},
|
|
368
383
|
{
|
|
369
|
-
equalityCheck: deepEqual2,
|
|
370
384
|
action: store.state.status === "success" ? "fetch-start-refetching" : "fetch-start-loading"
|
|
371
385
|
}
|
|
372
386
|
);
|
|
@@ -376,10 +390,10 @@ function newTSDFDocumentStore({
|
|
|
376
390
|
return false;
|
|
377
391
|
store.setPartialState(
|
|
378
392
|
{
|
|
379
|
-
data,
|
|
393
|
+
data: reusePrevIfEqual({ prev: store.state.data, current: data }),
|
|
380
394
|
status: "success"
|
|
381
395
|
},
|
|
382
|
-
{ action: "fetch-success"
|
|
396
|
+
{ action: "fetch-success" }
|
|
383
397
|
);
|
|
384
398
|
return true;
|
|
385
399
|
} catch (exception) {
|
|
@@ -646,14 +660,11 @@ function newTSDFCollectionStore({
|
|
|
646
660
|
const item = draft[itemId];
|
|
647
661
|
if (!item)
|
|
648
662
|
return;
|
|
649
|
-
item.data = data;
|
|
663
|
+
item.data = reusePrevIfEqual({ current: data, prev: item.data });
|
|
650
664
|
item.status = "success";
|
|
651
665
|
item.wasLoaded = true;
|
|
652
666
|
},
|
|
653
|
-
{
|
|
654
|
-
action: { type: "fetch-success", payload },
|
|
655
|
-
equalityCheck: deepEqual3
|
|
656
|
-
}
|
|
667
|
+
{ action: { type: "fetch-success", payload } }
|
|
657
668
|
);
|
|
658
669
|
return true;
|
|
659
670
|
} catch (exception) {
|
|
@@ -1086,7 +1097,10 @@ function newTSDFListQueryStore({
|
|
|
1086
1097
|
query.items = [];
|
|
1087
1098
|
for (const { data, itemPayload } of items) {
|
|
1088
1099
|
const itemKey = getItemKey(itemPayload);
|
|
1089
|
-
draft.items[itemKey] =
|
|
1100
|
+
draft.items[itemKey] = reusePrevIfEqual({
|
|
1101
|
+
current: data,
|
|
1102
|
+
prev: draft.items[itemKey] ?? void 0
|
|
1103
|
+
});
|
|
1090
1104
|
query.items.push(String(itemKey));
|
|
1091
1105
|
const itemQuery = draft.itemQueries[itemKey];
|
|
1092
1106
|
if (!itemQuery || itemQuery.status !== "loading" && itemQuery.status !== "refetching") {
|
|
@@ -1101,7 +1115,6 @@ function newTSDFListQueryStore({
|
|
|
1101
1115
|
}
|
|
1102
1116
|
},
|
|
1103
1117
|
{
|
|
1104
|
-
equalityCheck: deepEqual4,
|
|
1105
1118
|
action: { type: "fetch-query-success", payload }
|
|
1106
1119
|
}
|
|
1107
1120
|
);
|
|
@@ -1433,7 +1446,6 @@ function newTSDFListQueryStore({
|
|
|
1433
1446
|
itemQuery.refetchOnMount = false;
|
|
1434
1447
|
},
|
|
1435
1448
|
{
|
|
1436
|
-
equalityCheck: deepEqual4,
|
|
1437
1449
|
action: {
|
|
1438
1450
|
type: isLoaded ? "fetch-item-start" : "fetch-item-refetch-start",
|
|
1439
1451
|
itemPayload
|
|
@@ -1451,10 +1463,12 @@ function newTSDFListQueryStore({
|
|
|
1451
1463
|
return;
|
|
1452
1464
|
itemQuery.status = "success";
|
|
1453
1465
|
itemQuery.wasLoaded = true;
|
|
1454
|
-
draft.items[itemKey] =
|
|
1466
|
+
draft.items[itemKey] = reusePrevIfEqual({
|
|
1467
|
+
current: item,
|
|
1468
|
+
prev: draft.items[itemKey] ?? void 0
|
|
1469
|
+
});
|
|
1455
1470
|
},
|
|
1456
1471
|
{
|
|
1457
|
-
equalityCheck: deepEqual4,
|
|
1458
1472
|
action: { type: "fetch-item-success", itemPayload }
|
|
1459
1473
|
}
|
|
1460
1474
|
);
|