@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.
- package/LICENSE +201 -0
- package/NOTICE +16 -0
- package/README.md +60 -0
- package/dist/cjs/hooks/use_runner_error.d.ts +25 -0
- package/dist/cjs/hooks/use_runner_error.js +30 -0
- package/dist/cjs/hooks/use_runner_error_effect.d.ts +28 -0
- package/dist/cjs/hooks/use_runner_error_effect.js +35 -0
- package/dist/cjs/hooks/use_runner_feedback.d.ts +26 -0
- package/dist/cjs/hooks/use_runner_feedback.js +31 -0
- package/dist/cjs/hooks/use_runner_feedback_effect.d.ts +30 -0
- package/dist/cjs/hooks/use_runner_feedback_effect.js +37 -0
- package/dist/cjs/hooks/use_runner_progress.d.ts +21 -0
- package/dist/cjs/hooks/use_runner_progress.js +7 -0
- package/dist/cjs/hooks/use_runner_progress_effect.d.ts +31 -0
- package/dist/cjs/hooks/use_runner_progress_effect.js +38 -0
- package/dist/cjs/hooks/use_runner_status.d.ts +23 -0
- package/dist/cjs/hooks/use_runner_status.js +28 -0
- package/dist/cjs/hooks/use_runner_status_effect.d.ts +24 -0
- package/dist/cjs/hooks/use_runner_status_effect.js +31 -0
- package/dist/cjs/hooks/use_signal_value.d.ts +38 -0
- package/dist/cjs/hooks/use_signal_value.js +56 -0
- package/dist/cjs/hooks/use_signal_value_effect.d.ts +34 -0
- package/dist/cjs/hooks/use_signal_value_effect.js +60 -0
- package/dist/cjs/hooks/use_update.d.ts +14 -0
- package/dist/cjs/hooks/use_update.js +23 -0
- package/dist/cjs/index.d.ts +21 -0
- package/dist/cjs/index.js +37 -0
- package/dist/cjs/package.json +3 -0
- package/dist/hooks/use_runner_error.d.ts +26 -0
- package/dist/hooks/use_runner_error.d.ts.map +1 -0
- package/dist/hooks/use_runner_error.js +32 -0
- package/dist/hooks/use_runner_error.js.map +1 -0
- package/dist/hooks/use_runner_error_effect.d.ts +29 -0
- package/dist/hooks/use_runner_error_effect.d.ts.map +1 -0
- package/dist/hooks/use_runner_error_effect.js +37 -0
- package/dist/hooks/use_runner_error_effect.js.map +1 -0
- package/dist/hooks/use_runner_feedback.d.ts +21 -0
- package/dist/hooks/use_runner_feedback.d.ts.map +1 -0
- package/dist/hooks/use_runner_feedback.js +27 -0
- package/dist/hooks/use_runner_feedback.js.map +1 -0
- package/dist/hooks/use_runner_feedback_effect.d.ts +25 -0
- package/dist/hooks/use_runner_feedback_effect.d.ts.map +1 -0
- package/dist/hooks/use_runner_feedback_effect.js +33 -0
- package/dist/hooks/use_runner_feedback_effect.js.map +1 -0
- package/dist/hooks/use_runner_progress.d.ts +3 -0
- package/dist/hooks/use_runner_progress.d.ts.map +1 -0
- package/dist/hooks/use_runner_progress.js +9 -0
- package/dist/hooks/use_runner_progress.js.map +1 -0
- package/dist/hooks/use_runner_progress_effect.d.ts +26 -0
- package/dist/hooks/use_runner_progress_effect.d.ts.map +1 -0
- package/dist/hooks/use_runner_progress_effect.js +34 -0
- package/dist/hooks/use_runner_progress_effect.js.map +1 -0
- package/dist/hooks/use_runner_status.d.ts +24 -0
- package/dist/hooks/use_runner_status.d.ts.map +1 -0
- package/dist/hooks/use_runner_status.js +30 -0
- package/dist/hooks/use_runner_status.js.map +1 -0
- package/dist/hooks/use_runner_status_effect.d.ts +25 -0
- package/dist/hooks/use_runner_status_effect.d.ts.map +1 -0
- package/dist/hooks/use_runner_status_effect.js +33 -0
- package/dist/hooks/use_runner_status_effect.js.map +1 -0
- package/dist/hooks/use_signal_value.d.ts +39 -0
- package/dist/hooks/use_signal_value.d.ts.map +1 -0
- package/dist/hooks/use_signal_value.js +51 -0
- package/dist/hooks/use_signal_value.js.map +1 -0
- package/dist/hooks/use_signal_value_effect.d.ts +35 -0
- package/dist/hooks/use_signal_value_effect.d.ts.map +1 -0
- package/dist/hooks/use_signal_value_effect.js +54 -0
- package/dist/hooks/use_signal_value_effect.js.map +1 -0
- package/dist/hooks/use_update.d.ts +15 -0
- package/dist/hooks/use_update.d.ts.map +1 -0
- package/dist/hooks/use_update.js +24 -0
- package/dist/hooks/use_update.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/package.json +79 -0
- package/src/__tests__/exports.test.ts +32 -0
- package/src/__tests__/hooks.test.tsx +242 -0
- package/src/hooks/use_runner_error.ts +29 -0
- package/src/hooks/use_runner_error_effect.ts +37 -0
- package/src/hooks/use_runner_feedback.ts +31 -0
- package/src/hooks/use_runner_feedback_effect.ts +40 -0
- package/src/hooks/use_runner_progress.ts +25 -0
- package/src/hooks/use_runner_progress_effect.ts +41 -0
- package/src/hooks/use_runner_status.ts +27 -0
- package/src/hooks/use_runner_status_effect.ts +33 -0
- package/src/hooks/use_signal_value.ts +61 -0
- package/src/hooks/use_signal_value_effect.ts +68 -0
- package/src/hooks/use_update.ts +21 -0
- package/src/index.ts +21 -0
- package/tsconfig.json +23 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 TCN
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
@j13b/react-state
|
|
2
|
+
Copyright 2026 Jared J Barnes
|
|
3
|
+
|
|
4
|
+
This package contains the React bindings extracted from @j13b/state,
|
|
5
|
+
which is a fork of @tcn/state
|
|
6
|
+
(https://www.npmjs.com/package/@tcn/state):
|
|
7
|
+
|
|
8
|
+
Copyright 2024 TCN
|
|
9
|
+
Licensed under the Apache License, Version 2.0
|
|
10
|
+
|
|
11
|
+
The fork and all subsequent modifications by Jared J Barnes are also
|
|
12
|
+
distributed under the Apache License, Version 2.0. See LICENSE.
|
|
13
|
+
|
|
14
|
+
Files in this repository may have been modified from the @tcn/state
|
|
15
|
+
distribution. Refer to the git history for the complete record of
|
|
16
|
+
changes (Apache License 2.0 § 4(b)).
|
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @j13b/react-state
|
|
2
|
+
|
|
3
|
+
React bindings for [`@j13b/state`](https://github.com/jaredjbarnes/state) — hooks for subscribing to `Signal`s, `Runner`s, and broadcasts from React components.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @j13b/react-state @j13b/state
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Peer dependencies: `@j13b/state` (^0.2.0), `react` (^18.2.0), and `react-dom` (^18.2.0).
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { Signal } from "@j13b/state";
|
|
17
|
+
import { useSignalValue } from "@j13b/react-state";
|
|
18
|
+
|
|
19
|
+
const counter = new Signal(0);
|
|
20
|
+
|
|
21
|
+
function Counter() {
|
|
22
|
+
const value = useSignalValue(counter.broadcast);
|
|
23
|
+
return <button onClick={() => counter.set(value + 1)}>Count: {value}</button>;
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Hooks
|
|
28
|
+
|
|
29
|
+
| Hook | Returns / does |
|
|
30
|
+
|---|---|
|
|
31
|
+
| `useSignalValue(broadcast)` | Current value; re-renders on change. |
|
|
32
|
+
| `useSignalValueEffect(cb, broadcast)` | Runs `cb` on value changes without re-rendering. |
|
|
33
|
+
| `useUpdate()` | A function that forces a re-render. |
|
|
34
|
+
| `useRunnerStatus(broadcast)` | The runner's `Status` (INITIAL, PENDING, SUCCESS, ERROR). |
|
|
35
|
+
| `useRunnerStatusEffect(cb, task)` | Runs `cb` on status changes. |
|
|
36
|
+
| `useRunnerError(task)` | The runner's current `Error \| null`. |
|
|
37
|
+
| `useRunnerErrorEffect(cb, task)` | Runs `cb` on error changes. |
|
|
38
|
+
| `useRunnerProgress(task)` | The runner's progress (0–1). |
|
|
39
|
+
| `useRunnerProgressEffect(cb, task)` | Runs `cb` on progress changes. |
|
|
40
|
+
| `useRunnerFeedback(task)` | The runner's feedback message. |
|
|
41
|
+
| `useRunnerFeedbackEffect(cb, task)` | Runs `cb` on feedback changes. |
|
|
42
|
+
|
|
43
|
+
This package pairs with [`@j13b/state`](https://www.npmjs.com/package/@j13b/state), which provides the framework-agnostic primitives (`Signal`, `Runner`, `DerivedSignal`, events, and helpers) that these hooks subscribe to.
|
|
44
|
+
|
|
45
|
+
## Scripts
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm run build # vite + dts → dist/
|
|
49
|
+
npm run check:types # tsc --noEmit
|
|
50
|
+
npm test # vitest watch
|
|
51
|
+
npm run test:run # vitest run (CI)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Origins
|
|
55
|
+
|
|
56
|
+
These hooks were extracted from `@j13b/state`, which is a fork of [`@tcn/state`](https://www.npmjs.com/package/@tcn/state) (Copyright 2024 TCN). See [`NOTICE`](./NOTICE) for upstream attribution.
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
Apache License 2.0 — see [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,25 @@
|
|
|
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;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useRunnerError = useRunnerError;
|
|
4
|
+
const use_signal_value_js_1 = require("./use_signal_value.js");
|
|
5
|
+
/**
|
|
6
|
+
* A React hook that subscribes to the error state of a runner.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of value that the runner manages
|
|
9
|
+
* @param {IRunnerBroadcast<T>} task - The runner broadcast interface to subscribe to
|
|
10
|
+
* @returns {Error | null} The current error state of the runner, or null if there is no error
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const error = useRunnerError(saveRunner.broadcast);
|
|
15
|
+
* if (error) {
|
|
16
|
+
* return <ErrorMessage error={error} />;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* This hook is useful for:
|
|
22
|
+
* - Displaying error messages in the UI
|
|
23
|
+
* - Conditionally rendering error states
|
|
24
|
+
* - Triggering error handling logic
|
|
25
|
+
*
|
|
26
|
+
* The hook will automatically unsubscribe when the component unmounts.
|
|
27
|
+
*/
|
|
28
|
+
function useRunnerError(task) {
|
|
29
|
+
return (0, use_signal_value_js_1.useSignalValue)(task.stateBroadcast).error;
|
|
30
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useRunnerErrorEffect = useRunnerErrorEffect;
|
|
4
|
+
const use_signal_value_effect_js_1 = require("./use_signal_value_effect.js");
|
|
5
|
+
/**
|
|
6
|
+
* A React hook that executes a callback whenever the error state of a Runner changes.
|
|
7
|
+
* This hook is useful for handling side effects that need to respond to error states
|
|
8
|
+
* in async operations managed by a Runner.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of value managed by the Runner
|
|
11
|
+
* @param callback - A function that will be called with the current error state
|
|
12
|
+
* @param task - The Runner instance to monitor for error changes
|
|
13
|
+
* @returns void
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* useRunnerErrorEffect((error) => {
|
|
18
|
+
* if (error) {
|
|
19
|
+
* // Handle the error, e.g., show a notification
|
|
20
|
+
* showErrorNotification(error.message);
|
|
21
|
+
* }
|
|
22
|
+
* }, myRunner);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* - The callback will be called immediately with the current error state
|
|
27
|
+
* - The callback will be called whenever the error state changes
|
|
28
|
+
* - The hook automatically handles cleanup on component unmount
|
|
29
|
+
* - This hook is built on top of useSignalValueEffect for efficient state tracking
|
|
30
|
+
*/
|
|
31
|
+
function useRunnerErrorEffect(callback, task) {
|
|
32
|
+
return (0, use_signal_value_effect_js_1.useSignalValueEffect)(state => {
|
|
33
|
+
callback(state.error);
|
|
34
|
+
}, task.stateBroadcast);
|
|
35
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module hooks/use_runner_feedback
|
|
3
|
+
*
|
|
4
|
+
* This module provides a hook for accessing the feedback message from a Runner's state.
|
|
5
|
+
* It is useful for displaying status messages to users during async operations.
|
|
6
|
+
*/
|
|
7
|
+
import { IRunnerBroadcast } from '@j13b/state';
|
|
8
|
+
/**
|
|
9
|
+
* Hook that provides access to the feedback message from a Runner's state.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The type of the Runner's value
|
|
12
|
+
* @param {IRunnerBroadcast<T>} task - The Runner broadcast interface to subscribe to
|
|
13
|
+
* @returns {string | undefined} The current feedback message, or undefined if no feedback is set
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* const feedback = useRunnerFeedback(saveRunner.broadcast);
|
|
18
|
+
* return <div>{feedback}</div>;
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* This hook is useful for displaying status messages to users during async operations.
|
|
23
|
+
* The feedback message is typically set using the Runner's setFeedback method.
|
|
24
|
+
* The component will automatically re-render when the feedback message changes.
|
|
25
|
+
*/
|
|
26
|
+
export declare function useRunnerFeedback(task: IRunnerBroadcast<any>): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module hooks/use_runner_feedback
|
|
4
|
+
*
|
|
5
|
+
* This module provides a hook for accessing the feedback message from a Runner's state.
|
|
6
|
+
* It is useful for displaying status messages to users during async operations.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.useRunnerFeedback = useRunnerFeedback;
|
|
10
|
+
const use_signal_value_js_1 = require("./use_signal_value.js");
|
|
11
|
+
/**
|
|
12
|
+
* Hook that provides access to the feedback message from a Runner's state.
|
|
13
|
+
*
|
|
14
|
+
* @template T - The type of the Runner's value
|
|
15
|
+
* @param {IRunnerBroadcast<T>} task - The Runner broadcast interface to subscribe to
|
|
16
|
+
* @returns {string | undefined} The current feedback message, or undefined if no feedback is set
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* const feedback = useRunnerFeedback(saveRunner.broadcast);
|
|
21
|
+
* return <div>{feedback}</div>;
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* This hook is useful for displaying status messages to users during async operations.
|
|
26
|
+
* The feedback message is typically set using the Runner's setFeedback method.
|
|
27
|
+
* The component will automatically re-render when the feedback message changes.
|
|
28
|
+
*/
|
|
29
|
+
function useRunnerFeedback(task) {
|
|
30
|
+
return (0, use_signal_value_js_1.useSignalValue)(task.stateBroadcast).feedback;
|
|
31
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module hooks/use_runner_feedback_effect
|
|
3
|
+
*
|
|
4
|
+
* This module provides a React hook for handling feedback messages from a Runner.
|
|
5
|
+
* It allows components to react to changes in the feedback state of async operations.
|
|
6
|
+
*/
|
|
7
|
+
import { IRunnerBroadcast } from '@j13b/state';
|
|
8
|
+
/**
|
|
9
|
+
* A React hook that executes a callback whenever the feedback message of a Runner changes.
|
|
10
|
+
*
|
|
11
|
+
* This hook is useful for displaying operation feedback to users, such as loading messages,
|
|
12
|
+
* progress updates, or error notifications. It automatically handles cleanup when the
|
|
13
|
+
* component unmounts.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* useRunnerFeedbackEffect(
|
|
18
|
+
* (feedback) => {
|
|
19
|
+
* // Update UI with feedback message
|
|
20
|
+
* setMessage(feedback);
|
|
21
|
+
* },
|
|
22
|
+
* myRunner.broadcast
|
|
23
|
+
* );
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @param callback - A function that will be called with the new feedback message whenever it changes
|
|
27
|
+
* @param task - The Runner's broadcast interface to subscribe to
|
|
28
|
+
* @returns void
|
|
29
|
+
*/
|
|
30
|
+
export declare function useRunnerFeedbackEffect(callback: (feedback: string) => void, task: IRunnerBroadcast<any>): void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module hooks/use_runner_feedback_effect
|
|
4
|
+
*
|
|
5
|
+
* This module provides a React hook for handling feedback messages from a Runner.
|
|
6
|
+
* It allows components to react to changes in the feedback state of async operations.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.useRunnerFeedbackEffect = useRunnerFeedbackEffect;
|
|
10
|
+
const use_signal_value_effect_js_1 = require("./use_signal_value_effect.js");
|
|
11
|
+
/**
|
|
12
|
+
* A React hook that executes a callback whenever the feedback message of a Runner changes.
|
|
13
|
+
*
|
|
14
|
+
* This hook is useful for displaying operation feedback to users, such as loading messages,
|
|
15
|
+
* progress updates, or error notifications. It automatically handles cleanup when the
|
|
16
|
+
* component unmounts.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* useRunnerFeedbackEffect(
|
|
21
|
+
* (feedback) => {
|
|
22
|
+
* // Update UI with feedback message
|
|
23
|
+
* setMessage(feedback);
|
|
24
|
+
* },
|
|
25
|
+
* myRunner.broadcast
|
|
26
|
+
* );
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param callback - A function that will be called with the new feedback message whenever it changes
|
|
30
|
+
* @param task - The Runner's broadcast interface to subscribe to
|
|
31
|
+
* @returns void
|
|
32
|
+
*/
|
|
33
|
+
function useRunnerFeedbackEffect(callback, task) {
|
|
34
|
+
return (0, use_signal_value_effect_js_1.useSignalValueEffect)(state => {
|
|
35
|
+
callback(state.feedback);
|
|
36
|
+
}, task.stateBroadcast);
|
|
37
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A React hook that subscribes to the progress state of a Runner.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of the Runner's value
|
|
5
|
+
* @param {IRunnerBroadcast<T>} task - The Runner broadcast interface to subscribe to
|
|
6
|
+
* @returns {number} A number between 0 and 1 representing the current progress of the task
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const progress = useRunnerProgress(saveRunner.broadcast);
|
|
11
|
+
* // progress will be a number between 0 and 1
|
|
12
|
+
* // 0 = not started, 1 = complete
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* This hook is useful for tracking the progress of long-running operations
|
|
17
|
+
* such as file uploads, data processing, or any task that can report progress.
|
|
18
|
+
* The component will automatically re-render when the progress value changes.
|
|
19
|
+
*/
|
|
20
|
+
import { IRunnerBroadcast } from '@j13b/state';
|
|
21
|
+
export declare function useRunnerProgress(task: IRunnerBroadcast<any>): number;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useRunnerProgress = useRunnerProgress;
|
|
4
|
+
const use_signal_value_js_1 = require("./use_signal_value.js");
|
|
5
|
+
function useRunnerProgress(task) {
|
|
6
|
+
return (0, use_signal_value_js_1.useSignalValue)(task.stateBroadcast).progress;
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module hooks/use_runner_progress_effect
|
|
3
|
+
*
|
|
4
|
+
* This module provides a React hook for tracking the progress of a Runner operation.
|
|
5
|
+
* It allows components to react to progress changes in long-running operations.
|
|
6
|
+
*/
|
|
7
|
+
import { IRunnerBroadcast } from '@j13b/state';
|
|
8
|
+
/**
|
|
9
|
+
* Hook that executes a callback whenever the progress of a Runner operation changes.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The type of the Runner's value
|
|
12
|
+
* @param callback - Function to be called when progress changes. Receives the current progress value (0-1)
|
|
13
|
+
* @param task - The Runner broadcast interface to track progress from
|
|
14
|
+
* @returns void
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* useRunnerProgressEffect(
|
|
19
|
+
* (progress) => {
|
|
20
|
+
* console.log(`Operation is ${progress * 100}% complete`);
|
|
21
|
+
* },
|
|
22
|
+
* myRunner.broadcast
|
|
23
|
+
* );
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* - The callback will be called with a number between 0 and 1 representing progress
|
|
28
|
+
* - The effect is automatically cleaned up when the component unmounts
|
|
29
|
+
* - This hook is built on top of useSignalValueEffect for efficient state tracking
|
|
30
|
+
*/
|
|
31
|
+
export declare function useRunnerProgressEffect(callback: (progress: number) => void, task: IRunnerBroadcast<any>): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module hooks/use_runner_progress_effect
|
|
4
|
+
*
|
|
5
|
+
* This module provides a React hook for tracking the progress of a Runner operation.
|
|
6
|
+
* It allows components to react to progress changes in long-running operations.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.useRunnerProgressEffect = useRunnerProgressEffect;
|
|
10
|
+
const use_signal_value_effect_js_1 = require("./use_signal_value_effect.js");
|
|
11
|
+
/**
|
|
12
|
+
* Hook that executes a callback whenever the progress of a Runner operation changes.
|
|
13
|
+
*
|
|
14
|
+
* @template T - The type of the Runner's value
|
|
15
|
+
* @param callback - Function to be called when progress changes. Receives the current progress value (0-1)
|
|
16
|
+
* @param task - The Runner broadcast interface to track progress from
|
|
17
|
+
* @returns void
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* useRunnerProgressEffect(
|
|
22
|
+
* (progress) => {
|
|
23
|
+
* console.log(`Operation is ${progress * 100}% complete`);
|
|
24
|
+
* },
|
|
25
|
+
* myRunner.broadcast
|
|
26
|
+
* );
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* - The callback will be called with a number between 0 and 1 representing progress
|
|
31
|
+
* - The effect is automatically cleaned up when the component unmounts
|
|
32
|
+
* - This hook is built on top of useSignalValueEffect for efficient state tracking
|
|
33
|
+
*/
|
|
34
|
+
function useRunnerProgressEffect(callback, task) {
|
|
35
|
+
return (0, use_signal_value_effect_js_1.useSignalValueEffect)(state => {
|
|
36
|
+
callback(state.progress);
|
|
37
|
+
}, task.stateBroadcast);
|
|
38
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IRunnerBroadcast } from '@j13b/state';
|
|
2
|
+
/**
|
|
3
|
+
* A hook that subscribes to a runner's status changes and returns the current status.
|
|
4
|
+
* The component will re-render whenever the runner's status changes.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of the runner's value
|
|
7
|
+
* @param broadcast - The broadcast interface of the runner to subscribe to
|
|
8
|
+
* @returns The current status of the runner (INITIAL, PENDING, SUCCESS, ERROR)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const status = useRunnerStatus(runner.broadcast);
|
|
13
|
+
*
|
|
14
|
+
* return (
|
|
15
|
+
* <div>
|
|
16
|
+
* {status === 'PENDING' && <Spinner />}
|
|
17
|
+
* {status === 'ERROR' && <ErrorMessage />}
|
|
18
|
+
* {status === 'SUCCESS' && <SuccessMessage />}
|
|
19
|
+
* </div>
|
|
20
|
+
* );
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function useRunnerStatus(broadcast: IRunnerBroadcast<any>): import("@j13b/state").Status;
|