chizu 0.2.26 → 0.2.28
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 +104 -97
- package/dist/action/index.d.ts +19 -0
- package/dist/chizu.js +142 -425
- package/dist/chizu.umd.cjs +3 -1
- package/dist/decorators/index.d.ts +6 -0
- package/dist/error/index.d.ts +4 -0
- package/dist/error/types.d.ts +6 -0
- package/dist/hooks/index.d.ts +66 -10
- package/dist/hooks/types.d.ts +2 -0
- package/dist/hooks/utils.d.ts +18 -0
- package/dist/index.d.ts +6 -9
- package/dist/types/index.d.ts +47 -52
- package/dist/use/index.d.ts +5 -0
- package/dist/use/types.d.ts +3 -0
- package/dist/use/utils.d.ts +2 -0
- package/dist/utils/index.d.ts +28 -3
- package/package.json +51 -32
- package/dist/context/index.d.ts +0 -7
- package/dist/context/types.d.ts +0 -2
- package/dist/controller/index.d.ts +0 -3
- package/dist/controller/types.d.ts +0 -30
- package/dist/errors/index.d.ts +0 -8
- package/dist/errors/types.d.ts +0 -13
- package/dist/errors/utils.d.ts +0 -30
- package/dist/module/index.d.ts +0 -4
- package/dist/module/renderer/actions/index.d.ts +0 -3
- package/dist/module/renderer/actions/types.d.ts +0 -19
- package/dist/module/renderer/controller/index.d.ts +0 -4
- package/dist/module/renderer/controller/types.d.ts +0 -11
- package/dist/module/renderer/dispatchers/index.d.ts +0 -12
- package/dist/module/renderer/dispatchers/types.d.ts +0 -18
- package/dist/module/renderer/dispatchers/utils.d.ts +0 -10
- package/dist/module/renderer/elements/index.d.ts +0 -4
- package/dist/module/renderer/elements/types.d.ts +0 -2
- package/dist/module/renderer/elements/utils.d.ts +0 -4
- package/dist/module/renderer/index.d.ts +0 -4
- package/dist/module/renderer/lifecycles/index.d.ts +0 -3
- package/dist/module/renderer/lifecycles/types.d.ts +0 -13
- package/dist/module/renderer/model/index.d.ts +0 -5
- package/dist/module/renderer/model/types.d.ts +0 -15
- package/dist/module/renderer/model/utils.d.ts +0 -8
- package/dist/module/renderer/passive/index.d.ts +0 -1
- package/dist/module/renderer/types.d.ts +0 -10
- package/dist/module/renderer/update/index.d.ts +0 -5
- package/dist/module/renderer/update/types.d.ts +0 -2
- package/dist/module/renderer/utils.d.ts +0 -8
- package/dist/module/types.d.ts +0 -12
- package/dist/utils/produce/index.d.ts +0 -23
- package/dist/utils/produce/utils.d.ts +0 -15
- package/dist/view/index.d.ts +0 -3
- package/dist/view/types.d.ts +0 -16
- /package/dist/{utils/produce/index.test.d.ts → index.test.d.ts} +0 -0
package/dist/chizu.js
CHANGED
|
@@ -1,449 +1,166 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
constructor(e) {
|
|
17
|
-
this.value = e;
|
|
18
|
-
}
|
|
1
|
+
import { jsx as h } from "react/jsx-runtime";
|
|
2
|
+
import * as n from "react";
|
|
3
|
+
import { createContext as A, useContext as O } from "react";
|
|
4
|
+
import p from "eventemitter3";
|
|
5
|
+
import { State as P } from "immertation";
|
|
6
|
+
import { Op as Q, Operation as V, State as X } from "immertation";
|
|
7
|
+
const E = A(void 0);
|
|
8
|
+
function k() {
|
|
9
|
+
return O(E);
|
|
10
|
+
}
|
|
11
|
+
function F({
|
|
12
|
+
handler: t,
|
|
13
|
+
children: e
|
|
14
|
+
}) {
|
|
15
|
+
return /* @__PURE__ */ h(E.Provider, { value: t, children: e });
|
|
19
16
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return new H(e);
|
|
23
|
-
}
|
|
17
|
+
function T(t = "anonymous") {
|
|
18
|
+
return Symbol(`chizu.action/${t}`);
|
|
24
19
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
20
|
+
function I(t = "anonymous") {
|
|
21
|
+
return Symbol(`chizu.action/distributed/${t}`);
|
|
22
|
+
}
|
|
23
|
+
function d(t) {
|
|
24
|
+
return t.toString().startsWith("Symbol(chizu.action/distributed/");
|
|
25
|
+
}
|
|
26
|
+
class v {
|
|
27
|
+
static Mount = Symbol("lifecycle/mount");
|
|
28
|
+
static Node = Symbol("lifecycle/node");
|
|
29
|
+
static Derive = Symbol("lifecycle/derive");
|
|
30
|
+
static Error = Symbol("lifecycle/error");
|
|
31
|
+
static Unmount = Symbol("lifecycle/unmount");
|
|
32
|
+
}
|
|
33
|
+
function M(t) {
|
|
34
34
|
return new Promise((e) => setTimeout(e, t));
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function g(t) {
|
|
37
37
|
return t ? !!(t && typeof t != "symbol") : Symbol(`pk.${Date.now()}.${crypto.randomUUID()}`);
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const j = g;
|
|
40
|
+
function x(t) {
|
|
41
|
+
return (e, r) => {
|
|
42
|
+
e.actions.produce((s) => {
|
|
43
|
+
s[t] = r;
|
|
44
|
+
});
|
|
45
|
+
};
|
|
41
46
|
}
|
|
42
|
-
const
|
|
47
|
+
const z = x, N = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
43
48
|
__proto__: null,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return i.useMemo(() => {
|
|
52
|
-
const s = b(e);
|
|
53
|
-
if (r.current !== s) {
|
|
54
|
-
r.current = s;
|
|
55
|
-
const o = t();
|
|
56
|
-
return n.current = o, o;
|
|
57
|
-
}
|
|
58
|
-
return n.current;
|
|
59
|
-
}, e);
|
|
60
|
-
}
|
|
61
|
-
function k(t, e) {
|
|
62
|
-
const n = i.useRef(null);
|
|
63
|
-
i.useEffect(() => {
|
|
64
|
-
const r = b(e);
|
|
65
|
-
if (n.current !== r)
|
|
66
|
-
return n.current = r, t();
|
|
67
|
-
}, e);
|
|
68
|
-
}
|
|
69
|
-
const T = i.createContext({
|
|
70
|
-
instance: new M()
|
|
49
|
+
pk: g,
|
|
50
|
+
set: x,
|
|
51
|
+
sleep: M,
|
|
52
|
+
κ: j,
|
|
53
|
+
λ: z
|
|
54
|
+
}, Symbol.toStringTag, { value: "Module" })), C = n.createContext({
|
|
55
|
+
instance: new p()
|
|
71
56
|
});
|
|
72
|
-
function
|
|
73
|
-
return
|
|
74
|
-
}
|
|
75
|
-
function wt({ children: t }) {
|
|
76
|
-
const e = d(
|
|
77
|
-
() => ({
|
|
78
|
-
instance: new M()
|
|
79
|
-
}),
|
|
80
|
-
[]
|
|
81
|
-
);
|
|
82
|
-
return /* @__PURE__ */ C(T.Provider, { value: e, children: t });
|
|
83
|
-
}
|
|
84
|
-
const a = {
|
|
85
|
-
immer: new K(),
|
|
86
|
-
annotations: Symbol("annotations")
|
|
87
|
-
};
|
|
88
|
-
Q();
|
|
89
|
-
a.immer.setAutoFreeze(!1);
|
|
90
|
-
class j {
|
|
91
|
-
constructor(e, n, r = null) {
|
|
92
|
-
w(this, "process");
|
|
93
|
-
this.value = e, this.operations = n, this.field = r, this.process = null;
|
|
94
|
-
}
|
|
95
|
-
attach(e) {
|
|
96
|
-
return this.process = e, this;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
function Z(t, e = []) {
|
|
100
|
-
return new j(t, e);
|
|
101
|
-
}
|
|
102
|
-
class U {
|
|
103
|
-
constructor(e, n = e) {
|
|
104
|
-
this.stateless = e, this.stateful = n;
|
|
105
|
-
}
|
|
106
|
-
get validatable() {
|
|
107
|
-
return z(this.stateful);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
function z(t, e = []) {
|
|
111
|
-
return new Proxy(t, {
|
|
112
|
-
get(n, r) {
|
|
113
|
-
switch (r) {
|
|
114
|
-
case "is":
|
|
115
|
-
return (s) => {
|
|
116
|
-
const o = P(t, e);
|
|
117
|
-
if (!o) return !1;
|
|
118
|
-
const c = new Set(
|
|
119
|
-
o.flatMap((l) => l.operations)
|
|
120
|
-
);
|
|
121
|
-
return !!(Array.from(c).reduce(
|
|
122
|
-
(l, f) => l | (f ?? 0),
|
|
123
|
-
0
|
|
124
|
-
) & s);
|
|
125
|
-
};
|
|
126
|
-
case "pending":
|
|
127
|
-
return () => !!P(t, e);
|
|
128
|
-
case "draft":
|
|
129
|
-
return () => {
|
|
130
|
-
const s = P(t, e);
|
|
131
|
-
if (!s) return m(t, e);
|
|
132
|
-
const o = s.flatMap((c) => c.operations).find((c) => c instanceof H);
|
|
133
|
-
return o ? o.value : m(t, e);
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
return z(t, [...e, String(r)]);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
57
|
+
function D() {
|
|
58
|
+
return n.useContext(C);
|
|
139
59
|
}
|
|
140
|
-
function
|
|
141
|
-
|
|
142
|
-
|
|
60
|
+
function W({
|
|
61
|
+
children: t
|
|
62
|
+
}) {
|
|
63
|
+
const e = n.useMemo(() => ({
|
|
64
|
+
instance: new p()
|
|
65
|
+
}), []);
|
|
66
|
+
return /* @__PURE__ */ h(C.Provider, { value: e, children: t });
|
|
143
67
|
}
|
|
144
|
-
function
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
this.node instanceof j && this.update(this.node.value);
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
function s(c) {
|
|
155
|
-
return D(c).forEach(function() {
|
|
156
|
-
if (this.key === a.annotations) {
|
|
157
|
-
this.block();
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
if (this.node instanceof j) {
|
|
161
|
-
const u = typeof this.node.value == "object", l = [
|
|
162
|
-
...u ? this.path : this.path.slice(0, -1),
|
|
163
|
-
a.annotations
|
|
164
|
-
], f = m(t.stateful, l) ?? [], y = this.node.attach(e);
|
|
165
|
-
u ? this.update(
|
|
166
|
-
{
|
|
167
|
-
...this.node.value,
|
|
168
|
-
[a.annotations]: [y, ...f]
|
|
169
|
-
},
|
|
170
|
-
!0
|
|
171
|
-
) : (this.parent && (this.parent.node[a.annotations] = [y, ...f]), this.update(this.node.value, !0));
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
const o = (c) => n(c, c[E]);
|
|
176
|
-
return new U(
|
|
177
|
-
r(a.immer.produce(t.stateless, o)),
|
|
178
|
-
s(a.immer.produce(t.stateful, o))
|
|
179
|
-
);
|
|
68
|
+
function G(t, e) {
|
|
69
|
+
return Object.keys(t).reduce((r, s) => (Object.defineProperty(r, s, {
|
|
70
|
+
get() {
|
|
71
|
+
return e.current[s];
|
|
72
|
+
},
|
|
73
|
+
enumerable: !0
|
|
74
|
+
}), r), {});
|
|
180
75
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
},
|
|
196
|
-
!0
|
|
197
|
-
);
|
|
76
|
+
const R = Symbol("chizu.action.context");
|
|
77
|
+
function q(t) {
|
|
78
|
+
const e = k();
|
|
79
|
+
return n.useCallback(async (r, s) => {
|
|
80
|
+
try {
|
|
81
|
+
if (t.constructor.name === "GeneratorFunction" || t.constructor.name === "AsyncGeneratorFunction") {
|
|
82
|
+
const a = t(r, s);
|
|
83
|
+
for await (const S of a) ;
|
|
84
|
+
} else
|
|
85
|
+
await t(r, s);
|
|
86
|
+
} catch (f) {
|
|
87
|
+
console.error(`Chizu
|
|
88
|
+
|
|
89
|
+
`, f), e?.(f);
|
|
198
90
|
}
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
91
|
+
}, [t, e]);
|
|
92
|
+
}
|
|
93
|
+
function H(t, e) {
|
|
94
|
+
const r = D(), [s, f] = n.useState(t), a = n.useRef(new P(t)), S = _({
|
|
95
|
+
model: s
|
|
96
|
+
}), m = n.useMemo(() => new p(), []), w = n.useCallback((i) => {
|
|
97
|
+
const o = new AbortController();
|
|
98
|
+
return {
|
|
99
|
+
signal: o.signal,
|
|
100
|
+
actions: {
|
|
101
|
+
produce(c) {
|
|
102
|
+
if (o.signal.aborted) return;
|
|
103
|
+
const u = a.current.mutate((l) => c(l));
|
|
104
|
+
f(a.current.model), i.processes.add(u);
|
|
208
105
|
},
|
|
209
|
-
|
|
210
|
-
|
|
106
|
+
dispatch(...[c, u]) {
|
|
107
|
+
o.signal.aborted || (d(c) ? r.instance.emit(c, u) : m.emit(c, u));
|
|
211
108
|
},
|
|
212
|
-
|
|
213
|
-
annotate(
|
|
214
|
-
return Z(e, n);
|
|
215
|
-
},
|
|
216
|
-
produce(e) {
|
|
217
|
-
return (n, r) => I(n, r, e);
|
|
218
|
-
},
|
|
219
|
-
dispatch([e, ...n]) {
|
|
220
|
-
if (e == null) return Promise.reject();
|
|
221
|
-
const r = Promise.withResolvers();
|
|
222
|
-
return t.dispatchers.dispatch(e, n, r), r.promise;
|
|
223
|
-
},
|
|
224
|
-
context(e) {
|
|
225
|
-
const n = Object.keys(e);
|
|
226
|
-
return t.context.use.current = e, t.context.update(), n.reduce(
|
|
227
|
-
(r, s) => ({
|
|
228
|
-
...r,
|
|
229
|
-
get [s]() {
|
|
230
|
-
return t.context.values.current[s];
|
|
231
|
-
}
|
|
232
|
-
}),
|
|
233
|
-
{}
|
|
234
|
-
);
|
|
235
|
-
}
|
|
109
|
+
annotate(c, u) {
|
|
110
|
+
return a.current.annotate(c, u);
|
|
236
111
|
}
|
|
237
112
|
},
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return t.model.current.stateless;
|
|
241
|
-
},
|
|
242
|
-
get props() {
|
|
243
|
-
return t.options.using.props;
|
|
244
|
-
},
|
|
245
|
-
get validate() {
|
|
246
|
-
return t.model.current.validatable;
|
|
247
|
-
},
|
|
248
|
-
boundary: {
|
|
249
|
-
is(e) {
|
|
250
|
-
return t.model.current.stateless[E].boundary === e;
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
actions: {
|
|
254
|
-
dispatch([e, ...n]) {
|
|
255
|
-
if (e == null) return Promise.reject();
|
|
256
|
-
const r = Promise.withResolvers();
|
|
257
|
-
return t.dispatchers.dispatch(e, n, r), r.promise;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}),
|
|
262
|
-
[]
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
function tt(t) {
|
|
266
|
-
const e = B(null);
|
|
267
|
-
return e.current == null && (e.current = t.options.using.actions(t.actions.controller)), d(() => {
|
|
268
|
-
if (e.current)
|
|
269
|
-
return Object.entries(e.current).forEach(([r, s]) => t.dispatchers.attach(r, s)), e.current;
|
|
270
|
-
}, []);
|
|
271
|
-
}
|
|
272
|
-
function N(t) {
|
|
273
|
-
return t.startsWith("distributed");
|
|
274
|
-
}
|
|
275
|
-
function xt(t) {
|
|
276
|
-
return t instanceof J;
|
|
277
|
-
}
|
|
278
|
-
function F(t) {
|
|
279
|
-
return t instanceof J || t instanceof Error ? t : new Error("Unknown error", { cause: t });
|
|
280
|
-
}
|
|
281
|
-
var v, p;
|
|
282
|
-
class J extends Error {
|
|
283
|
-
constructor(n, r = null) {
|
|
284
|
-
super(String(r));
|
|
285
|
-
R(this, v);
|
|
286
|
-
R(this, p);
|
|
287
|
-
S(this, v, n), S(this, p, r);
|
|
288
|
-
}
|
|
289
|
-
get type() {
|
|
290
|
-
return x(this, v);
|
|
291
|
-
}
|
|
292
|
-
get message() {
|
|
293
|
-
return x(this, p) || "";
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
v = new WeakMap(), p = new WeakMap();
|
|
297
|
-
function et({
|
|
298
|
-
children: t
|
|
299
|
-
}) {
|
|
300
|
-
return t();
|
|
301
|
-
}
|
|
302
|
-
function nt(t) {
|
|
303
|
-
return (e, n) => async (r = Promise.withResolvers(), s) => {
|
|
304
|
-
if (typeof n != "function") return void r.resolve();
|
|
305
|
-
const o = Symbol("process"), c = n(...s);
|
|
306
|
-
try {
|
|
307
|
-
if (c == null) return void r.resolve();
|
|
308
|
-
if (typeof c == "function") {
|
|
309
|
-
const u = c(t.model.current, o);
|
|
310
|
-
return t.model.current = g(u, o), t.update.rerender(), void r.resolve();
|
|
113
|
+
[R]: {
|
|
114
|
+
controller: o
|
|
311
115
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
function rt(t) {
|
|
332
|
-
const e = $(), n = d(() => new M(), []), r = nt({ ...t, unicast: n });
|
|
333
|
-
return d(() => ({
|
|
334
|
-
attach(s, o) {
|
|
335
|
-
const c = String(s);
|
|
336
|
-
N(c) ? e.instance.on(c, r(s, o)) : n.on(c, r(s, o));
|
|
337
|
-
},
|
|
338
|
-
dispatch(s, o, c) {
|
|
339
|
-
const u = String(s);
|
|
340
|
-
N(u) ? e.instance.emit(u, c, o) : n.emit(u, c, o);
|
|
341
|
-
}
|
|
342
|
-
}), []);
|
|
343
|
-
}
|
|
344
|
-
function st() {
|
|
345
|
-
const t = i.useRef(null);
|
|
346
|
-
return d(() => ({ customElement: t }), []);
|
|
347
|
-
}
|
|
348
|
-
function ot(t) {
|
|
349
|
-
k(() => {
|
|
350
|
-
t.dispatchers.dispatch(h.Derive, []);
|
|
351
|
-
}, [t.options.using.props]), k(() => (t.dispatchers.dispatch(h.Mount, []), t.dispatchers.dispatch(h.Node, [
|
|
352
|
-
t.elements.customElement.current
|
|
353
|
-
]), () => t.dispatchers.dispatch(h.Unmount, [])), []);
|
|
354
|
-
}
|
|
355
|
-
function ct(t) {
|
|
356
|
-
const e = d(() => ({ ...t.options.using.model ?? {}, [E]: { boundary: O.Default } }), []);
|
|
357
|
-
return i.useRef(new U(e, e));
|
|
358
|
-
}
|
|
359
|
-
function ut() {
|
|
360
|
-
const [t, e] = i.useReducer((n) => n + 1, 0);
|
|
361
|
-
return d(() => ({ hash: t, rerender: e }), [t]);
|
|
362
|
-
}
|
|
363
|
-
const it = {
|
|
364
|
-
elementName: "x-chizu"
|
|
365
|
-
}, W = i.createContext(
|
|
366
|
-
null
|
|
367
|
-
);
|
|
368
|
-
function Rt() {
|
|
369
|
-
const t = i.useContext(W);
|
|
370
|
-
if (!t)
|
|
371
|
-
throw new Error("useScoped is not being used within a scoped module.");
|
|
372
|
-
return t;
|
|
373
|
-
}
|
|
374
|
-
class at extends i.Component {
|
|
375
|
-
constructor(e) {
|
|
376
|
-
super(e), this.state = { error: null };
|
|
377
|
-
}
|
|
378
|
-
componentDidCatch(e) {
|
|
379
|
-
const n = Symbol("process"), r = I(this.props.model.current, n, (s, o) => {
|
|
380
|
-
o.boundary = O.Error;
|
|
381
|
-
});
|
|
382
|
-
this.props.model.current = r, this.props.update.rerender(), this.props.dispatchers.dispatch(h.Error, [F(e)]);
|
|
383
|
-
}
|
|
384
|
-
render() {
|
|
385
|
-
return /* @__PURE__ */ C(et, { children: this.props.children });
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
function lt() {
|
|
389
|
-
const t = i.useRef({}), e = i.useRef({});
|
|
390
|
-
function n() {
|
|
391
|
-
e.current = Object.fromEntries(
|
|
392
|
-
Object.entries(t.current).map(([r, s]) => [r, i.use(s)])
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
return n(), d(() => ({ use: t, values: e, update: n }), []);
|
|
396
|
-
}
|
|
397
|
-
function dt() {
|
|
398
|
-
return B(0);
|
|
399
|
-
}
|
|
400
|
-
function ft({
|
|
401
|
-
options: t
|
|
402
|
-
}) {
|
|
403
|
-
const e = ut(), n = dt(), r = st(), s = $(), o = lt(), c = ct({ options: t }), u = rt({
|
|
404
|
-
broadcast: s,
|
|
405
|
-
options: t,
|
|
406
|
-
update: e,
|
|
407
|
-
model: c
|
|
408
|
-
}), l = L({
|
|
409
|
-
options: t,
|
|
410
|
-
model: c,
|
|
411
|
-
dispatchers: u,
|
|
412
|
-
context: o
|
|
413
|
-
});
|
|
414
|
-
return tt({ options: t, dispatchers: u, actions: l }), ot({ options: t, dispatchers: u, elements: r }), d(() => i.createElement(at, {
|
|
415
|
-
model: c,
|
|
416
|
-
dispatchers: u,
|
|
417
|
-
update: e,
|
|
418
|
-
module: l.view,
|
|
419
|
-
children() {
|
|
420
|
-
return i.createElement(W.Provider, {
|
|
421
|
-
value: l.view,
|
|
422
|
-
// eslint-disable-next-line react/no-children-prop
|
|
423
|
-
children: i.createElement(it.elementName, {
|
|
424
|
-
ref: r.customElement,
|
|
425
|
-
style: { display: "contents" },
|
|
426
|
-
children: t.children(l.view)
|
|
427
|
-
})
|
|
116
|
+
};
|
|
117
|
+
}, [S.model]);
|
|
118
|
+
return n.useLayoutEffect(() => {
|
|
119
|
+
const i = new e();
|
|
120
|
+
Object.getOwnPropertySymbols(i).forEach((o) => {
|
|
121
|
+
const c = o;
|
|
122
|
+
if (d(o))
|
|
123
|
+
return void r.instance.on(o, async (u) => {
|
|
124
|
+
const l = {
|
|
125
|
+
processes: /* @__PURE__ */ new Set()
|
|
126
|
+
}, y = Promise.withResolvers();
|
|
127
|
+
await i[c](w(l), u), l.processes.forEach((b) => a.current.prune(b)), y.resolve();
|
|
128
|
+
});
|
|
129
|
+
m.on(o, async (u) => {
|
|
130
|
+
const l = {
|
|
131
|
+
processes: /* @__PURE__ */ new Set()
|
|
132
|
+
}, y = Promise.withResolvers();
|
|
133
|
+
await i[c](w(l), u), l.processes.forEach((b) => a.current.prune(b)), y.resolve();
|
|
428
134
|
});
|
|
135
|
+
});
|
|
136
|
+
}, [m]), n.useLayoutEffect(() => (m.emit(v.Mount), () => void m.emit(v.Unmount)), []), n.useMemo(() => [s, {
|
|
137
|
+
dispatch(...[i, o]) {
|
|
138
|
+
d(i) ? r.instance.emit(i, o) : m.emit(i, o);
|
|
139
|
+
},
|
|
140
|
+
consume() {
|
|
141
|
+
},
|
|
142
|
+
get inspect() {
|
|
143
|
+
return a.current.inspect;
|
|
429
144
|
}
|
|
430
|
-
}
|
|
431
|
-
e.hash,
|
|
432
|
-
b(t.using.props),
|
|
433
|
-
t.passive ? n.current++ : 0
|
|
434
|
-
]);
|
|
145
|
+
}], [s, m]);
|
|
435
146
|
}
|
|
436
|
-
function
|
|
437
|
-
|
|
147
|
+
function _(t) {
|
|
148
|
+
const e = n.useRef(t);
|
|
149
|
+
return n.useLayoutEffect(() => {
|
|
150
|
+
e.current = t;
|
|
151
|
+
}, [t]), n.useMemo(() => G(t, e), [t]);
|
|
438
152
|
}
|
|
439
153
|
export {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
V as
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
154
|
+
F as ActionError,
|
|
155
|
+
W as Broadcaster,
|
|
156
|
+
v as Lifecycle,
|
|
157
|
+
Q as Op,
|
|
158
|
+
V as Operation,
|
|
159
|
+
X as State,
|
|
160
|
+
T as createAction,
|
|
161
|
+
I as createDistributedAction,
|
|
162
|
+
q as useAction,
|
|
163
|
+
H as useActions,
|
|
164
|
+
_ as useSnapshot,
|
|
165
|
+
N as utils
|
|
449
166
|
};
|
package/dist/chizu.umd.cjs
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(t,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("react/jsx-runtime"),require("react"),require("eventemitter3"),require("immertation")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","eventemitter3","immertation"],d):(t=typeof globalThis<"u"?globalThis:t||self,d(t.Chizu={},t.jsxRuntime,t.React,t.EventEmitter3,t.Immertation))})(this,(function(t,d,S,p,b){"use strict";function k(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const c=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,c.get?c:{enumerable:!0,get:()=>e[r]})}}return n.default=e,Object.freeze(n)}const o=k(S),j=S.createContext(void 0);function z(){return S.useContext(j)}function D({handler:e,children:n}){return d.jsx(j.Provider,{value:e,children:n})}function _(e="anonymous"){return Symbol(`chizu.action/${e}`)}function T(e="anonymous"){return Symbol(`chizu.action/distributed/${e}`)}function h(e){return e.toString().startsWith("Symbol(chizu.action/distributed/")}class w{static Mount=Symbol("lifecycle/mount");static Node=Symbol("lifecycle/node");static Derive=Symbol("lifecycle/derive");static Error=Symbol("lifecycle/error");static Unmount=Symbol("lifecycle/unmount")}function G(e){return new Promise(n=>setTimeout(n,e))}function v(e){return e?!!(e&&typeof e!="symbol"):Symbol(`pk.${Date.now()}.${crypto.randomUUID()}`)}const L=v;function A(e){return(n,r)=>{n.actions.produce(c=>{c[e]=r})}}const q=Object.freeze(Object.defineProperty({__proto__:null,pk:v,set:A,sleep:G,κ:L,λ:A},Symbol.toStringTag,{value:"Module"})),P=o.createContext({instance:new p});function x(){return o.useContext(P)}function B({children:e}){const n=o.useMemo(()=>({instance:new p}),[]);return d.jsx(P.Provider,{value:n,children:e})}function R(e,n){return Object.keys(e).reduce((r,c)=>(Object.defineProperty(r,c,{get(){return n.current[c]},enumerable:!0}),r),{})}const U=Symbol("chizu.action.context");function $(e){const n=z();return o.useCallback(async(r,c)=>{try{if(e.constructor.name==="GeneratorFunction"||e.constructor.name==="AsyncGeneratorFunction"){const f=e(r,c);for await(const E of f);}else await e(r,c)}catch(y){console.error(`Chizu
|
|
2
|
+
|
|
3
|
+
`,y),n?.(y)}},[e,n])}function F(e,n){const r=x(),[c,y]=o.useState(e),f=o.useRef(new b.State(e)),E=C({model:c}),l=o.useMemo(()=>new p,[]),M=o.useCallback(a=>{const s=new AbortController;return{signal:s.signal,actions:{produce(u){if(s.signal.aborted)return;const i=f.current.mutate(m=>u(m));y(f.current.model),a.processes.add(i)},dispatch(...[u,i]){s.signal.aborted||(h(u)?r.instance.emit(u,i):l.emit(u,i))},annotate(u,i){return f.current.annotate(u,i)}},[U]:{controller:s}}},[E.model]);return o.useLayoutEffect(()=>{const a=new n;Object.getOwnPropertySymbols(a).forEach(s=>{const u=s;if(h(s))return void r.instance.on(s,async i=>{const m={processes:new Set},O=Promise.withResolvers();await a[u](M(m),i),m.processes.forEach(g=>f.current.prune(g)),O.resolve()});l.on(s,async i=>{const m={processes:new Set},O=Promise.withResolvers();await a[u](M(m),i),m.processes.forEach(g=>f.current.prune(g)),O.resolve()})})},[l]),o.useLayoutEffect(()=>(l.emit(w.Mount),()=>void l.emit(w.Unmount)),[]),o.useMemo(()=>[c,{dispatch(...[a,s]){h(a)?r.instance.emit(a,s):l.emit(a,s)},consume(){},get inspect(){return f.current.inspect}}],[c,l])}function C(e){const n=o.useRef(e);return o.useLayoutEffect(()=>{n.current=e},[e]),o.useMemo(()=>R(e,n),[e])}Object.defineProperty(t,"Op",{enumerable:!0,get:()=>b.Op}),Object.defineProperty(t,"Operation",{enumerable:!0,get:()=>b.Operation}),Object.defineProperty(t,"State",{enumerable:!0,get:()=>b.State}),t.ActionError=D,t.Broadcaster=B,t.Lifecycle=w,t.createAction=_,t.createDistributedAction=T,t.useAction=$,t.useActions=F,t.useSnapshot=C,t.utils=q,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function Distributed(): (_value: unknown, context: ClassFieldDecoratorContext) => (initialValue: any) => any;
|
|
2
|
+
declare const _default: {
|
|
3
|
+
Synchronous(target: any, propertyKey: string): (...args: any[]) => any;
|
|
4
|
+
Debounce(target: any, propertyKey: string): (...args: any[]) => any;
|
|
5
|
+
};
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ErrorHandler, Props } from './types';
|
|
2
|
+
export declare const ErrorContext: import('react').Context<ErrorHandler | undefined>;
|
|
3
|
+
export declare function useActionError(): ErrorHandler | undefined;
|
|
4
|
+
export declare function ActionError({ handler, children }: Props): import("react/jsx-runtime").JSX.Element;
|