tsdf 11.1.4 → 11.1.5
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 +48 -73
- package/dist/main.d.ts +1 -0
- package/dist/main.js +26 -41
- package/package.json +2 -2
package/dist/main.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/main.ts
|
|
@@ -38,8 +28,7 @@ module.exports = __toCommonJS(main_exports);
|
|
|
38
28
|
|
|
39
29
|
// src/documentStore.ts
|
|
40
30
|
var import_immer = require("immer");
|
|
41
|
-
var
|
|
42
|
-
var import_react3 = require("react");
|
|
31
|
+
var import_react4 = require("react");
|
|
43
32
|
var import_t_state3 = require("t-state");
|
|
44
33
|
|
|
45
34
|
// src/fetchOrquestrator.ts
|
|
@@ -153,15 +142,16 @@ function createFetchOrquestrator({
|
|
|
153
142
|
}
|
|
154
143
|
function scheduleFetch(fetchType, params) {
|
|
155
144
|
const startTime = Date.now();
|
|
156
|
-
|
|
145
|
+
const fetchTypeToUse = !lastFetchStartTime ? "highPriority" : fetchType;
|
|
146
|
+
if (dynamicRealtimeThrottleMs && fetchTypeToUse === "realtimeUpdate") {
|
|
157
147
|
if (scheduleRTU(startTime, params)) {
|
|
158
148
|
return "rt-scheduled";
|
|
159
149
|
}
|
|
160
150
|
}
|
|
161
|
-
if (shouldSkipFetch(
|
|
151
|
+
if (shouldSkipFetch(fetchTypeToUse, startTime)) {
|
|
162
152
|
return "skipped";
|
|
163
153
|
}
|
|
164
|
-
if (shouldScheduleFetch(
|
|
154
|
+
if (shouldScheduleFetch(fetchTypeToUse, params)) {
|
|
165
155
|
return "scheduled";
|
|
166
156
|
}
|
|
167
157
|
startFetch(params, startTime);
|
|
@@ -290,8 +280,9 @@ var fetchTypePriority = {
|
|
|
290
280
|
};
|
|
291
281
|
|
|
292
282
|
// src/useEnsureIsLoaded.ts
|
|
293
|
-
var
|
|
294
|
-
var import_react2 = require("react");
|
|
283
|
+
var import_evtmitter = require("evtmitter");
|
|
284
|
+
var import_react2 = require("evtmitter/react");
|
|
285
|
+
var import_react3 = require("react");
|
|
295
286
|
|
|
296
287
|
// src/utils/hooks.ts
|
|
297
288
|
var import_react = require("react");
|
|
@@ -308,26 +299,6 @@ function useDeepCompareMemoize(value, equalityFn = import_t_state.deepEqual) {
|
|
|
308
299
|
function useDeepMemo(callback, deeps) {
|
|
309
300
|
return (0, import_react.useMemo)(callback, useDeepCompareMemoize(deeps));
|
|
310
301
|
}
|
|
311
|
-
function useLatestValue(value) {
|
|
312
|
-
const ref = (0, import_react.useRef)({ insideEffect: value, insideMemo: value });
|
|
313
|
-
ref.current.insideMemo = value;
|
|
314
|
-
(0, import_react.useLayoutEffect)(() => {
|
|
315
|
-
ref.current.insideEffect = value;
|
|
316
|
-
});
|
|
317
|
-
return ref.current;
|
|
318
|
-
}
|
|
319
|
-
function useOnMittEvent(mitt5, event, callback) {
|
|
320
|
-
const latestCallback = useLatestValue(callback);
|
|
321
|
-
(0, import_react.useLayoutEffect)(() => {
|
|
322
|
-
const cb = (payload) => {
|
|
323
|
-
latestCallback.insideEffect(payload);
|
|
324
|
-
};
|
|
325
|
-
mitt5.on(event, cb);
|
|
326
|
-
return () => {
|
|
327
|
-
mitt5.off(event, cb);
|
|
328
|
-
};
|
|
329
|
-
}, [mitt5, event, latestCallback]);
|
|
330
|
-
}
|
|
331
302
|
function usePrevious(value, initial) {
|
|
332
303
|
const ref = (0, import_react.useRef)(initial);
|
|
333
304
|
(0, import_react.useEffect)(() => {
|
|
@@ -358,8 +329,8 @@ function useConst(getValue) {
|
|
|
358
329
|
|
|
359
330
|
// src/useEnsureIsLoaded.ts
|
|
360
331
|
function useEnsureIsLoaded(ensureIsLoaded, enabled, forceFetch) {
|
|
361
|
-
const isLoadedEvtEmitter = useConst(() => (0,
|
|
362
|
-
const [isForceLoading, setIsForceLoading] = (0,
|
|
332
|
+
const isLoadedEvtEmitter = useConst(() => (0, import_evtmitter.evtmitter)());
|
|
333
|
+
const [isForceLoading, setIsForceLoading] = (0, import_react3.useState)(true);
|
|
363
334
|
useOnChange(
|
|
364
335
|
ensureIsLoaded && isForceLoading && enabled,
|
|
365
336
|
({ current }) => {
|
|
@@ -369,13 +340,13 @@ function useEnsureIsLoaded(ensureIsLoaded, enabled, forceFetch) {
|
|
|
369
340
|
},
|
|
370
341
|
{ callOnMount: true }
|
|
371
342
|
);
|
|
372
|
-
|
|
343
|
+
(0, import_react2.useOnEvtmitterEvent)(isLoadedEvtEmitter, "isLoaded", (isLoaded) => {
|
|
373
344
|
if (ensureIsLoaded && enabled && isLoaded) {
|
|
374
345
|
setIsForceLoading(false);
|
|
375
346
|
}
|
|
376
347
|
});
|
|
377
348
|
function useModifyResult(result) {
|
|
378
|
-
return (0,
|
|
349
|
+
return (0, import_react3.useMemo)(() => {
|
|
379
350
|
if (ensureIsLoaded) {
|
|
380
351
|
const newStatus = enabled && isForceLoading ? "loading" : result.status;
|
|
381
352
|
return {
|
|
@@ -390,7 +361,7 @@ function useEnsureIsLoaded(ensureIsLoaded, enabled, forceFetch) {
|
|
|
390
361
|
return [useModifyResult, isLoadedEvtEmitter.emit];
|
|
391
362
|
}
|
|
392
363
|
|
|
393
|
-
// src/utils/
|
|
364
|
+
// src/utils/reusePrevIfEqual.ts
|
|
394
365
|
var import_t_state2 = require("t-state");
|
|
395
366
|
function reusePrevIfEqual({
|
|
396
367
|
prev,
|
|
@@ -406,6 +377,8 @@ function reusePrevIfEqual({
|
|
|
406
377
|
}
|
|
407
378
|
|
|
408
379
|
// src/documentStore.ts
|
|
380
|
+
var import_evtmitter2 = require("evtmitter");
|
|
381
|
+
var import_react5 = require("evtmitter/react");
|
|
409
382
|
function newTSDFDocumentStore({
|
|
410
383
|
debugName,
|
|
411
384
|
fetchFn,
|
|
@@ -484,7 +457,7 @@ function newTSDFDocumentStore({
|
|
|
484
457
|
}
|
|
485
458
|
return { data: store.state.data, error: null };
|
|
486
459
|
}
|
|
487
|
-
const storeEvents = (0,
|
|
460
|
+
const storeEvents = (0, import_evtmitter2.evtmitter)();
|
|
488
461
|
let invalidationWasTriggered = false;
|
|
489
462
|
function invalidateData(priority = "highPriority") {
|
|
490
463
|
const currentInvalidationPriority = store.state.refetchOnMount ? fetchTypePriority[store.state.refetchOnMount] : -1;
|
|
@@ -503,7 +476,7 @@ function newTSDFDocumentStore({
|
|
|
503
476
|
returnIdleStatus = !!disabled,
|
|
504
477
|
ensureIsLoaded
|
|
505
478
|
} = {}) {
|
|
506
|
-
const storeStateSelector = (0,
|
|
479
|
+
const storeStateSelector = (0, import_react4.useCallback)(
|
|
507
480
|
(state) => {
|
|
508
481
|
const { error } = state;
|
|
509
482
|
const data = selector ? selector(state.data) : state.data;
|
|
@@ -526,14 +499,14 @@ function newTSDFDocumentStore({
|
|
|
526
499
|
const storeState = store.useSelector(storeStateSelector, {
|
|
527
500
|
useExternalDeps: true
|
|
528
501
|
});
|
|
529
|
-
|
|
502
|
+
(0, import_react5.useOnEvtmitterEvent)(storeEvents, "invalidateData", (priority) => {
|
|
530
503
|
if (!invalidationWasTriggered) {
|
|
531
504
|
store.setKey("refetchOnMount", false);
|
|
532
505
|
scheduleFetch(priority);
|
|
533
506
|
invalidationWasTriggered = true;
|
|
534
507
|
}
|
|
535
508
|
});
|
|
536
|
-
(0,
|
|
509
|
+
(0, import_react4.useEffect)(() => {
|
|
537
510
|
if (disabled)
|
|
538
511
|
return;
|
|
539
512
|
const fetchType = store.state.refetchOnMount || "lowPriority";
|
|
@@ -588,8 +561,10 @@ function newTSDFDocumentStore({
|
|
|
588
561
|
}
|
|
589
562
|
|
|
590
563
|
// src/collectionStore.ts
|
|
591
|
-
var
|
|
592
|
-
var
|
|
564
|
+
var import_evtmitter3 = require("evtmitter");
|
|
565
|
+
var import_react6 = require("evtmitter/react");
|
|
566
|
+
var import_json = require("klona/json");
|
|
567
|
+
var import_react7 = require("react");
|
|
593
568
|
var import_t_state4 = require("t-state");
|
|
594
569
|
|
|
595
570
|
// src/collectionFetchOrquestrator.ts
|
|
@@ -639,7 +614,6 @@ function orderedProps(obj) {
|
|
|
639
614
|
}
|
|
640
615
|
|
|
641
616
|
// src/collectionStore.ts
|
|
642
|
-
var import_json = require("klona/json");
|
|
643
617
|
function newTSDFCollectionStore({
|
|
644
618
|
debugName,
|
|
645
619
|
fetchFn,
|
|
@@ -784,7 +758,7 @@ function newTSDFCollectionStore({
|
|
|
784
758
|
return [getItemKey(params)];
|
|
785
759
|
}
|
|
786
760
|
}
|
|
787
|
-
const storeEvents = (0,
|
|
761
|
+
const storeEvents = (0, import_evtmitter3.evtmitter)();
|
|
788
762
|
const invalidationWasTriggered = /* @__PURE__ */ new Set();
|
|
789
763
|
function invalidateItem(itemPayload, priority = "highPriority") {
|
|
790
764
|
const itemsKey = getItemsKeyArray(itemPayload);
|
|
@@ -830,12 +804,12 @@ function newTSDFCollectionStore({
|
|
|
830
804
|
return { itemKey: getItemKey(payload), payload };
|
|
831
805
|
});
|
|
832
806
|
}, [queries]);
|
|
833
|
-
const dataSelector = (0,
|
|
807
|
+
const dataSelector = (0, import_react7.useCallback)((itemState) => {
|
|
834
808
|
if (selector)
|
|
835
809
|
return selector(itemState);
|
|
836
810
|
return itemState;
|
|
837
811
|
}, []);
|
|
838
|
-
const resultSelector = (0,
|
|
812
|
+
const resultSelector = (0, import_react7.useCallback)(
|
|
839
813
|
(state) => {
|
|
840
814
|
return queriesWithId.map(
|
|
841
815
|
({
|
|
@@ -890,7 +864,7 @@ function newTSDFCollectionStore({
|
|
|
890
864
|
equalityFn: import_t_state4.deepEqual,
|
|
891
865
|
useExternalDeps: true
|
|
892
866
|
});
|
|
893
|
-
|
|
867
|
+
(0, import_react6.useOnEvtmitterEvent)(storeEvents, "invalidateData", (event) => {
|
|
894
868
|
for (const { itemKey, payload } of queriesWithId) {
|
|
895
869
|
if (itemKey !== event.itemKey)
|
|
896
870
|
continue;
|
|
@@ -906,7 +880,7 @@ function newTSDFCollectionStore({
|
|
|
906
880
|
}
|
|
907
881
|
}
|
|
908
882
|
});
|
|
909
|
-
(0,
|
|
883
|
+
(0, import_react7.useEffect)(() => {
|
|
910
884
|
for (const { itemKey: itemId, payload } of queriesWithId) {
|
|
911
885
|
if (itemId) {
|
|
912
886
|
const itemState = getItemState(payload);
|
|
@@ -927,12 +901,12 @@ function newTSDFCollectionStore({
|
|
|
927
901
|
}
|
|
928
902
|
function useItem(payload, options = {}) {
|
|
929
903
|
const { selector, ensureIsLoaded } = options;
|
|
930
|
-
const query = (0,
|
|
904
|
+
const query = (0, import_react7.useMemo)(
|
|
931
905
|
() => payload === false || payload === null || payload === void 0 ? [] : [payload],
|
|
932
906
|
[payload]
|
|
933
907
|
);
|
|
934
908
|
const item = useMultipleItems(query, options);
|
|
935
|
-
const result = (0,
|
|
909
|
+
const result = (0, import_react7.useMemo)(
|
|
936
910
|
() => item[0] ?? {
|
|
937
911
|
payload: void 0,
|
|
938
912
|
data: selector ? selector(null) : null,
|
|
@@ -1047,10 +1021,11 @@ function newTSDFCollectionStore({
|
|
|
1047
1021
|
}
|
|
1048
1022
|
|
|
1049
1023
|
// src/listQueryStore.ts
|
|
1050
|
-
var
|
|
1051
|
-
var
|
|
1052
|
-
var import_t_state5 = require("t-state");
|
|
1024
|
+
var import_evtmitter4 = require("evtmitter");
|
|
1025
|
+
var import_react8 = require("evtmitter/react");
|
|
1053
1026
|
var import_json2 = require("klona/json");
|
|
1027
|
+
var import_react9 = require("react");
|
|
1028
|
+
var import_t_state5 = require("t-state");
|
|
1054
1029
|
|
|
1055
1030
|
// src/utils/findAndMap.ts
|
|
1056
1031
|
function findAndMap(arr, findFn) {
|
|
@@ -1349,7 +1324,7 @@ function newTSDFListQueryStore({
|
|
|
1349
1324
|
return [{ key: getQueryKey(payloads), payload: payloads }];
|
|
1350
1325
|
}
|
|
1351
1326
|
}
|
|
1352
|
-
const storeEvents = (0,
|
|
1327
|
+
const storeEvents = (0, import_evtmitter4.evtmitter)();
|
|
1353
1328
|
const queryInvalidationWasTriggered = /* @__PURE__ */ new Set();
|
|
1354
1329
|
function invalidateQuery(queryPayload, priority = "highPriority", ignoreInvalidationSync = false) {
|
|
1355
1330
|
const queriesKey = getQueriesKeyArray(queryPayload);
|
|
@@ -1415,8 +1390,8 @@ function newTSDFListQueryStore({
|
|
|
1415
1390
|
};
|
|
1416
1391
|
});
|
|
1417
1392
|
}, [queries]);
|
|
1418
|
-
const dataSelector = (0,
|
|
1419
|
-
const resultSelector = (0,
|
|
1393
|
+
const dataSelector = (0, import_react9.useCallback)(itemSelector, []);
|
|
1394
|
+
const resultSelector = (0, import_react9.useCallback)(
|
|
1420
1395
|
(state) => {
|
|
1421
1396
|
return queriesWithId.map(
|
|
1422
1397
|
({
|
|
@@ -1465,7 +1440,7 @@ function newTSDFListQueryStore({
|
|
|
1465
1440
|
equalityFn: import_t_state5.deepEqual,
|
|
1466
1441
|
useExternalDeps: true
|
|
1467
1442
|
});
|
|
1468
|
-
|
|
1443
|
+
(0, import_react8.useOnEvtmitterEvent)(storeEvents, "invalidateQuery", (event) => {
|
|
1469
1444
|
for (const { key, payload } of queriesWithId) {
|
|
1470
1445
|
if (key !== event.queryKey)
|
|
1471
1446
|
continue;
|
|
@@ -1482,7 +1457,7 @@ function newTSDFListQueryStore({
|
|
|
1482
1457
|
}
|
|
1483
1458
|
});
|
|
1484
1459
|
const loadSizeConst = useConst(() => loadSize);
|
|
1485
|
-
(0,
|
|
1460
|
+
(0, import_react9.useEffect)(() => {
|
|
1486
1461
|
for (const { key: itemId, payload: fetchParams } of queriesWithId) {
|
|
1487
1462
|
if (itemId) {
|
|
1488
1463
|
const itemState = getQueryState(fetchParams);
|
|
@@ -1503,12 +1478,12 @@ function newTSDFListQueryStore({
|
|
|
1503
1478
|
}
|
|
1504
1479
|
function useListQuery(payload, options = {}) {
|
|
1505
1480
|
const { ensureIsLoaded } = options;
|
|
1506
|
-
const query = (0,
|
|
1481
|
+
const query = (0, import_react9.useMemo)(
|
|
1507
1482
|
() => payload === false || payload === null || payload === void 0 ? [] : [payload],
|
|
1508
1483
|
[payload]
|
|
1509
1484
|
);
|
|
1510
1485
|
const queryResult = useMultipleListQueries(query, options);
|
|
1511
|
-
const result = (0,
|
|
1486
|
+
const result = (0, import_react9.useMemo)(
|
|
1512
1487
|
() => queryResult[0] ?? {
|
|
1513
1488
|
payload: void 0,
|
|
1514
1489
|
error: null,
|
|
@@ -1722,7 +1697,7 @@ function newTSDFListQueryStore({
|
|
|
1722
1697
|
disableRefetchOnMount,
|
|
1723
1698
|
loadFromStateOnly
|
|
1724
1699
|
} = {}) {
|
|
1725
|
-
const dataSelector = (0,
|
|
1700
|
+
const dataSelector = (0, import_react9.useCallback)(selector, []);
|
|
1726
1701
|
const memoizedItemKeys = useDeepMemo(
|
|
1727
1702
|
() => itemsPayload_.map(
|
|
1728
1703
|
(itemPayload) => ({
|
|
@@ -1732,7 +1707,7 @@ function newTSDFListQueryStore({
|
|
|
1732
1707
|
),
|
|
1733
1708
|
[itemsPayload_]
|
|
1734
1709
|
);
|
|
1735
|
-
const resultSelector = (0,
|
|
1710
|
+
const resultSelector = (0, import_react9.useCallback)(
|
|
1736
1711
|
(state) => {
|
|
1737
1712
|
return memoizedItemKeys.map(
|
|
1738
1713
|
({
|
|
@@ -1784,7 +1759,7 @@ function newTSDFListQueryStore({
|
|
|
1784
1759
|
equalityFn: import_t_state5.deepEqual,
|
|
1785
1760
|
useExternalDeps: true
|
|
1786
1761
|
});
|
|
1787
|
-
|
|
1762
|
+
(0, import_react8.useOnEvtmitterEvent)(storeEvents, "invalidateItem", (event) => {
|
|
1788
1763
|
if (loadFromStateOnly)
|
|
1789
1764
|
return;
|
|
1790
1765
|
for (const { payload, itemKey } of memoizedItemKeys) {
|
|
@@ -1802,7 +1777,7 @@ function newTSDFListQueryStore({
|
|
|
1802
1777
|
}
|
|
1803
1778
|
}
|
|
1804
1779
|
});
|
|
1805
|
-
(0,
|
|
1780
|
+
(0, import_react9.useEffect)(() => {
|
|
1806
1781
|
if (loadFromStateOnly)
|
|
1807
1782
|
return;
|
|
1808
1783
|
for (const { payload, itemKey } of memoizedItemKeys) {
|
|
@@ -1825,16 +1800,16 @@ function newTSDFListQueryStore({
|
|
|
1825
1800
|
}
|
|
1826
1801
|
function useItem(itemPayload, options = {}) {
|
|
1827
1802
|
const { ensureIsLoaded } = options;
|
|
1828
|
-
const query = (0,
|
|
1803
|
+
const query = (0, import_react9.useMemo)(
|
|
1829
1804
|
() => itemPayload === false || itemPayload === null || itemPayload === void 0 ? [] : [itemPayload],
|
|
1830
1805
|
[itemPayload]
|
|
1831
1806
|
);
|
|
1832
1807
|
const queryResult = useMultipleItems(query, options);
|
|
1833
|
-
const memoizedSelector = (0,
|
|
1808
|
+
const memoizedSelector = (0, import_react9.useCallback)(
|
|
1834
1809
|
options.selector ?? defaultItemDataSelector,
|
|
1835
1810
|
[]
|
|
1836
1811
|
);
|
|
1837
|
-
const result = (0,
|
|
1812
|
+
const result = (0, import_react9.useMemo)(
|
|
1838
1813
|
() => queryResult[0] ?? {
|
|
1839
1814
|
error: null,
|
|
1840
1815
|
isLoading: false,
|
package/dist/main.d.ts
CHANGED
|
@@ -113,6 +113,7 @@ declare function newTSDFCollectionStore<ItemState extends ValidStoreState, NErro
|
|
|
113
113
|
returnRefetchingStatus?: boolean | undefined;
|
|
114
114
|
disableRefetchOnMount?: boolean | undefined;
|
|
115
115
|
ensureIsLoaded?: boolean | undefined;
|
|
116
|
+
returnIdleStatus?: boolean | undefined;
|
|
116
117
|
}) => TSFDUseCollectionItemReturn<Selected_1, ItemPayload, NError>;
|
|
117
118
|
getItemKey: (params: ItemPayload) => string;
|
|
118
119
|
getItemState: {
|
package/dist/main.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// src/documentStore.ts
|
|
2
2
|
import { produce } from "immer";
|
|
3
|
-
import mitt2 from "mitt";
|
|
4
3
|
import { useCallback, useEffect as useEffect2 } from "react";
|
|
5
4
|
import { Store, useSubscribeToStore } from "t-state";
|
|
6
5
|
|
|
@@ -115,15 +114,16 @@ function createFetchOrquestrator({
|
|
|
115
114
|
}
|
|
116
115
|
function scheduleFetch(fetchType, params) {
|
|
117
116
|
const startTime = Date.now();
|
|
118
|
-
|
|
117
|
+
const fetchTypeToUse = !lastFetchStartTime ? "highPriority" : fetchType;
|
|
118
|
+
if (dynamicRealtimeThrottleMs && fetchTypeToUse === "realtimeUpdate") {
|
|
119
119
|
if (scheduleRTU(startTime, params)) {
|
|
120
120
|
return "rt-scheduled";
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
if (shouldSkipFetch(
|
|
123
|
+
if (shouldSkipFetch(fetchTypeToUse, startTime)) {
|
|
124
124
|
return "skipped";
|
|
125
125
|
}
|
|
126
|
-
if (shouldScheduleFetch(
|
|
126
|
+
if (shouldScheduleFetch(fetchTypeToUse, params)) {
|
|
127
127
|
return "scheduled";
|
|
128
128
|
}
|
|
129
129
|
startFetch(params, startTime);
|
|
@@ -252,7 +252,8 @@ var fetchTypePriority = {
|
|
|
252
252
|
};
|
|
253
253
|
|
|
254
254
|
// src/useEnsureIsLoaded.ts
|
|
255
|
-
import
|
|
255
|
+
import { evtmitter } from "evtmitter";
|
|
256
|
+
import { useOnEvtmitterEvent } from "evtmitter/react";
|
|
256
257
|
import { useMemo as useMemo2, useState } from "react";
|
|
257
258
|
|
|
258
259
|
// src/utils/hooks.ts
|
|
@@ -270,26 +271,6 @@ function useDeepCompareMemoize(value, equalityFn = deepEqual) {
|
|
|
270
271
|
function useDeepMemo(callback, deeps) {
|
|
271
272
|
return useMemo(callback, useDeepCompareMemoize(deeps));
|
|
272
273
|
}
|
|
273
|
-
function useLatestValue(value) {
|
|
274
|
-
const ref = useRef({ insideEffect: value, insideMemo: value });
|
|
275
|
-
ref.current.insideMemo = value;
|
|
276
|
-
useLayoutEffect(() => {
|
|
277
|
-
ref.current.insideEffect = value;
|
|
278
|
-
});
|
|
279
|
-
return ref.current;
|
|
280
|
-
}
|
|
281
|
-
function useOnMittEvent(mitt5, event, callback) {
|
|
282
|
-
const latestCallback = useLatestValue(callback);
|
|
283
|
-
useLayoutEffect(() => {
|
|
284
|
-
const cb = (payload) => {
|
|
285
|
-
latestCallback.insideEffect(payload);
|
|
286
|
-
};
|
|
287
|
-
mitt5.on(event, cb);
|
|
288
|
-
return () => {
|
|
289
|
-
mitt5.off(event, cb);
|
|
290
|
-
};
|
|
291
|
-
}, [mitt5, event, latestCallback]);
|
|
292
|
-
}
|
|
293
274
|
function usePrevious(value, initial) {
|
|
294
275
|
const ref = useRef(initial);
|
|
295
276
|
useEffect(() => {
|
|
@@ -320,7 +301,7 @@ function useConst(getValue) {
|
|
|
320
301
|
|
|
321
302
|
// src/useEnsureIsLoaded.ts
|
|
322
303
|
function useEnsureIsLoaded(ensureIsLoaded, enabled, forceFetch) {
|
|
323
|
-
const isLoadedEvtEmitter = useConst(() =>
|
|
304
|
+
const isLoadedEvtEmitter = useConst(() => evtmitter());
|
|
324
305
|
const [isForceLoading, setIsForceLoading] = useState(true);
|
|
325
306
|
useOnChange(
|
|
326
307
|
ensureIsLoaded && isForceLoading && enabled,
|
|
@@ -331,7 +312,7 @@ function useEnsureIsLoaded(ensureIsLoaded, enabled, forceFetch) {
|
|
|
331
312
|
},
|
|
332
313
|
{ callOnMount: true }
|
|
333
314
|
);
|
|
334
|
-
|
|
315
|
+
useOnEvtmitterEvent(isLoadedEvtEmitter, "isLoaded", (isLoaded) => {
|
|
335
316
|
if (ensureIsLoaded && enabled && isLoaded) {
|
|
336
317
|
setIsForceLoading(false);
|
|
337
318
|
}
|
|
@@ -352,7 +333,7 @@ function useEnsureIsLoaded(ensureIsLoaded, enabled, forceFetch) {
|
|
|
352
333
|
return [useModifyResult, isLoadedEvtEmitter.emit];
|
|
353
334
|
}
|
|
354
335
|
|
|
355
|
-
// src/utils/
|
|
336
|
+
// src/utils/reusePrevIfEqual.ts
|
|
356
337
|
import { deepEqual as deepEqual2 } from "t-state";
|
|
357
338
|
function reusePrevIfEqual({
|
|
358
339
|
prev,
|
|
@@ -368,6 +349,8 @@ function reusePrevIfEqual({
|
|
|
368
349
|
}
|
|
369
350
|
|
|
370
351
|
// src/documentStore.ts
|
|
352
|
+
import { evtmitter as evtmitter2 } from "evtmitter";
|
|
353
|
+
import { useOnEvtmitterEvent as useOnEvtmitterEvent2 } from "evtmitter/react";
|
|
371
354
|
function newTSDFDocumentStore({
|
|
372
355
|
debugName,
|
|
373
356
|
fetchFn,
|
|
@@ -446,7 +429,7 @@ function newTSDFDocumentStore({
|
|
|
446
429
|
}
|
|
447
430
|
return { data: store.state.data, error: null };
|
|
448
431
|
}
|
|
449
|
-
const storeEvents =
|
|
432
|
+
const storeEvents = evtmitter2();
|
|
450
433
|
let invalidationWasTriggered = false;
|
|
451
434
|
function invalidateData(priority = "highPriority") {
|
|
452
435
|
const currentInvalidationPriority = store.state.refetchOnMount ? fetchTypePriority[store.state.refetchOnMount] : -1;
|
|
@@ -488,7 +471,7 @@ function newTSDFDocumentStore({
|
|
|
488
471
|
const storeState = store.useSelector(storeStateSelector, {
|
|
489
472
|
useExternalDeps: true
|
|
490
473
|
});
|
|
491
|
-
|
|
474
|
+
useOnEvtmitterEvent2(storeEvents, "invalidateData", (priority) => {
|
|
492
475
|
if (!invalidationWasTriggered) {
|
|
493
476
|
store.setKey("refetchOnMount", false);
|
|
494
477
|
scheduleFetch(priority);
|
|
@@ -550,9 +533,11 @@ function newTSDFDocumentStore({
|
|
|
550
533
|
}
|
|
551
534
|
|
|
552
535
|
// src/collectionStore.ts
|
|
553
|
-
import
|
|
536
|
+
import { evtmitter as evtmitter3 } from "evtmitter";
|
|
537
|
+
import { useOnEvtmitterEvent as useOnEvtmitterEvent3 } from "evtmitter/react";
|
|
538
|
+
import { klona } from "klona/json";
|
|
554
539
|
import { useCallback as useCallback2, useEffect as useEffect3, useMemo as useMemo3 } from "react";
|
|
555
|
-
import {
|
|
540
|
+
import { Store as Store2, deepEqual as deepEqual3, useSubscribeToStore as useSubscribeToStore2 } from "t-state";
|
|
556
541
|
|
|
557
542
|
// src/collectionFetchOrquestrator.ts
|
|
558
543
|
function createCollectionFetchOrquestrator(props) {
|
|
@@ -601,7 +586,6 @@ function orderedProps(obj) {
|
|
|
601
586
|
}
|
|
602
587
|
|
|
603
588
|
// src/collectionStore.ts
|
|
604
|
-
import { klona } from "klona/json";
|
|
605
589
|
function newTSDFCollectionStore({
|
|
606
590
|
debugName,
|
|
607
591
|
fetchFn,
|
|
@@ -746,7 +730,7 @@ function newTSDFCollectionStore({
|
|
|
746
730
|
return [getItemKey(params)];
|
|
747
731
|
}
|
|
748
732
|
}
|
|
749
|
-
const storeEvents =
|
|
733
|
+
const storeEvents = evtmitter3();
|
|
750
734
|
const invalidationWasTriggered = /* @__PURE__ */ new Set();
|
|
751
735
|
function invalidateItem(itemPayload, priority = "highPriority") {
|
|
752
736
|
const itemsKey = getItemsKeyArray(itemPayload);
|
|
@@ -852,7 +836,7 @@ function newTSDFCollectionStore({
|
|
|
852
836
|
equalityFn: deepEqual3,
|
|
853
837
|
useExternalDeps: true
|
|
854
838
|
});
|
|
855
|
-
|
|
839
|
+
useOnEvtmitterEvent3(storeEvents, "invalidateData", (event) => {
|
|
856
840
|
for (const { itemKey, payload } of queriesWithId) {
|
|
857
841
|
if (itemKey !== event.itemKey)
|
|
858
842
|
continue;
|
|
@@ -1009,10 +993,11 @@ function newTSDFCollectionStore({
|
|
|
1009
993
|
}
|
|
1010
994
|
|
|
1011
995
|
// src/listQueryStore.ts
|
|
1012
|
-
import
|
|
1013
|
-
import {
|
|
1014
|
-
import { deepEqual as deepEqual4, Store as Store3, useSubscribeToStore as useSubscribeToStore3 } from "t-state";
|
|
996
|
+
import { evtmitter as evtmitter4 } from "evtmitter";
|
|
997
|
+
import { useOnEvtmitterEvent as useOnEvtmitterEvent4 } from "evtmitter/react";
|
|
1015
998
|
import { klona as klona2 } from "klona/json";
|
|
999
|
+
import { useCallback as useCallback3, useEffect as useEffect4, useMemo as useMemo4 } from "react";
|
|
1000
|
+
import { Store as Store3, deepEqual as deepEqual4, useSubscribeToStore as useSubscribeToStore3 } from "t-state";
|
|
1016
1001
|
|
|
1017
1002
|
// src/utils/findAndMap.ts
|
|
1018
1003
|
function findAndMap(arr, findFn) {
|
|
@@ -1311,7 +1296,7 @@ function newTSDFListQueryStore({
|
|
|
1311
1296
|
return [{ key: getQueryKey(payloads), payload: payloads }];
|
|
1312
1297
|
}
|
|
1313
1298
|
}
|
|
1314
|
-
const storeEvents =
|
|
1299
|
+
const storeEvents = evtmitter4();
|
|
1315
1300
|
const queryInvalidationWasTriggered = /* @__PURE__ */ new Set();
|
|
1316
1301
|
function invalidateQuery(queryPayload, priority = "highPriority", ignoreInvalidationSync = false) {
|
|
1317
1302
|
const queriesKey = getQueriesKeyArray(queryPayload);
|
|
@@ -1427,7 +1412,7 @@ function newTSDFListQueryStore({
|
|
|
1427
1412
|
equalityFn: deepEqual4,
|
|
1428
1413
|
useExternalDeps: true
|
|
1429
1414
|
});
|
|
1430
|
-
|
|
1415
|
+
useOnEvtmitterEvent4(storeEvents, "invalidateQuery", (event) => {
|
|
1431
1416
|
for (const { key, payload } of queriesWithId) {
|
|
1432
1417
|
if (key !== event.queryKey)
|
|
1433
1418
|
continue;
|
|
@@ -1746,7 +1731,7 @@ function newTSDFListQueryStore({
|
|
|
1746
1731
|
equalityFn: deepEqual4,
|
|
1747
1732
|
useExternalDeps: true
|
|
1748
1733
|
});
|
|
1749
|
-
|
|
1734
|
+
useOnEvtmitterEvent4(storeEvents, "invalidateItem", (event) => {
|
|
1750
1735
|
if (loadFromStateOnly)
|
|
1751
1736
|
return;
|
|
1752
1737
|
for (const { payload, itemKey } of memoizedItemKeys) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdf",
|
|
3
|
-
"version": "11.1.
|
|
3
|
+
"version": "11.1.5",
|
|
4
4
|
"description": "A data fetching solution based on t-state",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Lucas Santos",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"vitest": "^0.30.1"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
+
"evtmitter": "^0.3.1",
|
|
67
68
|
"immer": "^9.0.17",
|
|
68
69
|
"klona": "^2.0.6",
|
|
69
|
-
"mitt": "^3.0.0",
|
|
70
70
|
"t-state": "^8.3.0"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|