@j13b/react-state 0.1.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.
Files changed (91) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +16 -0
  3. package/README.md +60 -0
  4. package/dist/cjs/hooks/use_runner_error.d.ts +25 -0
  5. package/dist/cjs/hooks/use_runner_error.js +30 -0
  6. package/dist/cjs/hooks/use_runner_error_effect.d.ts +28 -0
  7. package/dist/cjs/hooks/use_runner_error_effect.js +35 -0
  8. package/dist/cjs/hooks/use_runner_feedback.d.ts +26 -0
  9. package/dist/cjs/hooks/use_runner_feedback.js +31 -0
  10. package/dist/cjs/hooks/use_runner_feedback_effect.d.ts +30 -0
  11. package/dist/cjs/hooks/use_runner_feedback_effect.js +37 -0
  12. package/dist/cjs/hooks/use_runner_progress.d.ts +21 -0
  13. package/dist/cjs/hooks/use_runner_progress.js +7 -0
  14. package/dist/cjs/hooks/use_runner_progress_effect.d.ts +31 -0
  15. package/dist/cjs/hooks/use_runner_progress_effect.js +38 -0
  16. package/dist/cjs/hooks/use_runner_status.d.ts +23 -0
  17. package/dist/cjs/hooks/use_runner_status.js +28 -0
  18. package/dist/cjs/hooks/use_runner_status_effect.d.ts +24 -0
  19. package/dist/cjs/hooks/use_runner_status_effect.js +31 -0
  20. package/dist/cjs/hooks/use_signal_value.d.ts +38 -0
  21. package/dist/cjs/hooks/use_signal_value.js +56 -0
  22. package/dist/cjs/hooks/use_signal_value_effect.d.ts +34 -0
  23. package/dist/cjs/hooks/use_signal_value_effect.js +60 -0
  24. package/dist/cjs/hooks/use_update.d.ts +14 -0
  25. package/dist/cjs/hooks/use_update.js +23 -0
  26. package/dist/cjs/index.d.ts +21 -0
  27. package/dist/cjs/index.js +37 -0
  28. package/dist/cjs/package.json +3 -0
  29. package/dist/hooks/use_runner_error.d.ts +26 -0
  30. package/dist/hooks/use_runner_error.d.ts.map +1 -0
  31. package/dist/hooks/use_runner_error.js +32 -0
  32. package/dist/hooks/use_runner_error.js.map +1 -0
  33. package/dist/hooks/use_runner_error_effect.d.ts +29 -0
  34. package/dist/hooks/use_runner_error_effect.d.ts.map +1 -0
  35. package/dist/hooks/use_runner_error_effect.js +37 -0
  36. package/dist/hooks/use_runner_error_effect.js.map +1 -0
  37. package/dist/hooks/use_runner_feedback.d.ts +21 -0
  38. package/dist/hooks/use_runner_feedback.d.ts.map +1 -0
  39. package/dist/hooks/use_runner_feedback.js +27 -0
  40. package/dist/hooks/use_runner_feedback.js.map +1 -0
  41. package/dist/hooks/use_runner_feedback_effect.d.ts +25 -0
  42. package/dist/hooks/use_runner_feedback_effect.d.ts.map +1 -0
  43. package/dist/hooks/use_runner_feedback_effect.js +33 -0
  44. package/dist/hooks/use_runner_feedback_effect.js.map +1 -0
  45. package/dist/hooks/use_runner_progress.d.ts +3 -0
  46. package/dist/hooks/use_runner_progress.d.ts.map +1 -0
  47. package/dist/hooks/use_runner_progress.js +9 -0
  48. package/dist/hooks/use_runner_progress.js.map +1 -0
  49. package/dist/hooks/use_runner_progress_effect.d.ts +26 -0
  50. package/dist/hooks/use_runner_progress_effect.d.ts.map +1 -0
  51. package/dist/hooks/use_runner_progress_effect.js +34 -0
  52. package/dist/hooks/use_runner_progress_effect.js.map +1 -0
  53. package/dist/hooks/use_runner_status.d.ts +24 -0
  54. package/dist/hooks/use_runner_status.d.ts.map +1 -0
  55. package/dist/hooks/use_runner_status.js +30 -0
  56. package/dist/hooks/use_runner_status.js.map +1 -0
  57. package/dist/hooks/use_runner_status_effect.d.ts +25 -0
  58. package/dist/hooks/use_runner_status_effect.d.ts.map +1 -0
  59. package/dist/hooks/use_runner_status_effect.js +33 -0
  60. package/dist/hooks/use_runner_status_effect.js.map +1 -0
  61. package/dist/hooks/use_signal_value.d.ts +39 -0
  62. package/dist/hooks/use_signal_value.d.ts.map +1 -0
  63. package/dist/hooks/use_signal_value.js +51 -0
  64. package/dist/hooks/use_signal_value.js.map +1 -0
  65. package/dist/hooks/use_signal_value_effect.d.ts +35 -0
  66. package/dist/hooks/use_signal_value_effect.d.ts.map +1 -0
  67. package/dist/hooks/use_signal_value_effect.js +54 -0
  68. package/dist/hooks/use_signal_value_effect.js.map +1 -0
  69. package/dist/hooks/use_update.d.ts +15 -0
  70. package/dist/hooks/use_update.d.ts.map +1 -0
  71. package/dist/hooks/use_update.js +24 -0
  72. package/dist/hooks/use_update.js.map +1 -0
  73. package/dist/index.d.ts +22 -0
  74. package/dist/index.d.ts.map +1 -0
  75. package/dist/index.js +12 -0
  76. package/package.json +79 -0
  77. package/src/__tests__/exports.test.ts +32 -0
  78. package/src/__tests__/hooks.test.tsx +242 -0
  79. package/src/hooks/use_runner_error.ts +29 -0
  80. package/src/hooks/use_runner_error_effect.ts +37 -0
  81. package/src/hooks/use_runner_feedback.ts +31 -0
  82. package/src/hooks/use_runner_feedback_effect.ts +40 -0
  83. package/src/hooks/use_runner_progress.ts +25 -0
  84. package/src/hooks/use_runner_progress_effect.ts +41 -0
  85. package/src/hooks/use_runner_status.ts +27 -0
  86. package/src/hooks/use_runner_status_effect.ts +33 -0
  87. package/src/hooks/use_signal_value.ts +61 -0
  88. package/src/hooks/use_signal_value_effect.ts +68 -0
  89. package/src/hooks/use_update.ts +21 -0
  90. package/src/index.ts +21 -0
  91. package/tsconfig.json +23 -0
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useRunnerStatus = useRunnerStatus;
4
+ const use_signal_value_js_1 = require("./use_signal_value.js");
5
+ /**
6
+ * A hook that subscribes to a runner's status changes and returns the current status.
7
+ * The component will re-render whenever the runner's status changes.
8
+ *
9
+ * @template T - The type of the runner's value
10
+ * @param broadcast - The broadcast interface of the runner to subscribe to
11
+ * @returns The current status of the runner (INITIAL, PENDING, SUCCESS, ERROR)
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const status = useRunnerStatus(runner.broadcast);
16
+ *
17
+ * return (
18
+ * <div>
19
+ * {status === 'PENDING' && <Spinner />}
20
+ * {status === 'ERROR' && <ErrorMessage />}
21
+ * {status === 'SUCCESS' && <SuccessMessage />}
22
+ * </div>
23
+ * );
24
+ * ```
25
+ */
26
+ function useRunnerStatus(broadcast) {
27
+ return (0, use_signal_value_js_1.useSignalValue)(broadcast.stateBroadcast).status;
28
+ }
@@ -0,0 +1,24 @@
1
+ import { IRunnerBroadcast, Status } from '@j13b/state';
2
+ /**
3
+ * A hook that runs an effect whenever a runner's status changes.
4
+ * This is useful for side effects that need to respond to runner status changes
5
+ * without causing a re-render.
6
+ *
7
+ * @template T - The type of the runner's value
8
+ * @param callback - The effect to run when the runner's status changes
9
+ * @param task - The broadcast interface of the runner to subscribe to
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * useRunnerStatusEffect(
14
+ * status => {
15
+ * if (status === 'ERROR') {
16
+ * // Handle error state
17
+ * showErrorToast();
18
+ * }
19
+ * },
20
+ * runner.broadcast
21
+ * );
22
+ * ```
23
+ */
24
+ export declare function useRunnerStatusEffect(callback: (value: Status) => void, task: IRunnerBroadcast<any>): void;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useRunnerStatusEffect = useRunnerStatusEffect;
4
+ const use_signal_value_effect_js_1 = require("./use_signal_value_effect.js");
5
+ /**
6
+ * A hook that runs an effect whenever a runner's status changes.
7
+ * This is useful for side effects that need to respond to runner status changes
8
+ * without causing a re-render.
9
+ *
10
+ * @template T - The type of the runner's value
11
+ * @param callback - The effect to run when the runner's status changes
12
+ * @param task - The broadcast interface of the runner to subscribe to
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * useRunnerStatusEffect(
17
+ * status => {
18
+ * if (status === 'ERROR') {
19
+ * // Handle error state
20
+ * showErrorToast();
21
+ * }
22
+ * },
23
+ * runner.broadcast
24
+ * );
25
+ * ```
26
+ */
27
+ function useRunnerStatusEffect(callback, task) {
28
+ return (0, use_signal_value_effect_js_1.useSignalValueEffect)(state => {
29
+ callback(state.status);
30
+ }, task.stateBroadcast);
31
+ }
@@ -0,0 +1,38 @@
1
+ import { IBroadcast } from '@j13b/state';
2
+ /**
3
+ * A hook that subscribes to a signal's value changes and returns the current value.
4
+ * The component re-renders when the signal broadcasts. Notifications are batched
5
+ * by React: a burst of synchronous emissions (e.g. several `set()` calls in one
6
+ * event tick) renders once with the latest value — intermediate states are never
7
+ * painted.
8
+ *
9
+ * Built on React 18's `useSyncExternalStore`, which makes the hook:
10
+ * - Tear-free under concurrent rendering (React re-checks the snapshot after render).
11
+ * - SSR-safe: on the server the current value is rendered via the server snapshot
12
+ * without subscribing (no `useLayoutEffect` warnings).
13
+ *
14
+ * The snapshot is the broadcast's monotonically increasing `version` rather than
15
+ * the value itself. This guarantees that no emission is silently ignored:
16
+ * `Signal.transform()` mutates the value in place and returns the SAME reference,
17
+ * so value/reference equality (`Object.is`) cannot detect the change — the version
18
+ * counter is what makes in-place transforms render. A consequence is that a
19
+ * `set()` of an identical value also triggers one render, since without a deep
20
+ * comparison it is indistinguishable from an in-place mutation.
21
+ *
22
+ * The subscription object returned by `broadcast.subscribe()` is strongly held by
23
+ * the unsubscribe closure for the lifetime of the subscription (the signal itself
24
+ * only holds it via WeakRef), and is unsubscribed when the component unmounts or
25
+ * the broadcast changes.
26
+ *
27
+ * @template TValue - The type of the signal's value
28
+ * @param broadcast - The broadcast interface of the signal to subscribe to
29
+ * @returns The current value of the signal
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * const value = useSignalValue(signal.broadcast);
34
+ *
35
+ * return <div>Current value: {value}</div>;
36
+ * ```
37
+ */
38
+ export declare function useSignalValue<TValue>(broadcast: IBroadcast<TValue>): TValue;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSignalValue = useSignalValue;
4
+ const react_1 = require("react");
5
+ /**
6
+ * A hook that subscribes to a signal's value changes and returns the current value.
7
+ * The component re-renders when the signal broadcasts. Notifications are batched
8
+ * by React: a burst of synchronous emissions (e.g. several `set()` calls in one
9
+ * event tick) renders once with the latest value — intermediate states are never
10
+ * painted.
11
+ *
12
+ * Built on React 18's `useSyncExternalStore`, which makes the hook:
13
+ * - Tear-free under concurrent rendering (React re-checks the snapshot after render).
14
+ * - SSR-safe: on the server the current value is rendered via the server snapshot
15
+ * without subscribing (no `useLayoutEffect` warnings).
16
+ *
17
+ * The snapshot is the broadcast's monotonically increasing `version` rather than
18
+ * the value itself. This guarantees that no emission is silently ignored:
19
+ * `Signal.transform()` mutates the value in place and returns the SAME reference,
20
+ * so value/reference equality (`Object.is`) cannot detect the change — the version
21
+ * counter is what makes in-place transforms render. A consequence is that a
22
+ * `set()` of an identical value also triggers one render, since without a deep
23
+ * comparison it is indistinguishable from an in-place mutation.
24
+ *
25
+ * The subscription object returned by `broadcast.subscribe()` is strongly held by
26
+ * the unsubscribe closure for the lifetime of the subscription (the signal itself
27
+ * only holds it via WeakRef), and is unsubscribed when the component unmounts or
28
+ * the broadcast changes.
29
+ *
30
+ * @template TValue - The type of the signal's value
31
+ * @param broadcast - The broadcast interface of the signal to subscribe to
32
+ * @returns The current value of the signal
33
+ *
34
+ * @example
35
+ * ```tsx
36
+ * const value = useSignalValue(signal.broadcast);
37
+ *
38
+ * return <div>Current value: {value}</div>;
39
+ * ```
40
+ */
41
+ function useSignalValue(broadcast) {
42
+ const subscribe = (0, react_1.useCallback)((onStoreChange) => {
43
+ // `subscription` must be strongly referenced: the signal only keeps a
44
+ // WeakRef to it, so this closure is what keeps the callback alive.
45
+ const subscription = broadcast.subscribe(onStoreChange);
46
+ return () => subscription.unsubscribe();
47
+ }, [broadcast]);
48
+ // Version snapshot (deliberate): transform() mutates in place and returns the
49
+ // same reference, so Object.is on the value would miss changes. The version
50
+ // increments on every set(), so no emission is ignored (React coalesces a
51
+ // synchronous burst into a single render of the latest value). Do not
52
+ // snapshot the value.
53
+ const getSnapshot = (0, react_1.useCallback)(() => broadcast.version, [broadcast]);
54
+ (0, react_1.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
55
+ return broadcast.get();
56
+ }
@@ -0,0 +1,34 @@
1
+ import type { IBroadcast } from '@j13b/state';
2
+ /**
3
+ * A hook that runs an effect whenever a signal's value changes.
4
+ * This is useful for side effects that need to respond to signal value changes
5
+ * without causing a re-render.
6
+ *
7
+ * Contract:
8
+ * - The callback fires exactly once with the current value on mount, and again
9
+ * once whenever the `broadcast` identity changes (with the new broadcast's
10
+ * current value).
11
+ * - After that, it fires exactly once per emission — including emissions of an
12
+ * identical value (every `set()` notifies subscribers). No double-fires.
13
+ * - The latest `callback` prop is always used; changing the callback does not
14
+ * re-subscribe or re-fire.
15
+ * - The subscription object is strongly held for the component's lifetime (the
16
+ * signal itself only holds it via WeakRef) and is cleaned up on unmount or
17
+ * when the broadcast changes.
18
+ *
19
+ * @template T - The type of the signal's value
20
+ * @param callback - The effect to run when the signal's value changes
21
+ * @param broadcast - The broadcast interface of the signal to subscribe to
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * useSignalValueEffect(
26
+ * value => {
27
+ * // Do something with the new value
28
+ * console.log('Value changed:', value);
29
+ * },
30
+ * signal.broadcast
31
+ * );
32
+ * ```
33
+ */
34
+ export declare function useSignalValueEffect<T>(callback: (value: T) => void, broadcast: IBroadcast<T>): void;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSignalValueEffect = useSignalValueEffect;
4
+ const react_1 = require("react");
5
+ // useLayoutEffect warns during server-side rendering; fall back to useEffect
6
+ // there. Effects never run on the server either way, so behavior is identical.
7
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? react_1.useLayoutEffect : react_1.useEffect;
8
+ /**
9
+ * A hook that runs an effect whenever a signal's value changes.
10
+ * This is useful for side effects that need to respond to signal value changes
11
+ * without causing a re-render.
12
+ *
13
+ * Contract:
14
+ * - The callback fires exactly once with the current value on mount, and again
15
+ * once whenever the `broadcast` identity changes (with the new broadcast's
16
+ * current value).
17
+ * - After that, it fires exactly once per emission — including emissions of an
18
+ * identical value (every `set()` notifies subscribers). No double-fires.
19
+ * - The latest `callback` prop is always used; changing the callback does not
20
+ * re-subscribe or re-fire.
21
+ * - The subscription object is strongly held for the component's lifetime (the
22
+ * signal itself only holds it via WeakRef) and is cleaned up on unmount or
23
+ * when the broadcast changes.
24
+ *
25
+ * @template T - The type of the signal's value
26
+ * @param callback - The effect to run when the signal's value changes
27
+ * @param broadcast - The broadcast interface of the signal to subscribe to
28
+ *
29
+ * @example
30
+ * ```tsx
31
+ * useSignalValueEffect(
32
+ * value => {
33
+ * // Do something with the new value
34
+ * console.log('Value changed:', value);
35
+ * },
36
+ * signal.broadcast
37
+ * );
38
+ * ```
39
+ */
40
+ function useSignalValueEffect(callback, broadcast) {
41
+ const callbackRef = (0, react_1.useRef)(callback);
42
+ // Declared before the subscription effect so the ref is up to date when the
43
+ // subscription effect (re-)runs in the same commit.
44
+ useIsomorphicLayoutEffect(() => {
45
+ callbackRef.current = callback;
46
+ }, [callback]);
47
+ useIsomorphicLayoutEffect(() => {
48
+ // `subscription` is strongly referenced by this effect's closure: the
49
+ // signal only keeps a WeakRef to it, so this is what keeps it alive.
50
+ const subscription = broadcast.subscribe(value => {
51
+ callbackRef.current(value);
52
+ });
53
+ // Fire exactly once with the current value on mount / broadcast change.
54
+ // Subsequent emissions arrive through the subscription above.
55
+ callbackRef.current(broadcast.get());
56
+ return () => {
57
+ subscription.unsubscribe();
58
+ };
59
+ }, [broadcast]);
60
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A hook that provides a way to force component re-renders.
3
+ *
4
+ * @returns A function that triggers a re-render when called
5
+ *
6
+ * @example
7
+ * ```tsx
8
+ * const update = useUpdate();
9
+ *
10
+ * // Force a re-render
11
+ * update();
12
+ * ```
13
+ */
14
+ export declare const useUpdate: () => () => void;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useUpdate = void 0;
4
+ const react_1 = require("react");
5
+ const updateReducer = (num) => (num + 1) % 1_000_000;
6
+ /**
7
+ * A hook that provides a way to force component re-renders.
8
+ *
9
+ * @returns A function that triggers a re-render when called
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * const update = useUpdate();
14
+ *
15
+ * // Force a re-render
16
+ * update();
17
+ * ```
18
+ */
19
+ const useUpdate = () => {
20
+ const [, update] = (0, react_1.useReducer)(updateReducer, 0);
21
+ return update;
22
+ };
23
+ exports.useUpdate = useUpdate;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * React bindings for @j13b/state.
3
+ * Hooks for subscribing to Signals, Runners, and Broadcasts from React
4
+ * components. Requires react and @j13b/state as peer dependencies.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { useSignalValue, useRunnerStatus } from '@j13b/react-state';
9
+ * ```
10
+ */
11
+ export * from './hooks/use_signal_value.js';
12
+ export * from './hooks/use_signal_value_effect.js';
13
+ export * from './hooks/use_update.js';
14
+ export * from './hooks/use_runner_status.js';
15
+ export * from './hooks/use_runner_status_effect.js';
16
+ export * from './hooks/use_runner_error.js';
17
+ export * from './hooks/use_runner_error_effect.js';
18
+ export * from './hooks/use_runner_progress.js';
19
+ export * from './hooks/use_runner_progress_effect.js';
20
+ export * from './hooks/use_runner_feedback.js';
21
+ export * from './hooks/use_runner_feedback_effect.js';
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * React bindings for @j13b/state.
19
+ * Hooks for subscribing to Signals, Runners, and Broadcasts from React
20
+ * components. Requires react and @j13b/state as peer dependencies.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * import { useSignalValue, useRunnerStatus } from '@j13b/react-state';
25
+ * ```
26
+ */
27
+ __exportStar(require("./hooks/use_signal_value.js"), exports);
28
+ __exportStar(require("./hooks/use_signal_value_effect.js"), exports);
29
+ __exportStar(require("./hooks/use_update.js"), exports);
30
+ __exportStar(require("./hooks/use_runner_status.js"), exports);
31
+ __exportStar(require("./hooks/use_runner_status_effect.js"), exports);
32
+ __exportStar(require("./hooks/use_runner_error.js"), exports);
33
+ __exportStar(require("./hooks/use_runner_error_effect.js"), exports);
34
+ __exportStar(require("./hooks/use_runner_progress.js"), exports);
35
+ __exportStar(require("./hooks/use_runner_progress_effect.js"), exports);
36
+ __exportStar(require("./hooks/use_runner_feedback.js"), exports);
37
+ __exportStar(require("./hooks/use_runner_feedback_effect.js"), exports);
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,26 @@
1
+ import { IRunnerBroadcast } from '@j13b/state';
2
+ /**
3
+ * A React hook that subscribes to the error state of a runner.
4
+ *
5
+ * @template T - The type of value that the runner manages
6
+ * @param {IRunnerBroadcast<T>} task - The runner broadcast interface to subscribe to
7
+ * @returns {Error | null} The current error state of the runner, or null if there is no error
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * const error = useRunnerError(saveRunner.broadcast);
12
+ * if (error) {
13
+ * return <ErrorMessage error={error} />;
14
+ * }
15
+ * ```
16
+ *
17
+ * @remarks
18
+ * This hook is useful for:
19
+ * - Displaying error messages in the UI
20
+ * - Conditionally rendering error states
21
+ * - Triggering error handling logic
22
+ *
23
+ * The hook will automatically unsubscribe when the component unmounts.
24
+ */
25
+ export declare function useRunnerError(task: IRunnerBroadcast<any>): Error | null;
26
+ //# sourceMappingURL=use_runner_error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use_runner_error.d.ts","sourceRoot":"","sources":["../../src/hooks/use_runner_error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,GAAG,CAAC,gBAEzD"}
@@ -0,0 +1,32 @@
1
+ import { useSignalValue } from "./use_signal_value.js";
2
+ //#region src/hooks/use_runner_error.ts
3
+ /**
4
+ * A React hook that subscribes to the error state of a runner.
5
+ *
6
+ * @template T - The type of value that the runner manages
7
+ * @param {IRunnerBroadcast<T>} task - The runner broadcast interface to subscribe to
8
+ * @returns {Error | null} The current error state of the runner, or null if there is no error
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const error = useRunnerError(saveRunner.broadcast);
13
+ * if (error) {
14
+ * return <ErrorMessage error={error} />;
15
+ * }
16
+ * ```
17
+ *
18
+ * @remarks
19
+ * This hook is useful for:
20
+ * - Displaying error messages in the UI
21
+ * - Conditionally rendering error states
22
+ * - Triggering error handling logic
23
+ *
24
+ * The hook will automatically unsubscribe when the component unmounts.
25
+ */
26
+ function useRunnerError(task) {
27
+ return useSignalValue(task.stateBroadcast).error;
28
+ }
29
+ //#endregion
30
+ export { useRunnerError };
31
+
32
+ //# sourceMappingURL=use_runner_error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use_runner_error.js","names":[],"sources":["../../src/hooks/use_runner_error.ts"],"sourcesContent":["import { IRunnerBroadcast } from '@j13b/state';\nimport { useSignalValue } from './use_signal_value.js';\n\n/**\n * A React hook that subscribes to the error state of a runner.\n *\n * @template T - The type of value that the runner manages\n * @param {IRunnerBroadcast<T>} task - The runner broadcast interface to subscribe to\n * @returns {Error | null} The current error state of the runner, or null if there is no error\n *\n * @example\n * ```tsx\n * const error = useRunnerError(saveRunner.broadcast);\n * if (error) {\n * return <ErrorMessage error={error} />;\n * }\n * ```\n *\n * @remarks\n * This hook is useful for:\n * - Displaying error messages in the UI\n * - Conditionally rendering error states\n * - Triggering error handling logic\n *\n * The hook will automatically unsubscribe when the component unmounts.\n */\nexport function useRunnerError(task: IRunnerBroadcast<any>) {\n return useSignalValue(task.stateBroadcast).error;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,eAAe,MAA6B;CAC1D,OAAO,eAAe,KAAK,cAAc,CAAC,CAAC;AAC7C"}
@@ -0,0 +1,29 @@
1
+ import { IRunnerBroadcast } from '@j13b/state';
2
+ /**
3
+ * A React hook that executes a callback whenever the error state of a Runner changes.
4
+ * This hook is useful for handling side effects that need to respond to error states
5
+ * in async operations managed by a Runner.
6
+ *
7
+ * @template T - The type of value managed by the Runner
8
+ * @param callback - A function that will be called with the current error state
9
+ * @param task - The Runner instance to monitor for error changes
10
+ * @returns void
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * useRunnerErrorEffect((error) => {
15
+ * if (error) {
16
+ * // Handle the error, e.g., show a notification
17
+ * showErrorNotification(error.message);
18
+ * }
19
+ * }, myRunner);
20
+ * ```
21
+ *
22
+ * @remarks
23
+ * - The callback will be called immediately with the current error state
24
+ * - The callback will be called whenever the error state changes
25
+ * - The hook automatically handles cleanup on component unmount
26
+ * - This hook is built on top of useSignalValueEffect for efficient state tracking
27
+ */
28
+ export declare function useRunnerErrorEffect(callback: (error: Error | null) => void, task: IRunnerBroadcast<any>): void;
29
+ //# sourceMappingURL=use_runner_error_effect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use_runner_error_effect.d.ts","sourceRoot":"","sources":["../../src/hooks/use_runner_error_effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,EACvC,IAAI,EAAE,gBAAgB,CAAC,GAAG,CAAC,QAK5B"}
@@ -0,0 +1,37 @@
1
+ import { useSignalValueEffect } from "./use_signal_value_effect.js";
2
+ //#region src/hooks/use_runner_error_effect.ts
3
+ /**
4
+ * A React hook that executes a callback whenever the error state of a Runner changes.
5
+ * This hook is useful for handling side effects that need to respond to error states
6
+ * in async operations managed by a Runner.
7
+ *
8
+ * @template T - The type of value managed by the Runner
9
+ * @param callback - A function that will be called with the current error state
10
+ * @param task - The Runner instance to monitor for error changes
11
+ * @returns void
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * useRunnerErrorEffect((error) => {
16
+ * if (error) {
17
+ * // Handle the error, e.g., show a notification
18
+ * showErrorNotification(error.message);
19
+ * }
20
+ * }, myRunner);
21
+ * ```
22
+ *
23
+ * @remarks
24
+ * - The callback will be called immediately with the current error state
25
+ * - The callback will be called whenever the error state changes
26
+ * - The hook automatically handles cleanup on component unmount
27
+ * - This hook is built on top of useSignalValueEffect for efficient state tracking
28
+ */
29
+ function useRunnerErrorEffect(callback, task) {
30
+ return useSignalValueEffect((state) => {
31
+ callback(state.error);
32
+ }, task.stateBroadcast);
33
+ }
34
+ //#endregion
35
+ export { useRunnerErrorEffect };
36
+
37
+ //# sourceMappingURL=use_runner_error_effect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use_runner_error_effect.js","names":[],"sources":["../../src/hooks/use_runner_error_effect.ts"],"sourcesContent":["import { IRunnerBroadcast } from '@j13b/state';\nimport { useSignalValueEffect } from './use_signal_value_effect.js';\n\n/**\n * A React hook that executes a callback whenever the error state of a Runner changes.\n * This hook is useful for handling side effects that need to respond to error states\n * in async operations managed by a Runner.\n *\n * @template T - The type of value managed by the Runner\n * @param callback - A function that will be called with the current error state\n * @param task - The Runner instance to monitor for error changes\n * @returns void\n *\n * @example\n * ```tsx\n * useRunnerErrorEffect((error) => {\n * if (error) {\n * // Handle the error, e.g., show a notification\n * showErrorNotification(error.message);\n * }\n * }, myRunner);\n * ```\n *\n * @remarks\n * - The callback will be called immediately with the current error state\n * - The callback will be called whenever the error state changes\n * - The hook automatically handles cleanup on component unmount\n * - This hook is built on top of useSignalValueEffect for efficient state tracking\n */\nexport function useRunnerErrorEffect(\n callback: (error: Error | null) => void,\n task: IRunnerBroadcast<any>\n) {\n return useSignalValueEffect(state => {\n callback(state.error);\n }, task.stateBroadcast);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,qBACd,UACA,MACA;CACA,OAAO,sBAAqB,UAAS;EACnC,SAAS,MAAM,KAAK;CACtB,GAAG,KAAK,cAAc;AACxB"}
@@ -0,0 +1,21 @@
1
+ import { IRunnerBroadcast } from '@j13b/state';
2
+ /**
3
+ * Hook that provides access to the feedback message from a Runner's state.
4
+ *
5
+ * @template T - The type of the Runner's value
6
+ * @param {IRunnerBroadcast<T>} task - The Runner broadcast interface to subscribe to
7
+ * @returns {string | undefined} The current feedback message, or undefined if no feedback is set
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * const feedback = useRunnerFeedback(saveRunner.broadcast);
12
+ * return <div>{feedback}</div>;
13
+ * ```
14
+ *
15
+ * @remarks
16
+ * This hook is useful for displaying status messages to users during async operations.
17
+ * The feedback message is typically set using the Runner's setFeedback method.
18
+ * The component will automatically re-render when the feedback message changes.
19
+ */
20
+ export declare function useRunnerFeedback(task: IRunnerBroadcast<any>): string;
21
+ //# sourceMappingURL=use_runner_feedback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use_runner_feedback.d.ts","sourceRoot":"","sources":["../../src/hooks/use_runner_feedback.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,CAAC,GAAG,CAAC,UAE5D"}
@@ -0,0 +1,27 @@
1
+ import { useSignalValue } from "./use_signal_value.js";
2
+ //#region src/hooks/use_runner_feedback.ts
3
+ /**
4
+ * Hook that provides access to the feedback message from a Runner's state.
5
+ *
6
+ * @template T - The type of the Runner's value
7
+ * @param {IRunnerBroadcast<T>} task - The Runner broadcast interface to subscribe to
8
+ * @returns {string | undefined} The current feedback message, or undefined if no feedback is set
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const feedback = useRunnerFeedback(saveRunner.broadcast);
13
+ * return <div>{feedback}</div>;
14
+ * ```
15
+ *
16
+ * @remarks
17
+ * This hook is useful for displaying status messages to users during async operations.
18
+ * The feedback message is typically set using the Runner's setFeedback method.
19
+ * The component will automatically re-render when the feedback message changes.
20
+ */
21
+ function useRunnerFeedback(task) {
22
+ return useSignalValue(task.stateBroadcast).feedback;
23
+ }
24
+ //#endregion
25
+ export { useRunnerFeedback };
26
+
27
+ //# sourceMappingURL=use_runner_feedback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use_runner_feedback.js","names":[],"sources":["../../src/hooks/use_runner_feedback.ts"],"sourcesContent":["/**\n * @module hooks/use_runner_feedback\n *\n * This module provides a hook for accessing the feedback message from a Runner's state.\n * It is useful for displaying status messages to users during async operations.\n */\n\nimport { IRunnerBroadcast } from '@j13b/state';\nimport { useSignalValue } from './use_signal_value.js';\n\n/**\n * Hook that provides access to the feedback message from a Runner's state.\n *\n * @template T - The type of the Runner's value\n * @param {IRunnerBroadcast<T>} task - The Runner broadcast interface to subscribe to\n * @returns {string | undefined} The current feedback message, or undefined if no feedback is set\n *\n * @example\n * ```tsx\n * const feedback = useRunnerFeedback(saveRunner.broadcast);\n * return <div>{feedback}</div>;\n * ```\n *\n * @remarks\n * This hook is useful for displaying status messages to users during async operations.\n * The feedback message is typically set using the Runner's setFeedback method.\n * The component will automatically re-render when the feedback message changes.\n */\nexport function useRunnerFeedback(task: IRunnerBroadcast<any>) {\n return useSignalValue(task.stateBroadcast).feedback;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,kBAAkB,MAA6B;CAC7D,OAAO,eAAe,KAAK,cAAc,CAAC,CAAC;AAC7C"}
@@ -0,0 +1,25 @@
1
+ import { IRunnerBroadcast } from '@j13b/state';
2
+ /**
3
+ * A React hook that executes a callback whenever the feedback message of a Runner changes.
4
+ *
5
+ * This hook is useful for displaying operation feedback to users, such as loading messages,
6
+ * progress updates, or error notifications. It automatically handles cleanup when the
7
+ * component unmounts.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * useRunnerFeedbackEffect(
12
+ * (feedback) => {
13
+ * // Update UI with feedback message
14
+ * setMessage(feedback);
15
+ * },
16
+ * myRunner.broadcast
17
+ * );
18
+ * ```
19
+ *
20
+ * @param callback - A function that will be called with the new feedback message whenever it changes
21
+ * @param task - The Runner's broadcast interface to subscribe to
22
+ * @returns void
23
+ */
24
+ export declare function useRunnerFeedbackEffect(callback: (feedback: string) => void, task: IRunnerBroadcast<any>): void;
25
+ //# sourceMappingURL=use_runner_feedback_effect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use_runner_feedback_effect.d.ts","sourceRoot":"","sources":["../../src/hooks/use_runner_feedback_effect.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,EACpC,IAAI,EAAE,gBAAgB,CAAC,GAAG,CAAC,QAK5B"}
@@ -0,0 +1,33 @@
1
+ import { useSignalValueEffect } from "./use_signal_value_effect.js";
2
+ //#region src/hooks/use_runner_feedback_effect.ts
3
+ /**
4
+ * A React hook that executes a callback whenever the feedback message of a Runner changes.
5
+ *
6
+ * This hook is useful for displaying operation feedback to users, such as loading messages,
7
+ * progress updates, or error notifications. It automatically handles cleanup when the
8
+ * component unmounts.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * useRunnerFeedbackEffect(
13
+ * (feedback) => {
14
+ * // Update UI with feedback message
15
+ * setMessage(feedback);
16
+ * },
17
+ * myRunner.broadcast
18
+ * );
19
+ * ```
20
+ *
21
+ * @param callback - A function that will be called with the new feedback message whenever it changes
22
+ * @param task - The Runner's broadcast interface to subscribe to
23
+ * @returns void
24
+ */
25
+ function useRunnerFeedbackEffect(callback, task) {
26
+ return useSignalValueEffect((state) => {
27
+ callback(state.feedback);
28
+ }, task.stateBroadcast);
29
+ }
30
+ //#endregion
31
+ export { useRunnerFeedbackEffect };
32
+
33
+ //# sourceMappingURL=use_runner_feedback_effect.js.map