tsdf 15.1.0 → 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 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
- isLoading,
2410
+ listIsLoading,
2410
2411
  isRefetching,
2411
- isNotFound,
2412
+ itemExists,
2412
2413
  loadItemFallback,
2413
2414
  itemId
2414
2415
  }) {
2415
- const [willBeRefetched, setWillBeRefetched] = (0, import_react11.useState)(isNotFound);
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 (isNotFound && !isRefetching && !willBeRefetched && !ignoreSetWillBeRefetched.current && itemId && !itemWasRefetched.has(itemId)) {
2421
+ if (itemExists && !isRefetching && !willBeRefetched && !ignoreSetWillBeRefetched.current && itemId && !itemWasRefetched.has(itemId)) {
2421
2422
  setWillBeRefetched(true);
2422
2423
  }
2423
- const latestIsLoadingOrRefetching = useLatestValue(isLoading || isRefetching);
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 isLoading || isNotFound && (isRefetching || !!willBeRefetched);
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({ 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,21 +2376,23 @@ 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 [willBeRefetched, setWillBeRefetched] = useState2(isNotFound);
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 (isNotFound && !isRefetching && !willBeRefetched && !ignoreSetWillBeRefetched.current && itemId && !itemWasRefetched.has(itemId)) {
2390
+ if (itemExists && !isRefetching && !willBeRefetched && !ignoreSetWillBeRefetched.current && itemId && !itemWasRefetched.has(itemId)) {
2391
2391
  setWillBeRefetched(true);
2392
2392
  }
2393
- const latestIsLoadingOrRefetching = useLatestValue(isLoading || isRefetching);
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 isLoading || isNotFound && (isRefetching || !!willBeRefetched);
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": "15.1.0",
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",
@@ -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",