chizu 0.2.18 → 0.2.19
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 +3 -3
- package/dist/broadcast/utils.d.ts +7 -0
- package/dist/chizu.js +231 -177
- package/dist/chizu.umd.cjs +1 -1
- package/dist/controller/types.d.ts +2 -2
- package/dist/errors/index.d.ts +9 -0
- package/dist/errors/types.d.ts +15 -0
- package/dist/errors/utils.d.ts +37 -0
- package/dist/index.d.ts +1 -1
- package/dist/module/renderer/dispatchers/types.d.ts +4 -1
- package/dist/module/renderer/dispatchers/utils.d.ts +0 -21
- package/dist/module/renderer/index.d.ts +1 -1
- package/dist/module/renderer/types.d.ts +5 -1
- package/dist/module/types.d.ts +3 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/view/types.d.ts +3 -0
- package/package.json +1 -1
- /package/dist/{module/renderer/dispatchers → broadcast}/utils.test.d.ts +0 -0
package/README.md
CHANGED
|
@@ -143,7 +143,7 @@ export default function ProfileView(props: Props): React.ReactElement {
|
|
|
143
143
|
|
|
144
144
|
## Error handling
|
|
145
145
|
|
|
146
|
-
Actions can throw errors directly or in any of their associated `yield` actions – all unhandled errors are automatically caught and
|
|
146
|
+
Actions can throw errors directly or in any of their associated `yield` actions – all unhandled errors are automatically caught and dispatched using the `Lifecycle.Error` action – you can render these [in a toast](https://github.com/fkhadra/react-toastify#readme) or similar UI.
|
|
147
147
|
|
|
148
148
|
You can also customise these errors a little further with your own error `enum` which describes the error type:
|
|
149
149
|
|
|
@@ -166,7 +166,7 @@ export default <Actions<Module>>function Actions(module) {
|
|
|
166
166
|
|
|
167
167
|
const name = await fetch(/* ... */);
|
|
168
168
|
|
|
169
|
-
if (!name) throw new
|
|
169
|
+
if (!name) throw new ActionError(Errors.UserValidation);
|
|
170
170
|
|
|
171
171
|
return module.actions.produce((draft) => {
|
|
172
172
|
draft.name = name;
|
|
@@ -190,7 +190,7 @@ export default <Actions<Module>>function Actions(module) {
|
|
|
190
190
|
|
|
191
191
|
if (!name) {
|
|
192
192
|
return module.actions.produce((draft) => {
|
|
193
|
-
draft.name = Maybe.of(new
|
|
193
|
+
draft.name = Maybe.of(new ActionError(Errors.UserValidation));
|
|
194
194
|
});
|
|
195
195
|
}
|
|
196
196
|
|
package/dist/chizu.js
CHANGED
|
@@ -1,35 +1,50 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var I = Object.defineProperty;
|
|
2
|
+
var j = (t) => {
|
|
3
3
|
throw TypeError(t);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var y = (t, e, n) => (
|
|
8
|
-
import { jsx as
|
|
5
|
+
var J = (t, e, n) => e in t ? I(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
6
|
+
var R = (t, e, n) => J(t, typeof e != "symbol" ? e + "" : e, n), A = (t, e, n) => e.has(t) || j("Cannot " + n);
|
|
7
|
+
var y = (t, e, n) => (A(t, e, "read from private field"), n ? n.call(t) : e.get(t)), w = (t, e, n) => e.has(t) ? j("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, n), b = (t, e, n, r) => (A(t, e, "write to private field"), r ? r.call(t, n) : e.set(t, n), n);
|
|
8
|
+
import { jsx as x, Fragment as Q } from "react/jsx-runtime";
|
|
9
9
|
import * as c from "react";
|
|
10
|
-
import
|
|
11
|
-
import { Immer as
|
|
12
|
-
import
|
|
13
|
-
import
|
|
10
|
+
import D from "eventemitter3";
|
|
11
|
+
import { Immer as W } from "immer";
|
|
12
|
+
import p from "lodash/get";
|
|
13
|
+
import C from "traverse";
|
|
14
14
|
class U {
|
|
15
15
|
constructor(e) {
|
|
16
16
|
this.value = e;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
class
|
|
19
|
+
class G {
|
|
20
20
|
static Draft(e) {
|
|
21
21
|
return new U(e);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
R(G, "Op", {
|
|
25
25
|
Add: 1,
|
|
26
26
|
Remove: 2,
|
|
27
27
|
Update: 4,
|
|
28
28
|
Move: 8,
|
|
29
29
|
Replace: 16
|
|
30
30
|
});
|
|
31
|
-
var h = /* @__PURE__ */ ((t) => (t.Mount = "lifecycle/mount", t.Node = "lifecycle/node", t.Derive = "lifecycle/derive", t.Error = "
|
|
32
|
-
function
|
|
31
|
+
var h = /* @__PURE__ */ ((t) => (t.Mount = "lifecycle/mount", t.Node = "lifecycle/node", t.Derive = "lifecycle/derive", t.Error = "lifecycle/error", t.Unmount = "lifecycle/unmount", t))(h || {});
|
|
32
|
+
function K(t) {
|
|
33
|
+
return new Promise((e) => setTimeout(e, t));
|
|
34
|
+
}
|
|
35
|
+
function V(t) {
|
|
36
|
+
return t ? !!(t && typeof t != "symbol") : Symbol(`pk.${Date.now()}.${crypto.randomUUID()}`);
|
|
37
|
+
}
|
|
38
|
+
function m(t) {
|
|
39
|
+
return JSON.stringify(t);
|
|
40
|
+
}
|
|
41
|
+
const Et = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
42
|
+
__proto__: null,
|
|
43
|
+
hash: m,
|
|
44
|
+
pk: V,
|
|
45
|
+
sleep: K
|
|
46
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
47
|
+
function f(t, e) {
|
|
33
48
|
const n = c.useRef(null), r = c.useRef(null);
|
|
34
49
|
return c.useMemo(() => {
|
|
35
50
|
const s = m(e);
|
|
@@ -41,7 +56,7 @@ function d(t, e) {
|
|
|
41
56
|
return n.current;
|
|
42
57
|
}, e);
|
|
43
58
|
}
|
|
44
|
-
function
|
|
59
|
+
function B(t, e) {
|
|
45
60
|
const n = c.useRef(null);
|
|
46
61
|
c.useEffect(() => {
|
|
47
62
|
const r = m(e);
|
|
@@ -50,127 +65,127 @@ function O(t, e) {
|
|
|
50
65
|
}, e);
|
|
51
66
|
}
|
|
52
67
|
const _ = c.createContext({
|
|
53
|
-
appEmitter: new
|
|
68
|
+
appEmitter: new D()
|
|
54
69
|
});
|
|
55
|
-
function
|
|
70
|
+
function H() {
|
|
56
71
|
return c.useContext(_);
|
|
57
72
|
}
|
|
58
|
-
function
|
|
59
|
-
const e =
|
|
73
|
+
function gt({ children: t }) {
|
|
74
|
+
const e = f(
|
|
60
75
|
() => ({
|
|
61
|
-
appEmitter: new
|
|
76
|
+
appEmitter: new D()
|
|
62
77
|
}),
|
|
63
78
|
[]
|
|
64
79
|
);
|
|
65
|
-
return /* @__PURE__ */
|
|
80
|
+
return /* @__PURE__ */ x(_.Provider, { value: e, children: t });
|
|
66
81
|
}
|
|
67
|
-
const
|
|
68
|
-
immer: new
|
|
82
|
+
const a = {
|
|
83
|
+
immer: new W(),
|
|
69
84
|
annotations: Symbol("annotations")
|
|
70
85
|
};
|
|
71
|
-
|
|
72
|
-
class
|
|
86
|
+
a.immer.setAutoFreeze(!1);
|
|
87
|
+
class P {
|
|
73
88
|
constructor(e, n, r = null) {
|
|
74
|
-
|
|
89
|
+
R(this, "process");
|
|
75
90
|
this.value = e, this.operations = n, this.field = r, this.process = null;
|
|
76
91
|
}
|
|
77
92
|
attach(e) {
|
|
78
93
|
return this.process = e, this;
|
|
79
94
|
}
|
|
80
95
|
}
|
|
81
|
-
function
|
|
82
|
-
return new
|
|
96
|
+
function X(t, e = []) {
|
|
97
|
+
return new P(t, e);
|
|
83
98
|
}
|
|
84
99
|
class k {
|
|
85
100
|
constructor(e, n = e) {
|
|
86
101
|
this.stateless = e, this.stateful = n;
|
|
87
102
|
}
|
|
88
103
|
get validatable() {
|
|
89
|
-
return
|
|
104
|
+
return T(this.stateful);
|
|
90
105
|
}
|
|
91
106
|
}
|
|
92
|
-
function
|
|
107
|
+
function T(t, e = []) {
|
|
93
108
|
return new Proxy(t, {
|
|
94
109
|
get(n, r) {
|
|
95
110
|
switch (r) {
|
|
96
111
|
case "is":
|
|
97
112
|
return (s) => {
|
|
98
|
-
const o =
|
|
113
|
+
const o = S(t, e);
|
|
99
114
|
if (!o) return !1;
|
|
100
115
|
const u = new Set(
|
|
101
|
-
o.flatMap((
|
|
116
|
+
o.flatMap((l) => l.operations)
|
|
102
117
|
);
|
|
103
118
|
return !!(Array.from(u).reduce(
|
|
104
|
-
(
|
|
119
|
+
(l, d) => l | (d ?? 0),
|
|
105
120
|
0
|
|
106
121
|
) & s);
|
|
107
122
|
};
|
|
108
123
|
case "pending":
|
|
109
|
-
return () => !!
|
|
124
|
+
return () => !!S(t, e);
|
|
110
125
|
case "draft":
|
|
111
126
|
return () => {
|
|
112
|
-
const s =
|
|
113
|
-
if (!s) return
|
|
127
|
+
const s = S(t, e);
|
|
128
|
+
if (!s) return p(t, e);
|
|
114
129
|
const o = s.flatMap((u) => u.operations).find((u) => u instanceof U);
|
|
115
|
-
return o ? o.value :
|
|
130
|
+
return o ? o.value : p(t, e);
|
|
116
131
|
};
|
|
117
132
|
}
|
|
118
|
-
return
|
|
133
|
+
return T(t, [...e, String(r)]);
|
|
119
134
|
}
|
|
120
135
|
});
|
|
121
136
|
}
|
|
122
|
-
function
|
|
123
|
-
const r = typeof
|
|
137
|
+
function S(t, e) {
|
|
138
|
+
const r = typeof p(t, e) == "object" ? e : e.slice(0, -1), s = r.length === 0 ? t : p(t, r), o = (s == null ? void 0 : s[a.annotations]) ?? [];
|
|
124
139
|
return o.length > 0 ? o : null;
|
|
125
140
|
}
|
|
126
|
-
function
|
|
141
|
+
function Y(t, e, n) {
|
|
127
142
|
function r(o) {
|
|
128
|
-
return
|
|
129
|
-
if (this.key ===
|
|
143
|
+
return C(o).forEach(function() {
|
|
144
|
+
if (this.key === a.annotations) {
|
|
130
145
|
this.block();
|
|
131
146
|
return;
|
|
132
147
|
}
|
|
133
|
-
this.node instanceof
|
|
148
|
+
this.node instanceof P && this.update(this.node.value);
|
|
134
149
|
});
|
|
135
150
|
}
|
|
136
151
|
function s(o) {
|
|
137
|
-
return
|
|
138
|
-
if (this.key ===
|
|
152
|
+
return C(o).forEach(function() {
|
|
153
|
+
if (this.key === a.annotations) {
|
|
139
154
|
this.block();
|
|
140
155
|
return;
|
|
141
156
|
}
|
|
142
|
-
if (this.node instanceof
|
|
157
|
+
if (this.node instanceof P) {
|
|
143
158
|
const u = typeof this.node.value == "object", i = [
|
|
144
159
|
...u ? this.path : this.path.slice(0, -1),
|
|
145
|
-
|
|
146
|
-
],
|
|
160
|
+
a.annotations
|
|
161
|
+
], l = p(t.stateful, i) ?? [], d = this.node.attach(e);
|
|
147
162
|
u ? this.update(
|
|
148
163
|
{
|
|
149
164
|
...this.node.value,
|
|
150
|
-
[
|
|
165
|
+
[a.annotations]: [d, ...l]
|
|
151
166
|
},
|
|
152
167
|
!0
|
|
153
|
-
) : (this.parent && (this.parent.node[
|
|
168
|
+
) : (this.parent && (this.parent.node[a.annotations] = [d, ...l]), this.update(this.node.value, !0));
|
|
154
169
|
}
|
|
155
170
|
});
|
|
156
171
|
}
|
|
157
172
|
return new k(
|
|
158
|
-
r(
|
|
159
|
-
s(
|
|
173
|
+
r(a.immer.produce(t.stateless, n)),
|
|
174
|
+
s(a.immer.produce(t.stateful, n))
|
|
160
175
|
);
|
|
161
176
|
}
|
|
162
|
-
function
|
|
163
|
-
const n =
|
|
164
|
-
if (this.key ===
|
|
177
|
+
function M(t, e) {
|
|
178
|
+
const n = C(t.stateful).forEach(function() {
|
|
179
|
+
if (this.key === a.annotations) {
|
|
165
180
|
this.block();
|
|
166
181
|
return;
|
|
167
182
|
}
|
|
168
|
-
if (this.node && this.node[
|
|
169
|
-
const r = this.node[
|
|
183
|
+
if (this.node && this.node[a.annotations]) {
|
|
184
|
+
const r = this.node[a.annotations];
|
|
170
185
|
this.update(
|
|
171
186
|
{
|
|
172
187
|
...this.node,
|
|
173
|
-
[
|
|
188
|
+
[a.annotations]: r.filter(
|
|
174
189
|
(s) => s.process !== e
|
|
175
190
|
)
|
|
176
191
|
},
|
|
@@ -180,73 +195,8 @@ function R(t, e) {
|
|
|
180
195
|
});
|
|
181
196
|
return new k(t.stateless, n);
|
|
182
197
|
}
|
|
183
|
-
function
|
|
184
|
-
|
|
185
|
-
return (n, r) => async (s = Promise.withResolvers(), o) => {
|
|
186
|
-
if (typeof r != "function") return;
|
|
187
|
-
const u = Symbol("process"), i = r(...o);
|
|
188
|
-
try {
|
|
189
|
-
if (i == null) return;
|
|
190
|
-
if (typeof i == "function") {
|
|
191
|
-
const a = i(t.model.current, u);
|
|
192
|
-
t.model.current = R(a, u), t.update.rerender(), s.resolve();
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
for (; ; ) {
|
|
196
|
-
const { value: a, done: f } = await i.next();
|
|
197
|
-
if (f) {
|
|
198
|
-
const $ = a(t.model.current, u);
|
|
199
|
-
t.model.current = R($, u), t.update.rerender();
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
const T = a;
|
|
203
|
-
t.model.current = T(t.model.current, u), t.update.rerender(), s.resolve();
|
|
204
|
-
}
|
|
205
|
-
} catch (a) {
|
|
206
|
-
R(t.model.current, u), t.update.rerender(), e.appEmitter.emit(h.Error, s, [a]);
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
function B(t) {
|
|
211
|
-
return t.startsWith("distributed");
|
|
212
|
-
}
|
|
213
|
-
var p, E;
|
|
214
|
-
class G extends Error {
|
|
215
|
-
constructor(n, r = null) {
|
|
216
|
-
super(String(r));
|
|
217
|
-
g(this, p);
|
|
218
|
-
g(this, E);
|
|
219
|
-
b(this, p, n), b(this, E, r);
|
|
220
|
-
}
|
|
221
|
-
get type() {
|
|
222
|
-
return y(this, p);
|
|
223
|
-
}
|
|
224
|
-
get message() {
|
|
225
|
-
return y(this, E) || "";
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
p = new WeakMap(), E = new WeakMap();
|
|
229
|
-
function K(t) {
|
|
230
|
-
return new Promise((e) => setTimeout(e, t));
|
|
231
|
-
}
|
|
232
|
-
function V(t) {
|
|
233
|
-
return t ? !!(t && typeof t != "symbol") : Symbol(`pk.${Date.now()}.${crypto.randomUUID()}`);
|
|
234
|
-
}
|
|
235
|
-
function X(t) {
|
|
236
|
-
return t instanceof G;
|
|
237
|
-
}
|
|
238
|
-
function m(t) {
|
|
239
|
-
return JSON.stringify(t);
|
|
240
|
-
}
|
|
241
|
-
const mt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
242
|
-
__proto__: null,
|
|
243
|
-
hash: m,
|
|
244
|
-
isEventError: X,
|
|
245
|
-
pk: V,
|
|
246
|
-
sleep: K
|
|
247
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
248
|
-
function Y(t) {
|
|
249
|
-
return d(
|
|
198
|
+
function Z(t) {
|
|
199
|
+
return f(
|
|
250
200
|
() => ({
|
|
251
201
|
controller: {
|
|
252
202
|
get model() {
|
|
@@ -255,10 +205,10 @@ function Y(t) {
|
|
|
255
205
|
queue: [],
|
|
256
206
|
actions: {
|
|
257
207
|
annotate(e, n) {
|
|
258
|
-
return
|
|
208
|
+
return X(e, n);
|
|
259
209
|
},
|
|
260
210
|
produce(e) {
|
|
261
|
-
return (n, r) =>
|
|
211
|
+
return (n, r) => Y(n, r, e);
|
|
262
212
|
},
|
|
263
213
|
dispatch([e, ...n]) {
|
|
264
214
|
if (e == null) return Promise.reject();
|
|
@@ -268,6 +218,7 @@ function Y(t) {
|
|
|
268
218
|
}
|
|
269
219
|
},
|
|
270
220
|
view: {
|
|
221
|
+
error: !1,
|
|
271
222
|
get model() {
|
|
272
223
|
return t.model.current.stateless;
|
|
273
224
|
},
|
|
@@ -275,6 +226,10 @@ function Y(t) {
|
|
|
275
226
|
return t.model.current.validatable;
|
|
276
227
|
},
|
|
277
228
|
actions: {
|
|
229
|
+
retry: () => {
|
|
230
|
+
},
|
|
231
|
+
remount: () => {
|
|
232
|
+
},
|
|
278
233
|
dispatch([e, ...n]) {
|
|
279
234
|
if (e == null) return Promise.reject();
|
|
280
235
|
const r = Promise.withResolvers();
|
|
@@ -286,88 +241,187 @@ function Y(t) {
|
|
|
286
241
|
[]
|
|
287
242
|
);
|
|
288
243
|
}
|
|
289
|
-
function
|
|
290
|
-
return
|
|
244
|
+
function L(t) {
|
|
245
|
+
return f(() => {
|
|
291
246
|
const e = t.options.using.actions(t.actions.controller);
|
|
292
247
|
return Object.entries(e).forEach(([r, s]) => t.dispatchers.attach(r, s)), e;
|
|
293
248
|
}, []);
|
|
294
249
|
}
|
|
295
|
-
function
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
250
|
+
function O(t) {
|
|
251
|
+
return t.startsWith("distributed");
|
|
252
|
+
}
|
|
253
|
+
function yt(t) {
|
|
254
|
+
return t instanceof z;
|
|
255
|
+
}
|
|
256
|
+
function wt(t) {
|
|
257
|
+
return t instanceof F;
|
|
258
|
+
}
|
|
259
|
+
function $(t) {
|
|
260
|
+
return t instanceof z || t instanceof F || t instanceof Error ? t : new Error("Unknown error", { cause: t });
|
|
261
|
+
}
|
|
262
|
+
var v, E;
|
|
263
|
+
class z extends Error {
|
|
264
|
+
constructor(n, r = null) {
|
|
265
|
+
super(String(r));
|
|
266
|
+
w(this, v);
|
|
267
|
+
w(this, E);
|
|
268
|
+
b(this, v, n), b(this, E, r);
|
|
269
|
+
}
|
|
270
|
+
get type() {
|
|
271
|
+
return y(this, v);
|
|
272
|
+
}
|
|
273
|
+
get message() {
|
|
274
|
+
return y(this, E) || "";
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
v = new WeakMap(), E = new WeakMap();
|
|
278
|
+
var g;
|
|
279
|
+
class F extends Error {
|
|
280
|
+
constructor(n = null) {
|
|
281
|
+
super(String(n));
|
|
282
|
+
w(this, g);
|
|
283
|
+
b(this, g, n);
|
|
284
|
+
}
|
|
285
|
+
get message() {
|
|
286
|
+
return y(this, g) || "";
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
g = new WeakMap();
|
|
290
|
+
function tt(t) {
|
|
291
|
+
return (e, n) => async (r = Promise.withResolvers(), s) => {
|
|
292
|
+
if (typeof n != "function") return;
|
|
293
|
+
const o = Symbol("process"), u = n(...s);
|
|
294
|
+
try {
|
|
295
|
+
if (u == null) return;
|
|
296
|
+
if (typeof u == "function") {
|
|
297
|
+
const i = u(t.model.current, o);
|
|
298
|
+
t.model.current = M(i, o), t.update.rerender(), r.resolve();
|
|
299
|
+
return;
|
|
307
300
|
}
|
|
308
|
-
|
|
309
|
-
|
|
301
|
+
for (; ; ) {
|
|
302
|
+
const { value: i, done: l } = await u.next();
|
|
303
|
+
if (l) {
|
|
304
|
+
const q = i(t.model.current, o);
|
|
305
|
+
t.model.current = M(q, o), t.update.rerender();
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
const d = i;
|
|
309
|
+
t.model.current = d(t.model.current, o), t.update.rerender(), r.resolve();
|
|
310
|
+
}
|
|
311
|
+
} catch (i) {
|
|
312
|
+
M(t.model.current, o), t.update.rerender(), t.unicast.emit(h.Error, r, [$(i)]);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function et(t) {
|
|
317
|
+
const e = H(), n = f(() => new D(), []), r = tt({ ...t, unicast: n });
|
|
318
|
+
return f(() => ({
|
|
319
|
+
attach(s, o) {
|
|
320
|
+
const u = String(s);
|
|
321
|
+
O(u) ? e.appEmitter.on(u, r(s, o)) : n.on(u, r(s, o));
|
|
322
|
+
},
|
|
323
|
+
dispatch(s, o, u) {
|
|
324
|
+
const i = String(s);
|
|
325
|
+
O(i) ? e.appEmitter.emit(i, u, o) : n.emit(i, u, o);
|
|
326
|
+
}
|
|
327
|
+
}), []);
|
|
310
328
|
}
|
|
311
|
-
function
|
|
329
|
+
function nt() {
|
|
312
330
|
const t = c.useRef(null);
|
|
313
|
-
return
|
|
331
|
+
return f(() => ({ customElement: t }), []);
|
|
314
332
|
}
|
|
315
|
-
function
|
|
316
|
-
|
|
333
|
+
function rt(t) {
|
|
334
|
+
B(() => {
|
|
317
335
|
t.dispatchers.dispatch(h.Derive, []);
|
|
318
|
-
}, [t.options.using.props]),
|
|
336
|
+
}, [t.options.using.props]), B(() => (t.dispatchers.dispatch(h.Mount, []), t.dispatchers.dispatch(h.Node, [
|
|
319
337
|
t.elements.customElement.current
|
|
320
338
|
]), () => t.dispatchers.dispatch(h.Unmount, [])), []);
|
|
321
339
|
}
|
|
322
|
-
function
|
|
323
|
-
const e =
|
|
340
|
+
function ot(t) {
|
|
341
|
+
const e = f(() => t.options.using.model ?? {}, []);
|
|
324
342
|
return c.useRef(new k(e, e));
|
|
325
343
|
}
|
|
326
|
-
function
|
|
344
|
+
function st() {
|
|
327
345
|
return c.useRef(/* @__PURE__ */ new Set());
|
|
328
346
|
}
|
|
329
|
-
function
|
|
347
|
+
function ut() {
|
|
330
348
|
const [t, e] = c.useReducer((n) => n + 1, 0);
|
|
331
|
-
return
|
|
349
|
+
return f(() => ({ hash: t, rerender: e }), [t]);
|
|
332
350
|
}
|
|
333
|
-
const
|
|
351
|
+
const N = c.createContext(
|
|
334
352
|
null
|
|
335
353
|
);
|
|
336
|
-
function
|
|
337
|
-
const t = c.useContext(
|
|
354
|
+
function bt() {
|
|
355
|
+
const t = c.useContext(N);
|
|
338
356
|
if (!t) throw new Error("useModule must be used within a module.");
|
|
339
357
|
return t;
|
|
340
358
|
}
|
|
341
|
-
|
|
359
|
+
class ct extends c.Component {
|
|
360
|
+
constructor(e) {
|
|
361
|
+
super(e), this.state = { errored: !1 };
|
|
362
|
+
}
|
|
363
|
+
static getDerivedStateFromError() {
|
|
364
|
+
return { errored: !0 };
|
|
365
|
+
}
|
|
366
|
+
componentDidCatch(e) {
|
|
367
|
+
this.props.module.actions.dispatch([h.Error, [$(e)]]);
|
|
368
|
+
}
|
|
369
|
+
render() {
|
|
370
|
+
const e = () => this.setState({ errored: !1 });
|
|
371
|
+
return this.props.children({ error: this.state.errored, retry: e });
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
function it({
|
|
342
375
|
options: t
|
|
343
376
|
}) {
|
|
344
|
-
const e =
|
|
377
|
+
const e = ut(), n = st(), r = nt(), s = H(), o = ot({ options: t }), u = et({
|
|
345
378
|
broadcast: s,
|
|
346
379
|
options: t,
|
|
347
380
|
update: e,
|
|
348
381
|
model: o,
|
|
349
382
|
queue: n
|
|
350
|
-
}), i =
|
|
351
|
-
return
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
383
|
+
}), i = Z({ model: o, dispatchers: u });
|
|
384
|
+
return L({ options: t, dispatchers: u, actions: i }), rt({ options: t, dispatchers: u, elements: r }), f(() => c.createElement(ct, {
|
|
385
|
+
module: i.view,
|
|
386
|
+
children(l) {
|
|
387
|
+
const d = {
|
|
388
|
+
...i.view,
|
|
389
|
+
error: l.error,
|
|
390
|
+
actions: {
|
|
391
|
+
...i.view.actions,
|
|
392
|
+
retry: l.retry,
|
|
393
|
+
remount: t.remount
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
return c.createElement(N.Provider, {
|
|
397
|
+
value: d,
|
|
398
|
+
// eslint-disable-next-line react/no-children-prop
|
|
399
|
+
children: c.createElement("x-chizu", {
|
|
400
|
+
ref: r.customElement,
|
|
401
|
+
style: { display: "contents" },
|
|
402
|
+
children: t.children(d)
|
|
403
|
+
})
|
|
404
|
+
});
|
|
405
|
+
}
|
|
359
406
|
}), [e.hash, m(t.using.props)]);
|
|
360
407
|
}
|
|
361
|
-
function
|
|
362
|
-
return
|
|
408
|
+
function at({ children: t }) {
|
|
409
|
+
return /* @__PURE__ */ x(Q, { children: t });
|
|
410
|
+
}
|
|
411
|
+
function lt(t) {
|
|
412
|
+
const [e, n] = c.useReducer((r) => r + 1, 0);
|
|
413
|
+
return /* @__PURE__ */ x(at, { children: /* @__PURE__ */ x(it, { options: { ...t, remount: n } }) }, e);
|
|
363
414
|
}
|
|
364
|
-
const
|
|
415
|
+
const xt = c.memo(lt, (t, e) => m(t) === m(e));
|
|
365
416
|
export {
|
|
366
|
-
|
|
367
|
-
|
|
417
|
+
z as ActionError,
|
|
418
|
+
gt as BroadcastProvider,
|
|
419
|
+
F as ComponentError,
|
|
368
420
|
h as Lifecycle,
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
421
|
+
G as State,
|
|
422
|
+
xt as Tree,
|
|
423
|
+
yt as isActionError,
|
|
424
|
+
wt as isComponentError,
|
|
425
|
+
bt as useModule,
|
|
426
|
+
Et as utils
|
|
373
427
|
};
|
package/dist/chizu.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(o,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react/jsx-runtime"),require("react"),require("eventemitter3"),require("immer"),require("lodash/get"),require("traverse")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","eventemitter3","immer","lodash/get","traverse"],u):(o=typeof globalThis<"u"?globalThis:o||self,u(o.Chizu={},o.jsxRuntime,o.React,o.EventEmitter3,o.Immer,o.get,o.Traverse))})(this,function(o,u,d,y,Q,w,C){"use strict";var ye=Object.defineProperty;var I=o=>{throw TypeError(o)};var Ee=(o,u,d)=>u in o?ye(o,u,{enumerable:!0,configurable:!0,writable:!0,value:d}):o[u]=d;var T=(o,u,d)=>Ee(o,typeof u!="symbol"?u+"":u,d),J=(o,u,d)=>u.has(o)||I("Cannot "+d);var j=(o,u,d)=>(J(o,u,"read from private field"),d?d.call(o):u.get(o)),M=(o,u,d)=>u.has(o)?I("Cannot add the same private member more than once"):u instanceof WeakSet?u.add(o):u.set(o,d),P=(o,u,d,y)=>(J(o,u,"write to private field"),y?y.call(o,d):u.set(o,d),d);var g,b,S;function W(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const a=W(d);class _{constructor(t){this.value=t}}class q{static Draft(t){return new _(t)}}T(q,"Op",{Add:1,Remove:2,Update:4,Move:8,Replace:16});var p=(e=>(e.Mount="lifecycle/mount",e.Node="lifecycle/node",e.Derive="lifecycle/derive",e.Error="lifecycle/error",e.Unmount="lifecycle/unmount",e))(p||{});function G(e){return new Promise(t=>setTimeout(t,e))}function K(e){return e?!!(e&&typeof e!="symbol"):Symbol(`pk.${Date.now()}.${crypto.randomUUID()}`)}function E(e){return JSON.stringify(e)}const V=Object.freeze(Object.defineProperty({__proto__:null,hash:E,pk:K,sleep:G},Symbol.toStringTag,{value:"Module"}));function m(e,t){const n=a.useRef(null),r=a.useRef(null);return a.useMemo(()=>{const i=E(t);if(r.current!==i){r.current=i;const s=e();return n.current=s,s}return n.current},t)}function B(e,t){const n=a.useRef(null);a.useEffect(()=>{const r=E(t);if(n.current!==r)return n.current=r,e()},t)}const U=a.createContext({appEmitter:new y});function z(){return a.useContext(U)}function X({children:e}){const t=m(()=>({appEmitter:new y}),[]);return u.jsx(U.Provider,{value:t,children:e})}const f={immer:new Q.Immer,annotations:Symbol("annotations")};f.immer.setAutoFreeze(!1);class R{constructor(t,n,r=null){T(this,"process");this.value=t,this.operations=n,this.field=r,this.process=null}attach(t){return this.process=t,this}}function Y(e,t=[]){return new R(e,t)}class O{constructor(t,n=t){this.stateless=t,this.stateful=n}get validatable(){return H(this.stateful)}}function H(e,t=[]){return new Proxy(e,{get(n,r){switch(r){case"is":return i=>{const s=x(e,t);if(!s)return!1;const c=new Set(s.flatMap(h=>h.operations));return!!(Array.from(c).reduce((h,v)=>h|(v??0),0)&i)};case"pending":return()=>!!x(e,t);case"draft":return()=>{const i=x(e,t);if(!i)return w(e,t);const s=i.flatMap(c=>c.operations).find(c=>c instanceof _);return s?s.value:w(e,t)}}return H(e,[...t,String(r)])}})}function x(e,t){const r=typeof w(e,t)=="object"?t:t.slice(0,-1),i=r.length===0?e:w(e,r),s=(i==null?void 0:i[f.annotations])??[];return s.length>0?s:null}function Z(e,t,n){function r(s){return C(s).forEach(function(){if(this.key===f.annotations){this.block();return}this.node instanceof R&&this.update(this.node.value)})}function i(s){return C(s).forEach(function(){if(this.key===f.annotations){this.block();return}if(this.node instanceof R){const c=typeof this.node.value=="object",l=[...c?this.path:this.path.slice(0,-1),f.annotations],h=w(e.stateful,l)??[],v=this.node.attach(t);c?this.update({...this.node.value,[f.annotations]:[v,...h]},!0):(this.parent&&(this.parent.node[f.annotations]=[v,...h]),this.update(this.node.value,!0))}})}return new O(r(f.immer.produce(e.stateless,n)),i(f.immer.produce(e.stateful,n)))}function D(e,t){const n=C(e.stateful).forEach(function(){if(this.key===f.annotations){this.block();return}if(this.node&&this.node[f.annotations]){const r=this.node[f.annotations];this.update({...this.node,[f.annotations]:r.filter(i=>i.process!==t)},!0)}});return new O(e.stateless,n)}function L(e){return m(()=>({controller:{get model(){return e.model.current.stateful},queue:[],actions:{annotate(t,n){return Y(t,n)},produce(t){return(n,r)=>Z(n,r,t)},dispatch([t,...n]){if(t==null)return Promise.reject();const r=Promise.withResolvers();return e.dispatchers.dispatch(t,n,r),r.promise}}},view:{error:!1,get model(){return e.model.current.stateless},get validate(){return e.model.current.validatable},actions:{retry:()=>{},remount:()=>{},dispatch([t,...n]){if(t==null)return Promise.reject();const r=Promise.withResolvers();return e.dispatchers.dispatch(t,n,r),r.promise}}}}),[])}function ee(e){return m(()=>{const t=e.options.using.actions(e.actions.controller);return Object.entries(t).forEach(([r,i])=>e.dispatchers.attach(r,i)),t},[])}function N(e){return e.startsWith("distributed")}function te(e){return e instanceof k}function ne(e){return e instanceof A}function $(e){return e instanceof k||e instanceof A||e instanceof Error?e:new Error("Unknown error",{cause:e})}class k extends Error{constructor(n,r=null){super(String(r));M(this,g);M(this,b);P(this,g,n),P(this,b,r)}get type(){return j(this,g)}get message(){return j(this,b)||""}}g=new WeakMap,b=new WeakMap;class A extends Error{constructor(n=null){super(String(n));M(this,S);P(this,S,n)}get message(){return j(this,S)||""}}S=new WeakMap;function re(e){return(t,n)=>async(r=Promise.withResolvers(),i)=>{if(typeof n!="function")return;const s=Symbol("process"),c=n(...i);try{if(c==null)return;if(typeof c=="function"){const l=c(e.model.current,s);e.model.current=D(l,s),e.update.rerender(),r.resolve();return}for(;;){const{value:l,done:h}=await c.next();if(h){const pe=l(e.model.current,s);e.model.current=D(pe,s),e.update.rerender();break}const v=l;e.model.current=v(e.model.current,s),e.update.rerender(),r.resolve()}}catch(l){D(e.model.current,s),e.update.rerender(),e.unicast.emit(p.Error,r,[$(l)])}}}function oe(e){const t=z(),n=m(()=>new y,[]),r=re({...e,unicast:n});return m(()=>({attach(i,s){const c=String(i);N(c)?t.appEmitter.on(c,r(i,s)):n.on(c,r(i,s))},dispatch(i,s,c){const l=String(i);N(l)?t.appEmitter.emit(l,c,s):n.emit(l,c,s)}}),[])}function se(){const e=a.useRef(null);return m(()=>({customElement:e}),[])}function ue(e){B(()=>{e.dispatchers.dispatch(p.Derive,[])},[e.options.using.props]),B(()=>(e.dispatchers.dispatch(p.Mount,[]),e.dispatchers.dispatch(p.Node,[e.elements.customElement.current]),()=>e.dispatchers.dispatch(p.Unmount,[])),[])}function ie(e){const t=m(()=>e.options.using.model??{},[]);return a.useRef(new O(t,t))}function ce(){return a.useRef(new Set)}function ae(){const[e,t]=a.useReducer(n=>n+1,0);return m(()=>({hash:e,rerender:t}),[e])}const F=a.createContext(null);function le(){const e=a.useContext(F);if(!e)throw new Error("useModule must be used within a module.");return e}class de extends a.Component{constructor(t){super(t),this.state={errored:!1}}static getDerivedStateFromError(){return{errored:!0}}componentDidCatch(t){this.props.module.actions.dispatch([p.Error,[$(t)]])}render(){const t=()=>this.setState({errored:!1});return this.props.children({error:this.state.errored,retry:t})}}function fe({options:e}){const t=ae(),n=ce(),r=se(),i=z(),s=ie({options:e}),c=oe({broadcast:i,options:e,update:t,model:s,queue:n}),l=L({model:s,dispatchers:c});return ee({options:e,dispatchers:c,actions:l}),ue({options:e,dispatchers:c,elements:r}),m(()=>a.createElement(de,{module:l.view,children(h){const v={...l.view,error:h.error,actions:{...l.view.actions,retry:h.retry,remount:e.remount}};return a.createElement(F.Provider,{value:v,children:a.createElement("x-chizu",{ref:r.customElement,style:{display:"contents"},children:e.children(v)})})}}),[t.hash,E(e.using.props)])}function he({children:e}){return u.jsx(u.Fragment,{children:e})}function me(e){const[t,n]=a.useReducer(r=>r+1,0);return u.jsx(he,{children:u.jsx(fe,{options:{...e,remount:n}})},t)}const ve=a.memo(me,(e,t)=>E(e)===E(t));o.ActionError=k,o.BroadcastProvider=X,o.ComponentError=A,o.Lifecycle=p,o.State=q,o.Tree=ve,o.isActionError=te,o.isComponentError=ne,o.useModule=le,o.utils=V,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ActionError, ComponentError } from '../errors/utils.ts';
|
|
2
2
|
import { Models } from '../module/renderer/model/utils.ts';
|
|
3
3
|
import { Head } from '../module/renderer/types.ts';
|
|
4
4
|
import { Actions, Draft, Lifecycle, ModuleDefinition, Op, Queue } from '../types/index.ts';
|
|
@@ -22,7 +22,7 @@ export type ControllerInstance<M extends ModuleDefinition> = {
|
|
|
22
22
|
[Lifecycle.Mount]?(): ActionGenerator<M>;
|
|
23
23
|
[Lifecycle.Derive]?(): ActionGenerator<M>;
|
|
24
24
|
[Lifecycle.Node]?(tree: HTMLElement): ActionGenerator<M>;
|
|
25
|
-
[Lifecycle.Error]?(error: Error |
|
|
25
|
+
[Lifecycle.Error]?(error: Error | ActionError | ComponentError): ActionGenerator<M>;
|
|
26
26
|
[Lifecycle.Unmount]?(): ActionGenerator<M>;
|
|
27
27
|
} & Partial<ActionEvents<M>>;
|
|
28
28
|
type Payload<A extends Actions, K> = A extends [K, infer P] ? P : never;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Props, State } from './types.ts';
|
|
2
|
+
import { ModuleDefinition } from '../types/index.ts';
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
export default class ErrorBoundary<M extends ModuleDefinition> extends React.Component<Props<M>, State> {
|
|
5
|
+
constructor(props: Props<M>);
|
|
6
|
+
static getDerivedStateFromError(): Partial<State>;
|
|
7
|
+
componentDidCatch(error: unknown): void;
|
|
8
|
+
render(): React.ReactNode;
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ModuleDefinition } from '../types/index.ts';
|
|
2
|
+
import { ViewArgs } from '../view/types.ts';
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
export type Props<M extends ModuleDefinition> = {
|
|
5
|
+
module: ViewArgs<M>;
|
|
6
|
+
children(props: ChildrenProps): React.ReactNode;
|
|
7
|
+
};
|
|
8
|
+
export type State = {
|
|
9
|
+
errored: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type ChildrenProps = {
|
|
12
|
+
error: boolean;
|
|
13
|
+
retry: Retry;
|
|
14
|
+
};
|
|
15
|
+
export type Retry = () => void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare function isActionError(error: Error | ActionError | ComponentError): error is ActionError;
|
|
2
|
+
export declare function isComponentError(error: Error | ActionError | ComponentError): error is ComponentError;
|
|
3
|
+
/**
|
|
4
|
+
* Convert an unknown error into a known error type.
|
|
5
|
+
*
|
|
6
|
+
* @function intoError
|
|
7
|
+
* @param error {unknown} - The error to convert to a known error type.
|
|
8
|
+
* @returns {Error | ActionError | ComponentError}
|
|
9
|
+
*/
|
|
10
|
+
export declare function intoError(error: unknown): Error | ActionError | ComponentError;
|
|
11
|
+
/**
|
|
12
|
+
* Custom error class for action errors.
|
|
13
|
+
*
|
|
14
|
+
* @class ActionError
|
|
15
|
+
* @extends Error
|
|
16
|
+
* @param type {string} - The type of the error.
|
|
17
|
+
* @param message {string} - The error message.
|
|
18
|
+
*/
|
|
19
|
+
export declare class ActionError extends Error {
|
|
20
|
+
#private;
|
|
21
|
+
constructor(type: number | string | symbol, message?: null | string);
|
|
22
|
+
get type(): number | string | symbol;
|
|
23
|
+
get message(): string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Custom error class for component errors.
|
|
27
|
+
*
|
|
28
|
+
* @class ComponentError
|
|
29
|
+
* @extends Error
|
|
30
|
+
* @param type {string} - The type of the error.
|
|
31
|
+
* @param message {string} - The error message.
|
|
32
|
+
*/
|
|
33
|
+
export declare class ComponentError extends Error {
|
|
34
|
+
#private;
|
|
35
|
+
constructor(message?: null | string);
|
|
36
|
+
get message(): string;
|
|
37
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { ControllerDefinition } from './controller/types.ts';
|
|
|
2
2
|
import { ViewArgs, ViewDefinition } from './view/types.ts';
|
|
3
3
|
export { Lifecycle, State } from './types/index.ts';
|
|
4
4
|
export * as utils from './utils/index.ts';
|
|
5
|
-
export { EventError } from './module/renderer/dispatchers/utils.ts';
|
|
6
5
|
export { default as Tree } from './module/index.tsx';
|
|
7
6
|
export { BroadcastProvider } from './broadcast/index.tsx';
|
|
8
7
|
export { useModule } from './module/renderer/utils.ts';
|
|
8
|
+
export { isActionError, isComponentError, ActionError, ComponentError, } from './errors/utils.ts';
|
|
9
9
|
export type * as Typed from './types/index.ts';
|
|
10
10
|
export type { Pk } from './types/index.ts';
|
|
11
11
|
export type { ViewDefinition as View };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { default as EventEmitter } from 'eventemitter3';
|
|
1
2
|
import { UseBroadcast } from '../../../broadcast/types.ts';
|
|
2
3
|
import { ModuleDefinition } from '../../../types/index.ts';
|
|
3
4
|
import { UseOptions } from '../../types.ts';
|
|
@@ -13,5 +14,7 @@ export type Props<M extends ModuleDefinition> = {
|
|
|
13
14
|
queue: UseQueue;
|
|
14
15
|
};
|
|
15
16
|
export type UseDispatchers = ReturnType<typeof useDispatchers>;
|
|
16
|
-
export type UseDispatchHandlerProps<M extends ModuleDefinition> = Props<M
|
|
17
|
+
export type UseDispatchHandlerProps<M extends ModuleDefinition> = Props<M> & {
|
|
18
|
+
unicast: EventEmitter;
|
|
19
|
+
};
|
|
17
20
|
export type Fn = (...args: any[]) => void;
|
|
@@ -7,24 +7,3 @@ import { UseDispatchHandlerProps } from './types.ts';
|
|
|
7
7
|
* @returns {(name: Head<M["Actions"]>, ƒ: GeneratorFn<M>) => (payload: Tail<M["Actions"]>) => Promise<void>}
|
|
8
8
|
*/
|
|
9
9
|
export declare function useDispatcher<M extends ModuleDefinition>(props: UseDispatchHandlerProps<M>): (_name: Head<M["Actions"]>, ƒ: ActionEvent<M>) => (task: Task | undefined, payload: Tail<M["Actions"]>) => Promise<void>;
|
|
10
|
-
/**
|
|
11
|
-
* Check if the name is a broadcast event.
|
|
12
|
-
*
|
|
13
|
-
* @param name {string}
|
|
14
|
-
* @returns {boolean}
|
|
15
|
-
*/
|
|
16
|
-
export declare function isBroadcast(name: string): boolean;
|
|
17
|
-
/**
|
|
18
|
-
* Custom error class for IO errors.
|
|
19
|
-
*
|
|
20
|
-
* @class EventError
|
|
21
|
-
* @extends Error
|
|
22
|
-
* @param type {string} - The type of the error.
|
|
23
|
-
* @param message {string} - The error message.
|
|
24
|
-
*/
|
|
25
|
-
export declare class EventError extends Error {
|
|
26
|
-
#private;
|
|
27
|
-
constructor(type: string, message?: null | string);
|
|
28
|
-
get type(): string;
|
|
29
|
-
get message(): string;
|
|
30
|
-
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ModuleDefinition } from '../../types/index.ts';
|
|
2
2
|
import { Props } from './types.ts';
|
|
3
3
|
import * as React from "react";
|
|
4
|
-
export default function
|
|
4
|
+
export default function Renderer<M extends ModuleDefinition>({ options, }: Props<M>): React.ReactNode;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { ModuleDefinition } from '../../types/index.ts';
|
|
2
2
|
import { UseOptions } from '../types.ts';
|
|
3
|
+
import * as React from "react";
|
|
3
4
|
export type ElementName = string;
|
|
5
|
+
export type Remount = React.ActionDispatch<[]>;
|
|
4
6
|
export type Props<M extends ModuleDefinition> = {
|
|
5
|
-
options: UseOptions<M
|
|
7
|
+
options: UseOptions<M> & {
|
|
8
|
+
remount: Remount;
|
|
9
|
+
};
|
|
6
10
|
};
|
|
7
11
|
export type Head<T extends any[]> = T extends [infer X, ...any[]] ? X : never;
|
|
8
12
|
export type Tail<T extends any[]> = T extends [any, ...infer XS] ? XS : never;
|
package/dist/module/types.d.ts
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare enum Lifecycle {
|
|
|
24
24
|
Mount = "lifecycle/mount",
|
|
25
25
|
Node = "lifecycle/node",
|
|
26
26
|
Derive = "lifecycle/derive",
|
|
27
|
-
Error = "
|
|
27
|
+
Error = "lifecycle/error",
|
|
28
28
|
Unmount = "lifecycle/unmount"
|
|
29
29
|
}
|
|
30
30
|
export type Model = Record<string, any>;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { EventError } from '../module/renderer/dispatchers/utils.ts';
|
|
2
1
|
import { Pk } from '../types/index.ts';
|
|
3
2
|
export { default as sleep } from './sleep/index.ts';
|
|
4
3
|
export declare function pk(): symbol;
|
|
5
4
|
export declare function pk<T>(id: Pk<T>): boolean;
|
|
6
|
-
export declare function isEventError(error: Error | EventError): error is EventError;
|
|
7
5
|
export declare function hash<T>(x: T): string;
|
package/dist/view/types.d.ts
CHANGED
|
@@ -2,9 +2,12 @@ import { Validatable } from '../module/renderer/model/types.ts';
|
|
|
2
2
|
import { ModuleDefinition } from '../types/index.ts';
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
export type ViewActions<M extends ModuleDefinition> = {
|
|
5
|
+
retry(): void;
|
|
6
|
+
remount(): void;
|
|
5
7
|
dispatch(action: M["Actions"]): Promise<void>;
|
|
6
8
|
};
|
|
7
9
|
export type ViewArgs<M extends ModuleDefinition> = Readonly<{
|
|
10
|
+
error: boolean;
|
|
8
11
|
model: Readonly<M["Model"]>;
|
|
9
12
|
validate: Readonly<Validatable<M["Model"]>>;
|
|
10
13
|
actions: Readonly<ViewActions<M>>;
|
package/package.json
CHANGED
|
File without changes
|