tsdf 15.0.1 → 16.0.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 +33 -6
- package/dist/main.d.cts +13 -4
- package/dist/main.d.ts +13 -4
- package/dist/main.js +32 -6
- package/package.json +5 -6
package/dist/main.cjs
CHANGED
|
@@ -24,6 +24,7 @@ __export(main_exports, {
|
|
|
24
24
|
newTSDFCollectionStore: () => newTSDFCollectionStore,
|
|
25
25
|
newTSDFDocumentStore: () => newTSDFDocumentStore,
|
|
26
26
|
newTSDFListQueryStore: () => newTSDFListQueryStore,
|
|
27
|
+
useListItemIsDeleted: () => useListItemIsDeleted,
|
|
27
28
|
useListItemIsLoading: () => useListItemIsLoading
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(main_exports);
|
|
@@ -2406,21 +2407,23 @@ function useTimeout(ms) {
|
|
|
2406
2407
|
|
|
2407
2408
|
// src/useListItemIsLoading.ts
|
|
2408
2409
|
function useListItemIsLoading({
|
|
2409
|
-
|
|
2410
|
+
listIsLoading,
|
|
2410
2411
|
isRefetching,
|
|
2411
|
-
|
|
2412
|
+
itemExists,
|
|
2412
2413
|
loadItemFallback,
|
|
2413
2414
|
itemId
|
|
2414
2415
|
}) {
|
|
2415
|
-
const [willBeRefetched, setWillBeRefetched] = (0, import_react11.useState)(
|
|
2416
|
+
const [willBeRefetched, setWillBeRefetched] = (0, import_react11.useState)(itemExists);
|
|
2416
2417
|
const resetWillBeRefechedTimeout = useTimeout(1e3);
|
|
2417
2418
|
const callFallbackLoadItemTimeout = useTimeout(100);
|
|
2418
2419
|
const ignoreSetWillBeRefetched = (0, import_react11.useRef)(false);
|
|
2419
2420
|
const itemWasRefetched = useConst(() => /* @__PURE__ */ new Set());
|
|
2420
|
-
if (
|
|
2421
|
+
if (itemExists && !isRefetching && !willBeRefetched && !ignoreSetWillBeRefetched.current && itemId && !itemWasRefetched.has(itemId)) {
|
|
2421
2422
|
setWillBeRefetched(true);
|
|
2422
2423
|
}
|
|
2423
|
-
const latestIsLoadingOrRefetching = useLatestValue(
|
|
2424
|
+
const latestIsLoadingOrRefetching = useLatestValue(
|
|
2425
|
+
listIsLoading || isRefetching
|
|
2426
|
+
);
|
|
2424
2427
|
const latestLoadItemFallback = useLatestValue(loadItemFallback);
|
|
2425
2428
|
(0, import_react11.useEffect)(() => {
|
|
2426
2429
|
if (isRefetching) {
|
|
@@ -2464,7 +2467,30 @@ function useListItemIsLoading({
|
|
|
2464
2467
|
latestLoadItemFallback,
|
|
2465
2468
|
callFallbackLoadItemTimeout
|
|
2466
2469
|
]);
|
|
2467
|
-
return
|
|
2470
|
+
return listIsLoading || itemExists && (isRefetching || !!willBeRefetched);
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
// src/useListItemIsDeleted.ts
|
|
2474
|
+
var import_react12 = require("react");
|
|
2475
|
+
function useListItemIsDeleted({
|
|
2476
|
+
itemExists,
|
|
2477
|
+
listIsLoading,
|
|
2478
|
+
onDelete,
|
|
2479
|
+
itemId
|
|
2480
|
+
}) {
|
|
2481
|
+
const [isDeleted, setIsDeleted] = (0, import_react12.useState)();
|
|
2482
|
+
useOnChange({ itemExists, itemId }, ({ current, prev }) => {
|
|
2483
|
+
if (current.itemId !== itemId)
|
|
2484
|
+
return;
|
|
2485
|
+
if (listIsLoading || !prev)
|
|
2486
|
+
return;
|
|
2487
|
+
const wasItemDeleted = !current.itemExists && !!prev.itemExists;
|
|
2488
|
+
if (wasItemDeleted) {
|
|
2489
|
+
onDelete?.();
|
|
2490
|
+
setIsDeleted(itemId);
|
|
2491
|
+
}
|
|
2492
|
+
});
|
|
2493
|
+
return isDeleted === itemId;
|
|
2468
2494
|
}
|
|
2469
2495
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2470
2496
|
0 && (module.exports = {
|
|
@@ -2472,5 +2498,6 @@ function useListItemIsLoading({
|
|
|
2472
2498
|
newTSDFCollectionStore,
|
|
2473
2499
|
newTSDFDocumentStore,
|
|
2474
2500
|
newTSDFListQueryStore,
|
|
2501
|
+
useListItemIsDeleted,
|
|
2475
2502
|
useListItemIsLoading
|
|
2476
2503
|
});
|
package/dist/main.d.cts
CHANGED
|
@@ -377,14 +377,23 @@ type TSFDListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload
|
|
|
377
377
|
|
|
378
378
|
/** Use to detect if a item of a list may be loading in cases which there is no
|
|
379
379
|
* clear indication of the status of individual items, ex: an item in a document collection that is loaded on demand */
|
|
380
|
-
declare function useListItemIsLoading({
|
|
380
|
+
declare function useListItemIsLoading({ listIsLoading, isRefetching, itemExists, loadItemFallback, itemId, }: {
|
|
381
381
|
itemId: string | null | false;
|
|
382
382
|
isRefetching: boolean;
|
|
383
|
-
|
|
384
|
-
|
|
383
|
+
listIsLoading: boolean;
|
|
384
|
+
/** true if item exists in any condition, ex: if list is not loaded item not exists in memory yet */
|
|
385
|
+
itemExists: boolean;
|
|
385
386
|
loadItemFallback: () => void;
|
|
386
387
|
}): boolean;
|
|
387
388
|
|
|
388
389
|
declare function getCacheId(input: unknown, maxDepth?: number): string;
|
|
389
390
|
|
|
390
|
-
|
|
391
|
+
declare function useListItemIsDeleted({ itemExists, listIsLoading, onDelete, itemId, }: {
|
|
392
|
+
itemId: string;
|
|
393
|
+
/** true if item exists in any condition, ex: if list is not loaded item not exists in memory yet */
|
|
394
|
+
itemExists: boolean;
|
|
395
|
+
listIsLoading: boolean;
|
|
396
|
+
onDelete?: () => void;
|
|
397
|
+
}): boolean;
|
|
398
|
+
|
|
399
|
+
export { CollectionInitialStateItem, CollectionUseMultipleItemsQuery, FetchListFnReturn, FetchListFnReturnItem, ListQueryStoreInitialData, ListQueryUseMultipleItemsQuery, ListQueryUseMultipleListQueriesQuery, OnCollectionItemInvalidate, OnDocumentInvalidate, OnListQueryInvalidate, OnListQueryItemInvalidate, TSDFCollectionStore, TSDFDocumentStore, TSDFDocumentStoreState, TSDFItemQuery, TSDFStatus, TSDFUseDocumentReturn, TSFDCollectionItem, TSFDCollectionState, TSFDListQuery, TSFDListQueryState, TSFDListQueryStore, TSFDUseCollectionItemReturn, TSFDUseListItemReturn, TSFDUseListQueryReturn, ValidPayload, ValidStoreState, getCacheId, newTSDFCollectionStore, newTSDFDocumentStore, newTSDFListQueryStore, useListItemIsDeleted, useListItemIsLoading };
|
package/dist/main.d.ts
CHANGED
|
@@ -377,14 +377,23 @@ type TSFDListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload
|
|
|
377
377
|
|
|
378
378
|
/** Use to detect if a item of a list may be loading in cases which there is no
|
|
379
379
|
* clear indication of the status of individual items, ex: an item in a document collection that is loaded on demand */
|
|
380
|
-
declare function useListItemIsLoading({
|
|
380
|
+
declare function useListItemIsLoading({ listIsLoading, isRefetching, itemExists, loadItemFallback, itemId, }: {
|
|
381
381
|
itemId: string | null | false;
|
|
382
382
|
isRefetching: boolean;
|
|
383
|
-
|
|
384
|
-
|
|
383
|
+
listIsLoading: boolean;
|
|
384
|
+
/** true if item exists in any condition, ex: if list is not loaded item not exists in memory yet */
|
|
385
|
+
itemExists: boolean;
|
|
385
386
|
loadItemFallback: () => void;
|
|
386
387
|
}): boolean;
|
|
387
388
|
|
|
388
389
|
declare function getCacheId(input: unknown, maxDepth?: number): string;
|
|
389
390
|
|
|
390
|
-
|
|
391
|
+
declare function useListItemIsDeleted({ itemExists, listIsLoading, onDelete, itemId, }: {
|
|
392
|
+
itemId: string;
|
|
393
|
+
/** true if item exists in any condition, ex: if list is not loaded item not exists in memory yet */
|
|
394
|
+
itemExists: boolean;
|
|
395
|
+
listIsLoading: boolean;
|
|
396
|
+
onDelete?: () => void;
|
|
397
|
+
}): boolean;
|
|
398
|
+
|
|
399
|
+
export { CollectionInitialStateItem, CollectionUseMultipleItemsQuery, FetchListFnReturn, FetchListFnReturnItem, ListQueryStoreInitialData, ListQueryUseMultipleItemsQuery, ListQueryUseMultipleListQueriesQuery, OnCollectionItemInvalidate, OnDocumentInvalidate, OnListQueryInvalidate, OnListQueryItemInvalidate, TSDFCollectionStore, TSDFDocumentStore, TSDFDocumentStoreState, TSDFItemQuery, TSDFStatus, TSDFUseDocumentReturn, TSFDCollectionItem, TSFDCollectionState, TSFDListQuery, TSFDListQueryState, TSFDListQueryStore, TSFDUseCollectionItemReturn, TSFDUseListItemReturn, TSFDUseListQueryReturn, ValidPayload, ValidStoreState, getCacheId, newTSDFCollectionStore, newTSDFDocumentStore, newTSDFListQueryStore, useListItemIsDeleted, useListItemIsLoading };
|
package/dist/main.js
CHANGED
|
@@ -2376,21 +2376,23 @@ function useTimeout(ms) {
|
|
|
2376
2376
|
|
|
2377
2377
|
// src/useListItemIsLoading.ts
|
|
2378
2378
|
function useListItemIsLoading({
|
|
2379
|
-
|
|
2379
|
+
listIsLoading,
|
|
2380
2380
|
isRefetching,
|
|
2381
|
-
|
|
2381
|
+
itemExists,
|
|
2382
2382
|
loadItemFallback,
|
|
2383
2383
|
itemId
|
|
2384
2384
|
}) {
|
|
2385
|
-
const [willBeRefetched, setWillBeRefetched] = useState2(
|
|
2385
|
+
const [willBeRefetched, setWillBeRefetched] = useState2(itemExists);
|
|
2386
2386
|
const resetWillBeRefechedTimeout = useTimeout(1e3);
|
|
2387
2387
|
const callFallbackLoadItemTimeout = useTimeout(100);
|
|
2388
2388
|
const ignoreSetWillBeRefetched = useRef2(false);
|
|
2389
2389
|
const itemWasRefetched = useConst(() => /* @__PURE__ */ new Set());
|
|
2390
|
-
if (
|
|
2390
|
+
if (itemExists && !isRefetching && !willBeRefetched && !ignoreSetWillBeRefetched.current && itemId && !itemWasRefetched.has(itemId)) {
|
|
2391
2391
|
setWillBeRefetched(true);
|
|
2392
2392
|
}
|
|
2393
|
-
const latestIsLoadingOrRefetching = useLatestValue(
|
|
2393
|
+
const latestIsLoadingOrRefetching = useLatestValue(
|
|
2394
|
+
listIsLoading || isRefetching
|
|
2395
|
+
);
|
|
2394
2396
|
const latestLoadItemFallback = useLatestValue(loadItemFallback);
|
|
2395
2397
|
useEffect6(() => {
|
|
2396
2398
|
if (isRefetching) {
|
|
@@ -2434,12 +2436,36 @@ function useListItemIsLoading({
|
|
|
2434
2436
|
latestLoadItemFallback,
|
|
2435
2437
|
callFallbackLoadItemTimeout
|
|
2436
2438
|
]);
|
|
2437
|
-
return
|
|
2439
|
+
return listIsLoading || itemExists && (isRefetching || !!willBeRefetched);
|
|
2440
|
+
}
|
|
2441
|
+
|
|
2442
|
+
// src/useListItemIsDeleted.ts
|
|
2443
|
+
import { useState as useState3 } from "react";
|
|
2444
|
+
function useListItemIsDeleted({
|
|
2445
|
+
itemExists,
|
|
2446
|
+
listIsLoading,
|
|
2447
|
+
onDelete,
|
|
2448
|
+
itemId
|
|
2449
|
+
}) {
|
|
2450
|
+
const [isDeleted, setIsDeleted] = useState3();
|
|
2451
|
+
useOnChange({ itemExists, itemId }, ({ current, prev }) => {
|
|
2452
|
+
if (current.itemId !== itemId)
|
|
2453
|
+
return;
|
|
2454
|
+
if (listIsLoading || !prev)
|
|
2455
|
+
return;
|
|
2456
|
+
const wasItemDeleted = !current.itemExists && !!prev.itemExists;
|
|
2457
|
+
if (wasItemDeleted) {
|
|
2458
|
+
onDelete?.();
|
|
2459
|
+
setIsDeleted(itemId);
|
|
2460
|
+
}
|
|
2461
|
+
});
|
|
2462
|
+
return isDeleted === itemId;
|
|
2438
2463
|
}
|
|
2439
2464
|
export {
|
|
2440
2465
|
getCacheId,
|
|
2441
2466
|
newTSDFCollectionStore,
|
|
2442
2467
|
newTSDFDocumentStore,
|
|
2443
2468
|
newTSDFListQueryStore,
|
|
2469
|
+
useListItemIsDeleted,
|
|
2444
2470
|
useListItemIsLoading
|
|
2445
2471
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdf",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.0.0",
|
|
4
4
|
"description": "A data fetching solution based on t-state",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Lucas Santos",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"@types/node": "^20.8.4",
|
|
30
30
|
"@types/react": "^18.2.28",
|
|
31
31
|
"@types/react-dom": "^18.2.13",
|
|
32
|
-
"@types/testing-library__jest-dom": "^6.0.0",
|
|
33
32
|
"@typescript-eslint/eslint-plugin": "^6.7.5",
|
|
34
33
|
"@typescript-eslint/parser": "^6.7.5",
|
|
35
34
|
"@vitest/ui": "1.0.4",
|
|
@@ -46,15 +45,15 @@
|
|
|
46
45
|
"tiny-glob": "^0.2.9",
|
|
47
46
|
"tsm": "^2.3.0",
|
|
48
47
|
"tsup": "^7.2.0",
|
|
49
|
-
"typescript": "^5.
|
|
50
|
-
"vite": "^
|
|
51
|
-
"vitest": "1.
|
|
48
|
+
"typescript": "^5.4.2",
|
|
49
|
+
"vite": "^5.1.5",
|
|
50
|
+
"vitest": "^1.3.1"
|
|
52
51
|
},
|
|
53
52
|
"dependencies": {
|
|
54
53
|
"evtmitter": "^0.3.3",
|
|
55
54
|
"immer": "^10.0.3",
|
|
56
55
|
"klona": "^2.0.6",
|
|
57
|
-
"t-state": "^
|
|
56
|
+
"t-state": "^9.0.0"
|
|
58
57
|
},
|
|
59
58
|
"peerDependencies": {
|
|
60
59
|
"react": "^18.0.0",
|