tsdf 15.1.0 → 16.0.1

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 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,12 +2407,13 @@ function useTimeout(ms) {
2406
2407
 
2407
2408
  // src/useListItemIsLoading.ts
2408
2409
  function useListItemIsLoading({
2409
- isLoading,
2410
+ listIsLoading,
2410
2411
  isRefetching,
2411
- isNotFound,
2412
+ itemExists,
2412
2413
  loadItemFallback,
2413
2414
  itemId
2414
2415
  }) {
2416
+ const isNotFound = !itemExists;
2415
2417
  const [willBeRefetched, setWillBeRefetched] = (0, import_react11.useState)(isNotFound);
2416
2418
  const resetWillBeRefechedTimeout = useTimeout(1e3);
2417
2419
  const callFallbackLoadItemTimeout = useTimeout(100);
@@ -2420,7 +2422,9 @@ function useListItemIsLoading({
2420
2422
  if (isNotFound && !isRefetching && !willBeRefetched && !ignoreSetWillBeRefetched.current && itemId && !itemWasRefetched.has(itemId)) {
2421
2423
  setWillBeRefetched(true);
2422
2424
  }
2423
- const latestIsLoadingOrRefetching = useLatestValue(isLoading || isRefetching);
2425
+ const latestIsLoadingOrRefetching = useLatestValue(
2426
+ listIsLoading || isRefetching
2427
+ );
2424
2428
  const latestLoadItemFallback = useLatestValue(loadItemFallback);
2425
2429
  (0, import_react11.useEffect)(() => {
2426
2430
  if (isRefetching) {
@@ -2464,7 +2468,30 @@ function useListItemIsLoading({
2464
2468
  latestLoadItemFallback,
2465
2469
  callFallbackLoadItemTimeout
2466
2470
  ]);
2467
- return isLoading || isNotFound && (isRefetching || !!willBeRefetched);
2471
+ return listIsLoading || isNotFound && (isRefetching || !!willBeRefetched);
2472
+ }
2473
+
2474
+ // src/useListItemIsDeleted.ts
2475
+ var import_react12 = require("react");
2476
+ function useListItemIsDeleted({
2477
+ itemExists,
2478
+ listIsLoading,
2479
+ onDelete,
2480
+ itemId
2481
+ }) {
2482
+ const [isDeleted, setIsDeleted] = (0, import_react12.useState)();
2483
+ useOnChange({ itemExists, itemId }, ({ current, prev }) => {
2484
+ if (current.itemId !== itemId)
2485
+ return;
2486
+ if (listIsLoading || !prev)
2487
+ return;
2488
+ const wasItemDeleted = !current.itemExists && !!prev.itemExists;
2489
+ if (wasItemDeleted) {
2490
+ onDelete?.();
2491
+ setIsDeleted(itemId);
2492
+ }
2493
+ });
2494
+ return isDeleted === itemId;
2468
2495
  }
2469
2496
  // Annotate the CommonJS export names for ESM import in node:
2470
2497
  0 && (module.exports = {
@@ -2472,5 +2499,6 @@ function useListItemIsLoading({
2472
2499
  newTSDFCollectionStore,
2473
2500
  newTSDFDocumentStore,
2474
2501
  newTSDFListQueryStore,
2502
+ useListItemIsDeleted,
2475
2503
  useListItemIsLoading
2476
2504
  });
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({ isLoading, isRefetching, isNotFound, loadItemFallback, itemId, }: {
380
+ declare function useListItemIsLoading({ listIsLoading, isRefetching, itemExists, loadItemFallback, itemId, }: {
381
381
  itemId: string | null | false;
382
382
  isRefetching: boolean;
383
- isLoading: boolean;
384
- isNotFound: boolean;
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
- 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, useListItemIsLoading };
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({ isLoading, isRefetching, isNotFound, loadItemFallback, itemId, }: {
380
+ declare function useListItemIsLoading({ listIsLoading, isRefetching, itemExists, loadItemFallback, itemId, }: {
381
381
  itemId: string | null | false;
382
382
  isRefetching: boolean;
383
- isLoading: boolean;
384
- isNotFound: boolean;
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
- 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, useListItemIsLoading };
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,12 +2376,13 @@ function useTimeout(ms) {
2376
2376
 
2377
2377
  // src/useListItemIsLoading.ts
2378
2378
  function useListItemIsLoading({
2379
- isLoading,
2379
+ listIsLoading,
2380
2380
  isRefetching,
2381
- isNotFound,
2381
+ itemExists,
2382
2382
  loadItemFallback,
2383
2383
  itemId
2384
2384
  }) {
2385
+ const isNotFound = !itemExists;
2385
2386
  const [willBeRefetched, setWillBeRefetched] = useState2(isNotFound);
2386
2387
  const resetWillBeRefechedTimeout = useTimeout(1e3);
2387
2388
  const callFallbackLoadItemTimeout = useTimeout(100);
@@ -2390,7 +2391,9 @@ function useListItemIsLoading({
2390
2391
  if (isNotFound && !isRefetching && !willBeRefetched && !ignoreSetWillBeRefetched.current && itemId && !itemWasRefetched.has(itemId)) {
2391
2392
  setWillBeRefetched(true);
2392
2393
  }
2393
- const latestIsLoadingOrRefetching = useLatestValue(isLoading || isRefetching);
2394
+ const latestIsLoadingOrRefetching = useLatestValue(
2395
+ listIsLoading || isRefetching
2396
+ );
2394
2397
  const latestLoadItemFallback = useLatestValue(loadItemFallback);
2395
2398
  useEffect6(() => {
2396
2399
  if (isRefetching) {
@@ -2434,12 +2437,36 @@ function useListItemIsLoading({
2434
2437
  latestLoadItemFallback,
2435
2438
  callFallbackLoadItemTimeout
2436
2439
  ]);
2437
- return isLoading || isNotFound && (isRefetching || !!willBeRefetched);
2440
+ return listIsLoading || isNotFound && (isRefetching || !!willBeRefetched);
2441
+ }
2442
+
2443
+ // src/useListItemIsDeleted.ts
2444
+ import { useState as useState3 } from "react";
2445
+ function useListItemIsDeleted({
2446
+ itemExists,
2447
+ listIsLoading,
2448
+ onDelete,
2449
+ itemId
2450
+ }) {
2451
+ const [isDeleted, setIsDeleted] = useState3();
2452
+ useOnChange({ itemExists, itemId }, ({ current, prev }) => {
2453
+ if (current.itemId !== itemId)
2454
+ return;
2455
+ if (listIsLoading || !prev)
2456
+ return;
2457
+ const wasItemDeleted = !current.itemExists && !!prev.itemExists;
2458
+ if (wasItemDeleted) {
2459
+ onDelete?.();
2460
+ setIsDeleted(itemId);
2461
+ }
2462
+ });
2463
+ return isDeleted === itemId;
2438
2464
  }
2439
2465
  export {
2440
2466
  getCacheId,
2441
2467
  newTSDFCollectionStore,
2442
2468
  newTSDFDocumentStore,
2443
2469
  newTSDFListQueryStore,
2470
+ useListItemIsDeleted,
2444
2471
  useListItemIsLoading
2445
2472
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdf",
3
- "version": "15.1.0",
3
+ "version": "16.0.1",
4
4
  "description": "A data fetching solution based on t-state",
5
5
  "license": "MIT",
6
6
  "author": "Lucas Santos",
@@ -45,9 +45,9 @@
45
45
  "tiny-glob": "^0.2.9",
46
46
  "tsm": "^2.3.0",
47
47
  "tsup": "^7.2.0",
48
- "typescript": "^5.2.2",
49
- "vite": "^4.4.11",
50
- "vitest": "1.0.4"
48
+ "typescript": "^5.4.2",
49
+ "vite": "^5.1.5",
50
+ "vitest": "^1.3.1"
51
51
  },
52
52
  "dependencies": {
53
53
  "evtmitter": "^0.3.3",