@t8/react-pending 1.0.21 → 1.0.23

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.
@@ -0,0 +1,4 @@
1
+ export * from "./src/PendingState.ts";
2
+ export * from "./src/PendingStateContext.ts";
3
+ export * from "./src/PendingStateProvider.tsx";
4
+ export * from "./src/usePendingState.ts";
@@ -0,0 +1,6 @@
1
+ export type PendingState = {
2
+ initialized?: boolean | undefined;
3
+ complete?: boolean | undefined;
4
+ time?: number | undefined;
5
+ error?: unknown;
6
+ };
@@ -0,0 +1,3 @@
1
+ import type { Store } from "@t8/react-store";
2
+ import type { PendingState } from "./PendingState.ts";
3
+ export declare const PendingStateContext: import("react").Context<Map<string, Store<PendingState>>>;
@@ -0,0 +1,8 @@
1
+ import { Store } from "@t8/react-store";
2
+ import { type ReactNode } from "react";
3
+ import type { PendingState } from "./PendingState.ts";
4
+ export type PendingStateProviderProps = {
5
+ value?: Record<string, PendingState> | Map<string, Store<PendingState>> | null | undefined;
6
+ children?: ReactNode;
7
+ };
8
+ export declare const PendingStateProvider: ({ value, children, }: PendingStateProviderProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,23 @@
1
+ import { type SetStoreState, Store } from "@t8/react-store";
2
+ import type { PendingState } from "./PendingState.ts";
3
+ export type WithStateOptions = {
4
+ silent?: boolean;
5
+ throws?: boolean;
6
+ delay?: number;
7
+ };
8
+ /**
9
+ * Returns an array containing `[state, withState, setState]`:
10
+ * - `state` reflects the state of a value passed to `withState()`;
11
+ * - `withState(value, [options])` enables the tracking of the state
12
+ * of `value`; setting the options to `{silent: true}` prevents
13
+ * `withState()` from updating the state while `value` is pending
14
+ * (e.g. for background or optimistic updates);
15
+ * - `setState()` to directly update the state.
16
+ */
17
+ export declare function usePendingState(
18
+ /**
19
+ * A unique store key or a store. Providing a store key or a
20
+ * shared store allows to share the state across multiple
21
+ * components.
22
+ */
23
+ store?: string | Store<PendingState> | null): [PendingState, <T>(value: T) => T, SetStoreState<PendingState>];
package/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from "./src/PendingState";
2
- export * from "./src/PendingStateContext";
3
- export * from "./src/PendingStateProvider";
4
- export * from "./src/usePendingState";
1
+ export * from "./src/PendingState.ts";
2
+ export * from "./src/PendingStateContext.ts";
3
+ export * from "./src/PendingStateProvider.tsx";
4
+ export * from "./src/usePendingState.ts";
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@t8/react-pending",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "description": "Concise async action state tracking for React apps",
5
5
  "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
6
7
  "type": "module",
7
8
  "scripts": {
8
- "build": "npx npm-run-all clean compile",
9
+ "build": "npx npm-run-all clean compile types",
9
10
  "clean": "node -e \"require('node:fs').rmSync('dist', { force: true, recursive: true });\"",
10
11
  "compile": "npx esbuild index.ts --bundle --outdir=dist --platform=neutral --external:react",
11
12
  "demo": "npx @t8/serve 3000 * tests/async_status -b src/index.tsx",
@@ -13,7 +14,8 @@
13
14
  "preversion": "npx npm-run-all typecheck shape build test",
14
15
  "shape": "npx codeshape",
15
16
  "test": "npx playwright test --project=chromium",
16
- "typecheck": "tsc --noEmit"
17
+ "typecheck": "tsc --noEmit",
18
+ "types": "tsc -p tsconfig.build.json"
17
19
  },
18
20
  "author": "axtk",
19
21
  "license": "MIT",
@@ -32,7 +34,7 @@
32
34
  },
33
35
  "devDependencies": {
34
36
  "@playwright/test": "^1.56.0",
35
- "@t8/serve": "^0.1.30",
37
+ "@t8/serve": "^0.1.35",
36
38
  "@types/node": "^24.5.2",
37
39
  "@types/react": "^19.1.10",
38
40
  "@types/react-dom": "^19.1.9",
@@ -40,6 +42,6 @@
40
42
  "typescript": "^5.9.3"
41
43
  },
42
44
  "dependencies": {
43
- "@t8/react-store": "^1.0.31"
45
+ "@t8/react-store": "^1.0.34"
44
46
  }
45
47
  }
@@ -1,6 +1,6 @@
1
1
  import type { Store } from "@t8/react-store";
2
2
  import { createContext } from "react";
3
- import type { PendingState } from "./PendingState";
3
+ import type { PendingState } from "./PendingState.ts";
4
4
 
5
5
  export const PendingStateContext = createContext(
6
6
  new Map<string, Store<PendingState>>(),
@@ -1,7 +1,7 @@
1
1
  import { Store } from "@t8/react-store";
2
2
  import { type ReactNode, useMemo, useRef } from "react";
3
- import type { PendingState } from "./PendingState";
4
- import { PendingStateContext } from "./PendingStateContext";
3
+ import type { PendingState } from "./PendingState.ts";
4
+ import { PendingStateContext } from "./PendingStateContext.ts";
5
5
 
6
6
  export type PendingStateProviderProps = {
7
7
  value?:
@@ -1,7 +1,7 @@
1
1
  import { isStore, type SetStoreState, Store, useStore } from "@t8/react-store";
2
2
  import { useCallback, useContext, useMemo, useRef, useState } from "react";
3
- import type { PendingState } from "./PendingState";
4
- import { PendingStateContext } from "./PendingStateContext";
3
+ import type { PendingState } from "./PendingState.ts";
4
+ import { PendingStateContext } from "./PendingStateContext.ts";
5
5
 
6
6
  function createState(
7
7
  initialized = false,
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": ["./index.ts", "./src"]
4
+ }
package/tsconfig.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
- "include": ["index.ts", "playwright.config.ts", "src", "tests"],
2
+ "include": ["./index.ts", "./playwright.config.ts", "./src", "./tests"],
3
3
  "compilerOptions": {
4
+ "declaration": true,
5
+ "emitDeclarationOnly": true,
4
6
  "lib": ["ESNext", "DOM"],
5
- "target": "ESNext",
7
+ "target": "esnext",
6
8
  "outDir": "dist",
7
- "moduleResolution": "node",
9
+ "module": "nodenext",
10
+ "moduleResolution": "nodenext",
11
+ "allowImportingTsExtensions": true,
8
12
  "jsx": "react-jsx",
9
13
  "strict": true,
10
14
  "noUnusedLocals": true,