@t8/react-pending 1.0.26 → 1.0.27

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/README.md CHANGED
@@ -83,7 +83,7 @@ Omit the custom string key parameter of `usePendingState()` to scope the pending
83
83
  + let [state, withState] = usePendingState(); // local
84
84
  ```
85
85
 
86
- ## Silent tracking of background and optimistic updates
86
+ ## Silent tracking of background actions and optimistic updates
87
87
 
88
88
  ```diff
89
89
  - withState(fetchItems())
@@ -96,7 +96,7 @@ Omit the custom string key parameter of `usePendingState()` to scope the pending
96
96
 
97
97
  ```diff
98
98
  - withState(fetchItems())
99
- + withState(fetchItems(), { delay: 500 })
99
+ + withState(fetchItems(), { delay: 500 }) // in milliseconds
100
100
  ```
101
101
 
102
102
  🔹 Use case: avoiding flashing a process indicator when the action is likely to complete by the end of a short delay.
@@ -121,7 +121,7 @@ Omit the custom string key parameter of `usePendingState()` to scope the pending
121
121
  + </PendingStateProvider>
122
122
  ```
123
123
 
124
- 🔹 `<PendingStateProvider>` creates an isolated instance of initial shared action state. Prime use cases: tests, SSR. It isn't required with client-side rendering, but it can be used to separate action states of larger self-contained portions of a web app.
124
+ 🔹 `<PendingStateProvider>` creates an isolated instance of initial shared action state. Prime use cases are SSR and tests. It isn't required with client-side rendering, but it can be used to separate action states of larger self-contained portions of a web app.
125
125
 
126
126
  ## Providing custom initial pending&nbsp;state
127
127
 
package/dist/index.d.ts CHANGED
@@ -14,26 +14,42 @@ export type PendingStateProviderProps = {
14
14
  };
15
15
  export declare const PendingStateProvider: ({ value, children, }: PendingStateProviderProps) => import("react/jsx-runtime").JSX.Element;
16
16
  export type WithStateOptions = {
17
+ /**
18
+ * Whether to track the action state silently (e.g. with a background
19
+ * action or an optimistic update).
20
+ *
21
+ * When set to `true`, the state's `complete` property doesn't switch
22
+ * to `false` in the pending state.
23
+ */
17
24
  silent?: boolean;
18
- throws?: boolean;
25
+ /**
26
+ * Delays switching the action state's `complete` property to `false`
27
+ * in the pending state by the given number of milliseconds.
28
+ *
29
+ * Use case: to avoid flashing a process indicator if the action is
30
+ * likely to complete by the end of a short delay.
31
+ */
19
32
  delay?: number;
33
+ /**
34
+ * Allows the async action to reject explicitly, along with exposing
35
+ * the action state's `error` property that goes by default.
36
+ */
37
+ throws?: boolean;
20
38
  };
21
39
  /**
22
- * Returns an array containing `[state, withState, setState]`:
23
- * - `state` reflects the state of a value passed to `withState()`;
24
- * - `withState(value, [options])` enables the tracking of the state
25
- * of `value`; setting the options to `{silent: true}` prevents
26
- * `withState()` from updating the state while `value` is pending
27
- * (e.g. for background or optimistic updates);
28
- * - `setState()` to directly update the state.
29
- */
30
- export declare function usePendingState(
31
- /**
32
- * A unique store key or a store. Providing a store key or a
33
- * shared store allows to share the state across multiple
40
+ * Returns an instance of pending state and the functions to update it.
41
+ *
42
+ * @param store - A unique store key or a store. Providing a store
43
+ * key or a shared store allows to share the state across multiple
34
44
  * components.
45
+ *
46
+ * @returns `[state, withState, setState]`, where
47
+ * - `state` is the current value of the pending state;
48
+ * - `withState(action, options?)` reads and tracks the pending state
49
+ * of `action`;
50
+ * - `setState(update)` can update the pending state value directly.
35
51
  */
36
- store?: string | Store<PendingState> | null): [
52
+ export declare function usePendingState(store?: string | Store<PendingState> | null): [
37
53
  PendingState,
38
54
  <T>(value: T) => T,
39
55
  SetStoreState<PendingState>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t8/react-pending",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "Concise async action state tracking for React apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -17,26 +17,43 @@ function createState(
17
17
  }
18
18
 
19
19
  export type WithStateOptions = {
20
+ /**
21
+ * Whether to track the action state silently (e.g. with a background
22
+ * action or an optimistic update).
23
+ *
24
+ * When set to `true`, the state's `complete` property doesn't switch
25
+ * to `false` in the pending state.
26
+ */
20
27
  silent?: boolean;
21
- throws?: boolean;
28
+ /**
29
+ * Delays switching the action state's `complete` property to `false`
30
+ * in the pending state by the given number of milliseconds.
31
+ *
32
+ * Use case: to avoid flashing a process indicator if the action is
33
+ * likely to complete by the end of a short delay.
34
+ */
22
35
  delay?: number;
36
+ /**
37
+ * Allows the async action to reject explicitly, along with exposing
38
+ * the action state's `error` property that goes by default.
39
+ */
40
+ throws?: boolean;
23
41
  };
24
42
 
25
43
  /**
26
- * Returns an array containing `[state, withState, setState]`:
27
- * - `state` reflects the state of a value passed to `withState()`;
28
- * - `withState(value, [options])` enables the tracking of the state
29
- * of `value`; setting the options to `{silent: true}` prevents
30
- * `withState()` from updating the state while `value` is pending
31
- * (e.g. for background or optimistic updates);
32
- * - `setState()` to directly update the state.
44
+ * Returns an instance of pending state and the functions to update it.
45
+ *
46
+ * @param store - A unique store key or a store. Providing a store
47
+ * key or a shared store allows to share the state across multiple
48
+ * components.
49
+ *
50
+ * @returns `[state, withState, setState]`, where
51
+ * - `state` is the current value of the pending state;
52
+ * - `withState(action, options?)` reads and tracks the pending state
53
+ * of `action`;
54
+ * - `setState(update)` can update the pending state value directly.
33
55
  */
34
56
  export function usePendingState(
35
- /**
36
- * A unique store key or a store. Providing a store key or a
37
- * shared store allows to share the state across multiple
38
- * components.
39
- */
40
57
  store?: string | Store<PendingState> | null,
41
58
  ): [PendingState, <T>(value: T) => T, SetStoreState<PendingState>] {
42
59
  let storeMap = useContext(PendingStateContext);