tsdf 8.0.0-beta.10 → 8.0.0-beta.12
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 +77 -31
- package/dist/main.js +63 -17
- 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({
|
|
@@ -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");
|
|
@@ -370,6 +377,21 @@ function useEnsureIsLoaded(ensureIsLoaded, enabled, forceFetch) {
|
|
|
370
377
|
return [useModifyResult, isLoadedEvtEmitter.emit];
|
|
371
378
|
}
|
|
372
379
|
|
|
380
|
+
// src/utils/reuseRefIfEqual.ts
|
|
381
|
+
var import_t_state2 = require("t-state");
|
|
382
|
+
function reusePrevIfEqual({
|
|
383
|
+
prev,
|
|
384
|
+
current,
|
|
385
|
+
d: equalityFn_ = import_t_state2.deepEqual
|
|
386
|
+
}) {
|
|
387
|
+
if (prev === void 0)
|
|
388
|
+
return current;
|
|
389
|
+
if (equalityFn_(prev, current)) {
|
|
390
|
+
return prev;
|
|
391
|
+
}
|
|
392
|
+
return current;
|
|
393
|
+
}
|
|
394
|
+
|
|
373
395
|
// src/documentStore.ts
|
|
374
396
|
function newTSDFDocumentStore({
|
|
375
397
|
debugName,
|
|
@@ -383,7 +405,7 @@ function newTSDFDocumentStore({
|
|
|
383
405
|
disableInitialDataInvalidation,
|
|
384
406
|
errorNormalizer
|
|
385
407
|
}) {
|
|
386
|
-
const store = new
|
|
408
|
+
const store = new import_t_state3.Store({
|
|
387
409
|
debugName,
|
|
388
410
|
state: {
|
|
389
411
|
data: initialData ?? null,
|
|
@@ -400,7 +422,6 @@ function newTSDFDocumentStore({
|
|
|
400
422
|
refetchOnMount: false
|
|
401
423
|
},
|
|
402
424
|
{
|
|
403
|
-
equalityCheck: import_t_state2.deepEqual,
|
|
404
425
|
action: store.state.status === "success" ? "fetch-start-refetching" : "fetch-start-loading"
|
|
405
426
|
}
|
|
406
427
|
);
|
|
@@ -410,10 +431,10 @@ function newTSDFDocumentStore({
|
|
|
410
431
|
return false;
|
|
411
432
|
store.setPartialState(
|
|
412
433
|
{
|
|
413
|
-
data,
|
|
434
|
+
data: reusePrevIfEqual({ prev: store.state.data, current: data }),
|
|
414
435
|
status: "success"
|
|
415
436
|
},
|
|
416
|
-
{ action: "fetch-success"
|
|
437
|
+
{ action: "fetch-success" }
|
|
417
438
|
);
|
|
418
439
|
return true;
|
|
419
440
|
} catch (exception) {
|
|
@@ -451,6 +472,10 @@ function newTSDFDocumentStore({
|
|
|
451
472
|
const storeEvents = (0, import_mitt2.default)();
|
|
452
473
|
let invalidationWasTriggered = false;
|
|
453
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;
|
|
454
479
|
store.setKey("refetchOnMount", priority, { action: "invalidate-data" });
|
|
455
480
|
invalidationWasTriggered = false;
|
|
456
481
|
storeEvents.emit("invalidateData", priority);
|
|
@@ -511,7 +536,7 @@ function newTSDFDocumentStore({
|
|
|
511
536
|
scheduleFetch("highPriority");
|
|
512
537
|
}
|
|
513
538
|
);
|
|
514
|
-
(0,
|
|
539
|
+
(0, import_t_state3.useSubscribeToStore)(store, ({ observe }) => {
|
|
515
540
|
observe.ifSelector((state) => state.status).change.then(({ current }) => {
|
|
516
541
|
if (current === "success" || current === "error") {
|
|
517
542
|
emitIsLoadedEvt("isLoaded", true);
|
|
@@ -553,7 +578,7 @@ function newTSDFDocumentStore({
|
|
|
553
578
|
// src/collectionStore.ts
|
|
554
579
|
var import_mitt3 = __toESM(require("mitt"), 1);
|
|
555
580
|
var import_react4 = require("react");
|
|
556
|
-
var
|
|
581
|
+
var import_t_state4 = require("t-state");
|
|
557
582
|
|
|
558
583
|
// src/collectionFetchOrquestrator.ts
|
|
559
584
|
function createCollectionFetchOrquestrator(props) {
|
|
@@ -631,7 +656,7 @@ function newTSDFCollectionStore({
|
|
|
631
656
|
};
|
|
632
657
|
}
|
|
633
658
|
}
|
|
634
|
-
const store = new
|
|
659
|
+
const store = new import_t_state4.Store({
|
|
635
660
|
debugName,
|
|
636
661
|
state: initialState
|
|
637
662
|
});
|
|
@@ -664,7 +689,7 @@ function newTSDFCollectionStore({
|
|
|
664
689
|
item.refetchOnMount = false;
|
|
665
690
|
},
|
|
666
691
|
{
|
|
667
|
-
equalityCheck:
|
|
692
|
+
equalityCheck: import_t_state4.deepEqual,
|
|
668
693
|
action: {
|
|
669
694
|
type: !itemState?.data ? "fetch-start-loading" : "fetch-start-refetching",
|
|
670
695
|
payload
|
|
@@ -680,14 +705,11 @@ function newTSDFCollectionStore({
|
|
|
680
705
|
const item = draft[itemId];
|
|
681
706
|
if (!item)
|
|
682
707
|
return;
|
|
683
|
-
item.data = data;
|
|
708
|
+
item.data = reusePrevIfEqual({ current: data, prev: item.data });
|
|
684
709
|
item.status = "success";
|
|
685
710
|
item.wasLoaded = true;
|
|
686
711
|
},
|
|
687
|
-
{
|
|
688
|
-
action: { type: "fetch-success", payload },
|
|
689
|
-
equalityCheck: import_t_state3.deepEqual
|
|
690
|
-
}
|
|
712
|
+
{ action: { type: "fetch-success", payload } }
|
|
691
713
|
);
|
|
692
714
|
return true;
|
|
693
715
|
} catch (exception) {
|
|
@@ -754,12 +776,19 @@ function newTSDFCollectionStore({
|
|
|
754
776
|
function invalidateItem(itemPayload, priority = "highPriority") {
|
|
755
777
|
const itemsKey = getItemsKeyArray(itemPayload);
|
|
756
778
|
for (const itemKey of itemsKey) {
|
|
779
|
+
const item = store.state[itemKey];
|
|
780
|
+
if (!item)
|
|
781
|
+
continue;
|
|
782
|
+
const currentInvalidationPriority = item.refetchOnMount ? fetchTypePriority[item.refetchOnMount] : -1;
|
|
783
|
+
const newInvalidationPriority = fetchTypePriority[priority];
|
|
784
|
+
if (currentInvalidationPriority >= newInvalidationPriority)
|
|
785
|
+
return;
|
|
757
786
|
store.produceState(
|
|
758
787
|
(draft) => {
|
|
759
|
-
const
|
|
760
|
-
if (!
|
|
788
|
+
const draftItem = draft[itemKey];
|
|
789
|
+
if (!draftItem)
|
|
761
790
|
return;
|
|
762
|
-
|
|
791
|
+
draftItem.refetchOnMount = priority;
|
|
763
792
|
},
|
|
764
793
|
{ action: { type: "invalidate-data", itemKey } }
|
|
765
794
|
);
|
|
@@ -845,7 +874,7 @@ function newTSDFCollectionStore({
|
|
|
845
874
|
]
|
|
846
875
|
);
|
|
847
876
|
const storeState = store.useSelector(resultSelector, {
|
|
848
|
-
equalityFn:
|
|
877
|
+
equalityFn: import_t_state4.deepEqual,
|
|
849
878
|
useExternalDeps: true
|
|
850
879
|
});
|
|
851
880
|
useOnMittEvent(storeEvents, "invalidateData", (event) => {
|
|
@@ -906,7 +935,7 @@ function newTSDFCollectionStore({
|
|
|
906
935
|
}
|
|
907
936
|
}
|
|
908
937
|
);
|
|
909
|
-
(0,
|
|
938
|
+
(0, import_t_state4.useSubscribeToStore)(store, ({ observe }) => {
|
|
910
939
|
if (!ensureIsLoaded)
|
|
911
940
|
return;
|
|
912
941
|
observe.ifSelector((state) => state[result.itemStateKey]?.status).change.then(({ current }) => {
|
|
@@ -1010,7 +1039,7 @@ function newTSDFCollectionStore({
|
|
|
1010
1039
|
// src/listQueryStore.ts
|
|
1011
1040
|
var import_mitt4 = __toESM(require("mitt"), 1);
|
|
1012
1041
|
var import_react5 = require("react");
|
|
1013
|
-
var
|
|
1042
|
+
var import_t_state5 = require("t-state");
|
|
1014
1043
|
var import_json2 = require("klona/json");
|
|
1015
1044
|
var noFetchFnError = "No fetchItemFn was provided";
|
|
1016
1045
|
function newTSDFListQueryStore({
|
|
@@ -1054,7 +1083,7 @@ function newTSDFListQueryStore({
|
|
|
1054
1083
|
};
|
|
1055
1084
|
}
|
|
1056
1085
|
}
|
|
1057
|
-
const store = new
|
|
1086
|
+
const store = new import_t_state5.Store({
|
|
1058
1087
|
debugName,
|
|
1059
1088
|
state: initialState
|
|
1060
1089
|
});
|
|
@@ -1089,7 +1118,7 @@ function newTSDFListQueryStore({
|
|
|
1089
1118
|
query.refetchOnMount = false;
|
|
1090
1119
|
},
|
|
1091
1120
|
{
|
|
1092
|
-
equalityCheck:
|
|
1121
|
+
equalityCheck: import_t_state5.deepEqual,
|
|
1093
1122
|
action: {
|
|
1094
1123
|
type: isLoading ? "fetch-query-start-loading" : fetchType === "loadMore" ? "fetch-query-loading-more" : "refetching-query-start",
|
|
1095
1124
|
payload
|
|
@@ -1120,7 +1149,10 @@ function newTSDFListQueryStore({
|
|
|
1120
1149
|
query.items = [];
|
|
1121
1150
|
for (const { data, itemPayload } of items) {
|
|
1122
1151
|
const itemKey = getItemKey(itemPayload);
|
|
1123
|
-
draft.items[itemKey] =
|
|
1152
|
+
draft.items[itemKey] = reusePrevIfEqual({
|
|
1153
|
+
current: data,
|
|
1154
|
+
prev: draft.items[itemKey] ?? void 0
|
|
1155
|
+
});
|
|
1124
1156
|
query.items.push(String(itemKey));
|
|
1125
1157
|
const itemQuery = draft.itemQueries[itemKey];
|
|
1126
1158
|
if (!itemQuery || itemQuery.status !== "loading" && itemQuery.status !== "refetching") {
|
|
@@ -1135,7 +1167,6 @@ function newTSDFListQueryStore({
|
|
|
1135
1167
|
}
|
|
1136
1168
|
},
|
|
1137
1169
|
{
|
|
1138
|
-
equalityCheck: import_t_state4.deepEqual,
|
|
1139
1170
|
action: { type: "fetch-query-success", payload }
|
|
1140
1171
|
}
|
|
1141
1172
|
);
|
|
@@ -1269,6 +1300,13 @@ function newTSDFListQueryStore({
|
|
|
1269
1300
|
function invalidateQuery(queryPayload, priority = "highPriority", ignoreInvalidationSync = false) {
|
|
1270
1301
|
const queriesKey = getQueriesKeyArray(queryPayload);
|
|
1271
1302
|
for (const { key } of queriesKey) {
|
|
1303
|
+
const queryState = store.state.queries[key];
|
|
1304
|
+
if (!queryState)
|
|
1305
|
+
continue;
|
|
1306
|
+
const currentInvalidationPriority = queryState.refetchOnMount ? fetchTypePriority[queryState.refetchOnMount] : -1;
|
|
1307
|
+
const newInvalidationPriority = fetchTypePriority[priority];
|
|
1308
|
+
if (currentInvalidationPriority >= newInvalidationPriority)
|
|
1309
|
+
return;
|
|
1272
1310
|
store.produceState(
|
|
1273
1311
|
(draft) => {
|
|
1274
1312
|
const query = draft.queries[key];
|
|
@@ -1368,7 +1406,7 @@ function newTSDFListQueryStore({
|
|
|
1368
1406
|
]
|
|
1369
1407
|
);
|
|
1370
1408
|
const storeState = store.useSelector(resultSelector, {
|
|
1371
|
-
equalityFn:
|
|
1409
|
+
equalityFn: import_t_state5.deepEqual,
|
|
1372
1410
|
useExternalDeps: true
|
|
1373
1411
|
});
|
|
1374
1412
|
useOnMittEvent(storeEvents, "invalidateQuery", (event) => {
|
|
@@ -1432,7 +1470,7 @@ function newTSDFListQueryStore({
|
|
|
1432
1470
|
}
|
|
1433
1471
|
}
|
|
1434
1472
|
);
|
|
1435
|
-
(0,
|
|
1473
|
+
(0, import_t_state5.useSubscribeToStore)(store, ({ observe }) => {
|
|
1436
1474
|
if (!ensureIsLoaded)
|
|
1437
1475
|
return;
|
|
1438
1476
|
observe.ifSelector((state) => state.queries[result.queryKey]?.status).change.then(({ current }) => {
|
|
@@ -1467,7 +1505,6 @@ function newTSDFListQueryStore({
|
|
|
1467
1505
|
itemQuery.refetchOnMount = false;
|
|
1468
1506
|
},
|
|
1469
1507
|
{
|
|
1470
|
-
equalityCheck: import_t_state4.deepEqual,
|
|
1471
1508
|
action: {
|
|
1472
1509
|
type: isLoaded ? "fetch-item-start" : "fetch-item-refetch-start",
|
|
1473
1510
|
itemPayload
|
|
@@ -1485,10 +1522,12 @@ function newTSDFListQueryStore({
|
|
|
1485
1522
|
return;
|
|
1486
1523
|
itemQuery.status = "success";
|
|
1487
1524
|
itemQuery.wasLoaded = true;
|
|
1488
|
-
draft.items[itemKey] =
|
|
1525
|
+
draft.items[itemKey] = reusePrevIfEqual({
|
|
1526
|
+
current: item,
|
|
1527
|
+
prev: draft.items[itemKey] ?? void 0
|
|
1528
|
+
});
|
|
1489
1529
|
},
|
|
1490
1530
|
{
|
|
1491
|
-
equalityCheck: import_t_state4.deepEqual,
|
|
1492
1531
|
action: { type: "fetch-item-success", itemPayload }
|
|
1493
1532
|
}
|
|
1494
1533
|
);
|
|
@@ -1557,6 +1596,13 @@ function newTSDFListQueryStore({
|
|
|
1557
1596
|
}
|
|
1558
1597
|
const itemsKey = getItemsKeyArray(itemId);
|
|
1559
1598
|
for (const { itemKey } of itemsKey) {
|
|
1599
|
+
const item = store.state.itemQueries[itemKey];
|
|
1600
|
+
if (!item)
|
|
1601
|
+
continue;
|
|
1602
|
+
const currentInvalidationPriority = item.refetchOnMount ? fetchTypePriority[item.refetchOnMount] : -1;
|
|
1603
|
+
const newInvalidationPriority = fetchTypePriority[priority];
|
|
1604
|
+
if (currentInvalidationPriority >= newInvalidationPriority)
|
|
1605
|
+
return;
|
|
1560
1606
|
store.produceState(
|
|
1561
1607
|
(draft) => {
|
|
1562
1608
|
const query = draft.itemQueries[itemKey];
|
|
@@ -1673,7 +1719,7 @@ function newTSDFListQueryStore({
|
|
|
1673
1719
|
]
|
|
1674
1720
|
);
|
|
1675
1721
|
const storeState = store.useSelector(resultSelector, {
|
|
1676
|
-
equalityFn:
|
|
1722
|
+
equalityFn: import_t_state5.deepEqual,
|
|
1677
1723
|
useExternalDeps: true
|
|
1678
1724
|
});
|
|
1679
1725
|
useOnMittEvent(storeEvents, "invalidateItem", (event) => {
|
|
@@ -1737,7 +1783,7 @@ function newTSDFListQueryStore({
|
|
|
1737
1783
|
}
|
|
1738
1784
|
}
|
|
1739
1785
|
);
|
|
1740
|
-
(0,
|
|
1786
|
+
(0, import_t_state5.useSubscribeToStore)(store, ({ observe }) => {
|
|
1741
1787
|
if (!ensureIsLoaded || !itemPayload)
|
|
1742
1788
|
return;
|
|
1743
1789
|
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({
|
|
@@ -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";
|
|
@@ -336,6 +343,21 @@ function useEnsureIsLoaded(ensureIsLoaded, enabled, forceFetch) {
|
|
|
336
343
|
return [useModifyResult, isLoadedEvtEmitter.emit];
|
|
337
344
|
}
|
|
338
345
|
|
|
346
|
+
// src/utils/reuseRefIfEqual.ts
|
|
347
|
+
import { deepEqual as deepEqual2 } from "t-state";
|
|
348
|
+
function reusePrevIfEqual({
|
|
349
|
+
prev,
|
|
350
|
+
current,
|
|
351
|
+
d: equalityFn_ = deepEqual2
|
|
352
|
+
}) {
|
|
353
|
+
if (prev === void 0)
|
|
354
|
+
return current;
|
|
355
|
+
if (equalityFn_(prev, current)) {
|
|
356
|
+
return prev;
|
|
357
|
+
}
|
|
358
|
+
return current;
|
|
359
|
+
}
|
|
360
|
+
|
|
339
361
|
// src/documentStore.ts
|
|
340
362
|
function newTSDFDocumentStore({
|
|
341
363
|
debugName,
|
|
@@ -366,7 +388,6 @@ function newTSDFDocumentStore({
|
|
|
366
388
|
refetchOnMount: false
|
|
367
389
|
},
|
|
368
390
|
{
|
|
369
|
-
equalityCheck: deepEqual2,
|
|
370
391
|
action: store.state.status === "success" ? "fetch-start-refetching" : "fetch-start-loading"
|
|
371
392
|
}
|
|
372
393
|
);
|
|
@@ -376,10 +397,10 @@ function newTSDFDocumentStore({
|
|
|
376
397
|
return false;
|
|
377
398
|
store.setPartialState(
|
|
378
399
|
{
|
|
379
|
-
data,
|
|
400
|
+
data: reusePrevIfEqual({ prev: store.state.data, current: data }),
|
|
380
401
|
status: "success"
|
|
381
402
|
},
|
|
382
|
-
{ action: "fetch-success"
|
|
403
|
+
{ action: "fetch-success" }
|
|
383
404
|
);
|
|
384
405
|
return true;
|
|
385
406
|
} catch (exception) {
|
|
@@ -417,6 +438,10 @@ function newTSDFDocumentStore({
|
|
|
417
438
|
const storeEvents = mitt2();
|
|
418
439
|
let invalidationWasTriggered = false;
|
|
419
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;
|
|
420
445
|
store.setKey("refetchOnMount", priority, { action: "invalidate-data" });
|
|
421
446
|
invalidationWasTriggered = false;
|
|
422
447
|
storeEvents.emit("invalidateData", priority);
|
|
@@ -646,14 +671,11 @@ function newTSDFCollectionStore({
|
|
|
646
671
|
const item = draft[itemId];
|
|
647
672
|
if (!item)
|
|
648
673
|
return;
|
|
649
|
-
item.data = data;
|
|
674
|
+
item.data = reusePrevIfEqual({ current: data, prev: item.data });
|
|
650
675
|
item.status = "success";
|
|
651
676
|
item.wasLoaded = true;
|
|
652
677
|
},
|
|
653
|
-
{
|
|
654
|
-
action: { type: "fetch-success", payload },
|
|
655
|
-
equalityCheck: deepEqual3
|
|
656
|
-
}
|
|
678
|
+
{ action: { type: "fetch-success", payload } }
|
|
657
679
|
);
|
|
658
680
|
return true;
|
|
659
681
|
} catch (exception) {
|
|
@@ -720,12 +742,19 @@ function newTSDFCollectionStore({
|
|
|
720
742
|
function invalidateItem(itemPayload, priority = "highPriority") {
|
|
721
743
|
const itemsKey = getItemsKeyArray(itemPayload);
|
|
722
744
|
for (const itemKey of itemsKey) {
|
|
745
|
+
const item = store.state[itemKey];
|
|
746
|
+
if (!item)
|
|
747
|
+
continue;
|
|
748
|
+
const currentInvalidationPriority = item.refetchOnMount ? fetchTypePriority[item.refetchOnMount] : -1;
|
|
749
|
+
const newInvalidationPriority = fetchTypePriority[priority];
|
|
750
|
+
if (currentInvalidationPriority >= newInvalidationPriority)
|
|
751
|
+
return;
|
|
723
752
|
store.produceState(
|
|
724
753
|
(draft) => {
|
|
725
|
-
const
|
|
726
|
-
if (!
|
|
754
|
+
const draftItem = draft[itemKey];
|
|
755
|
+
if (!draftItem)
|
|
727
756
|
return;
|
|
728
|
-
|
|
757
|
+
draftItem.refetchOnMount = priority;
|
|
729
758
|
},
|
|
730
759
|
{ action: { type: "invalidate-data", itemKey } }
|
|
731
760
|
);
|
|
@@ -1086,7 +1115,10 @@ function newTSDFListQueryStore({
|
|
|
1086
1115
|
query.items = [];
|
|
1087
1116
|
for (const { data, itemPayload } of items) {
|
|
1088
1117
|
const itemKey = getItemKey(itemPayload);
|
|
1089
|
-
draft.items[itemKey] =
|
|
1118
|
+
draft.items[itemKey] = reusePrevIfEqual({
|
|
1119
|
+
current: data,
|
|
1120
|
+
prev: draft.items[itemKey] ?? void 0
|
|
1121
|
+
});
|
|
1090
1122
|
query.items.push(String(itemKey));
|
|
1091
1123
|
const itemQuery = draft.itemQueries[itemKey];
|
|
1092
1124
|
if (!itemQuery || itemQuery.status !== "loading" && itemQuery.status !== "refetching") {
|
|
@@ -1101,7 +1133,6 @@ function newTSDFListQueryStore({
|
|
|
1101
1133
|
}
|
|
1102
1134
|
},
|
|
1103
1135
|
{
|
|
1104
|
-
equalityCheck: deepEqual4,
|
|
1105
1136
|
action: { type: "fetch-query-success", payload }
|
|
1106
1137
|
}
|
|
1107
1138
|
);
|
|
@@ -1235,6 +1266,13 @@ function newTSDFListQueryStore({
|
|
|
1235
1266
|
function invalidateQuery(queryPayload, priority = "highPriority", ignoreInvalidationSync = false) {
|
|
1236
1267
|
const queriesKey = getQueriesKeyArray(queryPayload);
|
|
1237
1268
|
for (const { key } of queriesKey) {
|
|
1269
|
+
const queryState = store.state.queries[key];
|
|
1270
|
+
if (!queryState)
|
|
1271
|
+
continue;
|
|
1272
|
+
const currentInvalidationPriority = queryState.refetchOnMount ? fetchTypePriority[queryState.refetchOnMount] : -1;
|
|
1273
|
+
const newInvalidationPriority = fetchTypePriority[priority];
|
|
1274
|
+
if (currentInvalidationPriority >= newInvalidationPriority)
|
|
1275
|
+
return;
|
|
1238
1276
|
store.produceState(
|
|
1239
1277
|
(draft) => {
|
|
1240
1278
|
const query = draft.queries[key];
|
|
@@ -1433,7 +1471,6 @@ function newTSDFListQueryStore({
|
|
|
1433
1471
|
itemQuery.refetchOnMount = false;
|
|
1434
1472
|
},
|
|
1435
1473
|
{
|
|
1436
|
-
equalityCheck: deepEqual4,
|
|
1437
1474
|
action: {
|
|
1438
1475
|
type: isLoaded ? "fetch-item-start" : "fetch-item-refetch-start",
|
|
1439
1476
|
itemPayload
|
|
@@ -1451,10 +1488,12 @@ function newTSDFListQueryStore({
|
|
|
1451
1488
|
return;
|
|
1452
1489
|
itemQuery.status = "success";
|
|
1453
1490
|
itemQuery.wasLoaded = true;
|
|
1454
|
-
draft.items[itemKey] =
|
|
1491
|
+
draft.items[itemKey] = reusePrevIfEqual({
|
|
1492
|
+
current: item,
|
|
1493
|
+
prev: draft.items[itemKey] ?? void 0
|
|
1494
|
+
});
|
|
1455
1495
|
},
|
|
1456
1496
|
{
|
|
1457
|
-
equalityCheck: deepEqual4,
|
|
1458
1497
|
action: { type: "fetch-item-success", itemPayload }
|
|
1459
1498
|
}
|
|
1460
1499
|
);
|
|
@@ -1523,6 +1562,13 @@ function newTSDFListQueryStore({
|
|
|
1523
1562
|
}
|
|
1524
1563
|
const itemsKey = getItemsKeyArray(itemId);
|
|
1525
1564
|
for (const { itemKey } of itemsKey) {
|
|
1565
|
+
const item = store.state.itemQueries[itemKey];
|
|
1566
|
+
if (!item)
|
|
1567
|
+
continue;
|
|
1568
|
+
const currentInvalidationPriority = item.refetchOnMount ? fetchTypePriority[item.refetchOnMount] : -1;
|
|
1569
|
+
const newInvalidationPriority = fetchTypePriority[priority];
|
|
1570
|
+
if (currentInvalidationPriority >= newInvalidationPriority)
|
|
1571
|
+
return;
|
|
1526
1572
|
store.produceState(
|
|
1527
1573
|
(draft) => {
|
|
1528
1574
|
const query = draft.itemQueries[itemKey];
|