chizu 0.2.21 → 0.2.22
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 +31 -23
- package/dist/broadcast/index.d.ts +9 -1
- package/dist/broadcast/utils.d.ts +1 -1
- package/dist/chizu.js +120 -123
- package/dist/chizu.umd.cjs +1 -1
- package/dist/controller/types.d.ts +2 -2
- package/dist/errors/utils.d.ts +11 -6
- package/dist/index.d.ts +8 -10
- package/dist/module/index.d.ts +2 -2
- package/dist/module/renderer/utils.d.ts +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/view/types.d.ts +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Strongly typed React framework using generators and efficiently updated views al
|
|
|
9
9
|
1. [Benefits](#benefits)
|
|
10
10
|
1. [Getting started](#getting-started)
|
|
11
11
|
1. [Handling errors](#handling-errors)
|
|
12
|
-
1. [Distributed
|
|
12
|
+
1. [Distributed actions](#distributed-actions)
|
|
13
13
|
1. [Module context](#module-context)
|
|
14
14
|
|
|
15
15
|
## Benefits
|
|
@@ -32,7 +32,7 @@ Actions are responsible for mutating the state of the view. In the below example
|
|
|
32
32
|
```tsx
|
|
33
33
|
export default <Actions<Module>>function Actions(module) {
|
|
34
34
|
return {
|
|
35
|
-
[
|
|
35
|
+
[Action.Name](name) {
|
|
36
36
|
return module.actions.produce((draft) => {
|
|
37
37
|
draft.name = name;
|
|
38
38
|
});
|
|
@@ -44,13 +44,13 @@ export default <Actions<Module>>function Actions(module) {
|
|
|
44
44
|
```tsx
|
|
45
45
|
export default function Profile(props: Props): React.ReactElement {
|
|
46
46
|
return (
|
|
47
|
-
<
|
|
47
|
+
<Scope<Module> using={{ model, actions, props }}>
|
|
48
48
|
{(module) => (
|
|
49
49
|
<>
|
|
50
50
|
<p>Hey {module.model.name}</p>
|
|
51
51
|
|
|
52
52
|
<button
|
|
53
|
-
onClick={() => module.actions.dispatch([
|
|
53
|
+
onClick={() => module.actions.dispatch([Action.Name, randomName()])}
|
|
54
54
|
>
|
|
55
55
|
Switch profile
|
|
56
56
|
</button>
|
|
@@ -66,7 +66,7 @@ You can perform asynchronous operations in the action which will cause the assoc
|
|
|
66
66
|
```tsx
|
|
67
67
|
export default <Actions<Module>>function Actions(module) {
|
|
68
68
|
return {
|
|
69
|
-
async *[
|
|
69
|
+
async *[Action.Name]() {
|
|
70
70
|
yield module.actions.produce((draft) => {
|
|
71
71
|
draft.name = null;
|
|
72
72
|
});
|
|
@@ -84,12 +84,12 @@ export default <Actions<Module>>function Actions(module) {
|
|
|
84
84
|
```tsx
|
|
85
85
|
export default function Profile(props: Props): React.ReactElement {
|
|
86
86
|
return (
|
|
87
|
-
<
|
|
87
|
+
<Scope<Module> using={{ model, actions, props }}>
|
|
88
88
|
{(module) => (
|
|
89
89
|
<>
|
|
90
90
|
<p>Hey {module.model.name}</p>
|
|
91
91
|
|
|
92
|
-
<button onClick={() => module.actions.dispatch([
|
|
92
|
+
<button onClick={() => module.actions.dispatch([Action.Name])}>
|
|
93
93
|
Switch profile
|
|
94
94
|
</button>
|
|
95
95
|
</>
|
|
@@ -104,7 +104,7 @@ However in the above example where the name is fetched asynchronously, there is
|
|
|
104
104
|
```tsx
|
|
105
105
|
export default <Actions<Module>>function Actions(module) {
|
|
106
106
|
return {
|
|
107
|
-
async *[
|
|
107
|
+
async *[Action.Name]() {
|
|
108
108
|
yield module.actions.produce((draft) => {
|
|
109
109
|
draft.name = module.actions.annotate(null);
|
|
110
110
|
});
|
|
@@ -121,7 +121,7 @@ export default <Actions<Module>>function Actions(module) {
|
|
|
121
121
|
```tsx
|
|
122
122
|
export default function ProfileView(props: Props): React.ReactElement {
|
|
123
123
|
return (
|
|
124
|
-
<
|
|
124
|
+
<Scope<Module> using={{ module, actions, props }}>
|
|
125
125
|
{(module) => (
|
|
126
126
|
<>
|
|
127
127
|
<p>Hey {module.model.name}</p>
|
|
@@ -130,7 +130,7 @@ export default function ProfileView(props: Props): React.ReactElement {
|
|
|
130
130
|
|
|
131
131
|
<button
|
|
132
132
|
disabled={module.validate.name.is(State.Op.Update)}
|
|
133
|
-
onClick={() => module.actions.dispatch([
|
|
133
|
+
onClick={() => module.actions.dispatch([Action.Name])}
|
|
134
134
|
>
|
|
135
135
|
Switch profile
|
|
136
136
|
</button>
|
|
@@ -148,7 +148,7 @@ Most errors are likely to occur in the actions because the views should be free
|
|
|
148
148
|
```tsx
|
|
149
149
|
export default <Actions<Module>>function Actions(module) {
|
|
150
150
|
return {
|
|
151
|
-
*[
|
|
151
|
+
*[Action.Name]() {
|
|
152
152
|
yield module.actions.produce((draft) => {
|
|
153
153
|
draft.name = null;
|
|
154
154
|
});
|
|
@@ -165,12 +165,12 @@ export default <Actions<Module>>function Actions(module) {
|
|
|
165
165
|
|
|
166
166
|
However in eventualities where an error has not been caught in an action then the `Lifecycle.Error` is the next best thing – use it to display a toast message and log it your chosen error log service.
|
|
167
167
|
|
|
168
|
-
Additionally when rendering an error may be thrown which prevents the DOM from updating as you'd expect – perhaps a side effect has delivered an unexpected data structure. In those cases again `Lifecycle.Error` is your friend. When such an error is thrown the component
|
|
168
|
+
Additionally when rendering an error may be thrown which prevents the DOM from updating as you'd expect – perhaps a side effect has delivered an unexpected data structure. In those cases again `Lifecycle.Error` is your friend. When such an error is thrown the component boundary will be switched to `Boundary.Error` which you detect using `module.boundary.is(Boundary.Error)` and switch to an alternative markup that _should_ render, within that you could display a button to attempt recovery – simply call an action again and update the meta to switch the boundary back to `Boundary.Default`:
|
|
169
169
|
|
|
170
170
|
```tsx
|
|
171
171
|
export default <Actions<Module>>function Actions(module) {
|
|
172
172
|
return {
|
|
173
|
-
*[
|
|
173
|
+
*[Action.Recover]() {
|
|
174
174
|
yield module.actions.produce((draft) => {
|
|
175
175
|
draft.name = null;
|
|
176
176
|
});
|
|
@@ -178,7 +178,7 @@ export default <Actions<Module>>function Actions(module) {
|
|
|
178
178
|
const name = await fetch(/* ... */);
|
|
179
179
|
|
|
180
180
|
return module.actions.produce((draft, meta) => {
|
|
181
|
-
meta.
|
|
181
|
+
meta.boundary = Boundary.Default;
|
|
182
182
|
draft.name = name;
|
|
183
183
|
});
|
|
184
184
|
},
|
|
@@ -186,34 +186,42 @@ export default <Actions<Module>>function Actions(module) {
|
|
|
186
186
|
};
|
|
187
187
|
```
|
|
188
188
|
|
|
189
|
-
If the component again throws an error after attempting recovery, it will simply switch back to the `
|
|
189
|
+
If the component again throws an error after attempting recovery, it will simply switch back to the `Boundary.Error` again.
|
|
190
190
|
|
|
191
|
-
## Distributed
|
|
191
|
+
## Distributed actions
|
|
192
192
|
|
|
193
193
|
Actions can communicate with other mounted actions using the `DistributedActions` approach. You can configure the enum and union type in the root of your application:
|
|
194
194
|
|
|
195
195
|
```ts
|
|
196
|
-
export enum
|
|
196
|
+
export enum DistributedAction {
|
|
197
197
|
SignedOut = "distributed/signed-out",
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
export type DistributedActions = [
|
|
200
|
+
export type DistributedActions = [DistributedAction.SignedOut];
|
|
201
201
|
```
|
|
202
202
|
|
|
203
|
-
Note that you must prefix the enum name with `distributed` for it to behave as a distributed event, otherwise it'll be considered a module event only. Once you have the distributed
|
|
203
|
+
Note that you must prefix the enum name with `distributed` for it to behave as a distributed event, otherwise it'll be considered a module event only. Once you have the distributed actions you simply need to augment the module actions union with the `DistributedActions` and use it as you do other actions:
|
|
204
204
|
|
|
205
205
|
```ts
|
|
206
|
-
export type Actions = DistributedActions | [
|
|
206
|
+
export type Actions = DistributedActions | [Action.Task, string]; // etc...
|
|
207
207
|
```
|
|
208
208
|
|
|
209
209
|
## Module context
|
|
210
210
|
|
|
211
|
-
In the eventuality that you have a component but don't want associated actions, models, etc… but want to still fire
|
|
211
|
+
In the eventuality that you have a component but don't want associated actions, models, etc… but want to still fire actions either the closest module or a distributed action, you can use the `useScoped` hook:
|
|
212
212
|
|
|
213
213
|
```ts
|
|
214
|
-
const module =
|
|
214
|
+
const module = useScoped<Module>();
|
|
215
215
|
|
|
216
216
|
// ...
|
|
217
217
|
|
|
218
|
-
module.actions.dispatch([
|
|
218
|
+
module.actions.dispatch([Action.Task, "My task that needs to be done."]);
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Alternatively you can pass the current module as a prop to your components using the `Scoped` helper:
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
export type Props = {
|
|
225
|
+
module: Scoped<Module>;
|
|
226
|
+
};
|
|
219
227
|
```
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { BroadcastContext, Props } from './types.ts';
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
export declare function useBroadcast(): BroadcastContext;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Note: only needed if you want to create a new broadcast context, useful for
|
|
6
|
+
* libraries that want to provide their own broadcast context without intefering
|
|
7
|
+
* with the app's broadcast context.
|
|
8
|
+
*
|
|
9
|
+
* @param param0 - { children }: Props
|
|
10
|
+
* @returns {React.ReactNode}
|
|
11
|
+
*/
|
|
12
|
+
export declare function Broadcaster({ children }: Props): React.ReactNode;
|
package/dist/chizu.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
var J = Object.defineProperty;
|
|
2
|
-
var
|
|
2
|
+
var U = (t) => {
|
|
3
3
|
throw TypeError(t);
|
|
4
4
|
};
|
|
5
5
|
var Q = (t, e, n) => e in t ? J(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
import { jsx as
|
|
6
|
+
var b = (t, e, n) => Q(t, typeof e != "symbol" ? e + "" : e, n), _ = (t, e, n) => e.has(t) || U("Cannot " + n);
|
|
7
|
+
var g = (t, e, n) => (_(t, e, "read from private field"), n ? n.call(t) : e.get(t)), S = (t, e, n) => e.has(t) ? U("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, n), x = (t, e, n, r) => (_(t, e, "write to private field"), r ? r.call(t, n) : e.set(t, n), n);
|
|
8
|
+
import { jsx as M } from "react/jsx-runtime";
|
|
9
9
|
import * as i from "react";
|
|
10
|
-
import
|
|
10
|
+
import k from "eventemitter3";
|
|
11
11
|
import { Immer as W, enablePatches as G } from "immer";
|
|
12
12
|
import p from "lodash/get";
|
|
13
|
-
import
|
|
13
|
+
import P from "traverse";
|
|
14
14
|
class $ {
|
|
15
15
|
constructor(e) {
|
|
16
16
|
this.value = e;
|
|
@@ -21,14 +21,14 @@ class K {
|
|
|
21
21
|
return new $(e);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
b(K, "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
|
|
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 || {}), j = /* @__PURE__ */ ((t) => (t[t.Default = 0] = "Default", t[t.Error = 1] = "Error", t))(j || {});
|
|
32
32
|
function V(t) {
|
|
33
33
|
return new Promise((e) => setTimeout(e, t));
|
|
34
34
|
}
|
|
@@ -38,26 +38,26 @@ function X(t) {
|
|
|
38
38
|
function m(t) {
|
|
39
39
|
return JSON.stringify(t);
|
|
40
40
|
}
|
|
41
|
-
const
|
|
41
|
+
const w = Symbol("meta"), yt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
42
42
|
__proto__: null,
|
|
43
43
|
hash: m,
|
|
44
|
-
meta:
|
|
44
|
+
meta: w,
|
|
45
45
|
pk: X,
|
|
46
46
|
sleep: V
|
|
47
47
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
48
48
|
function l(t, e) {
|
|
49
49
|
const n = i.useRef(null), r = i.useRef(null);
|
|
50
50
|
return i.useMemo(() => {
|
|
51
|
-
const
|
|
52
|
-
if (r.current !==
|
|
53
|
-
r.current =
|
|
54
|
-
const
|
|
55
|
-
return n.current =
|
|
51
|
+
const s = m(e);
|
|
52
|
+
if (r.current !== s) {
|
|
53
|
+
r.current = s;
|
|
54
|
+
const o = t();
|
|
55
|
+
return n.current = o, o;
|
|
56
56
|
}
|
|
57
57
|
return n.current;
|
|
58
58
|
}, e);
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function A(t, e) {
|
|
61
61
|
const n = i.useRef(null);
|
|
62
62
|
i.useEffect(() => {
|
|
63
63
|
const r = m(e);
|
|
@@ -65,20 +65,20 @@ function _(t, e) {
|
|
|
65
65
|
return n.current = r, t();
|
|
66
66
|
}, e);
|
|
67
67
|
}
|
|
68
|
-
const
|
|
69
|
-
appEmitter: new
|
|
68
|
+
const B = i.createContext({
|
|
69
|
+
appEmitter: new k()
|
|
70
70
|
});
|
|
71
|
-
function
|
|
72
|
-
return i.useContext(
|
|
71
|
+
function H() {
|
|
72
|
+
return i.useContext(B);
|
|
73
73
|
}
|
|
74
|
-
function
|
|
74
|
+
function wt({ children: t }) {
|
|
75
75
|
const e = l(
|
|
76
76
|
() => ({
|
|
77
|
-
appEmitter: new
|
|
77
|
+
appEmitter: new k()
|
|
78
78
|
}),
|
|
79
79
|
[]
|
|
80
80
|
);
|
|
81
|
-
return /* @__PURE__ */
|
|
81
|
+
return /* @__PURE__ */ M(B.Provider, { value: e, children: t });
|
|
82
82
|
}
|
|
83
83
|
const a = {
|
|
84
84
|
immer: new W(),
|
|
@@ -86,9 +86,9 @@ const a = {
|
|
|
86
86
|
};
|
|
87
87
|
G();
|
|
88
88
|
a.immer.setAutoFreeze(!1);
|
|
89
|
-
class
|
|
89
|
+
class C {
|
|
90
90
|
constructor(e, n, r = null) {
|
|
91
|
-
|
|
91
|
+
b(this, "process");
|
|
92
92
|
this.value = e, this.operations = n, this.field = r, this.process = null;
|
|
93
93
|
}
|
|
94
94
|
attach(e) {
|
|
@@ -96,89 +96,89 @@ class P {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
function Y(t, e = []) {
|
|
99
|
-
return new
|
|
99
|
+
return new C(t, e);
|
|
100
100
|
}
|
|
101
|
-
class
|
|
101
|
+
class O {
|
|
102
102
|
constructor(e, n = e) {
|
|
103
103
|
this.stateless = e, this.stateful = n;
|
|
104
104
|
}
|
|
105
105
|
get validatable() {
|
|
106
|
-
return
|
|
106
|
+
return T(this.stateful);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function T(t, e = []) {
|
|
110
110
|
return new Proxy(t, {
|
|
111
111
|
get(n, r) {
|
|
112
112
|
switch (r) {
|
|
113
113
|
case "is":
|
|
114
|
-
return (
|
|
115
|
-
const
|
|
116
|
-
if (!
|
|
114
|
+
return (s) => {
|
|
115
|
+
const o = R(t, e);
|
|
116
|
+
if (!o) return !1;
|
|
117
117
|
const c = new Set(
|
|
118
|
-
|
|
118
|
+
o.flatMap((d) => d.operations)
|
|
119
119
|
);
|
|
120
120
|
return !!(Array.from(c).reduce(
|
|
121
|
-
(d,
|
|
121
|
+
(d, f) => d | (f ?? 0),
|
|
122
122
|
0
|
|
123
|
-
) &
|
|
123
|
+
) & s);
|
|
124
124
|
};
|
|
125
125
|
case "pending":
|
|
126
|
-
return () => !!
|
|
126
|
+
return () => !!R(t, e);
|
|
127
127
|
case "draft":
|
|
128
128
|
return () => {
|
|
129
|
-
const
|
|
130
|
-
if (!
|
|
131
|
-
const
|
|
132
|
-
return
|
|
129
|
+
const s = R(t, e);
|
|
130
|
+
if (!s) return p(t, e);
|
|
131
|
+
const o = s.flatMap((c) => c.operations).find((c) => c instanceof $);
|
|
132
|
+
return o ? o.value : p(t, e);
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
|
-
return
|
|
135
|
+
return T(t, [...e, String(r)]);
|
|
136
136
|
}
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
|
-
function
|
|
140
|
-
const r = typeof p(t, e) == "object" ? e : e.slice(0, -1),
|
|
141
|
-
return
|
|
139
|
+
function R(t, e) {
|
|
140
|
+
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]) ?? [];
|
|
141
|
+
return o.length > 0 ? o : null;
|
|
142
142
|
}
|
|
143
|
-
function
|
|
143
|
+
function z(t, e, n) {
|
|
144
144
|
function r(c) {
|
|
145
|
-
return
|
|
145
|
+
return P(c).forEach(function() {
|
|
146
146
|
if (this.key === a.annotations) {
|
|
147
147
|
this.block();
|
|
148
148
|
return;
|
|
149
149
|
}
|
|
150
|
-
this.node instanceof
|
|
150
|
+
this.node instanceof C && this.update(this.node.value);
|
|
151
151
|
});
|
|
152
152
|
}
|
|
153
|
-
function
|
|
154
|
-
return
|
|
153
|
+
function s(c) {
|
|
154
|
+
return P(c).forEach(function() {
|
|
155
155
|
if (this.key === a.annotations) {
|
|
156
156
|
this.block();
|
|
157
157
|
return;
|
|
158
158
|
}
|
|
159
|
-
if (this.node instanceof
|
|
159
|
+
if (this.node instanceof C) {
|
|
160
160
|
const u = typeof this.node.value == "object", d = [
|
|
161
161
|
...u ? this.path : this.path.slice(0, -1),
|
|
162
162
|
a.annotations
|
|
163
|
-
],
|
|
163
|
+
], f = p(t.stateful, d) ?? [], y = this.node.attach(e);
|
|
164
164
|
u ? this.update(
|
|
165
165
|
{
|
|
166
166
|
...this.node.value,
|
|
167
|
-
[a.annotations]: [
|
|
167
|
+
[a.annotations]: [y, ...f]
|
|
168
168
|
},
|
|
169
169
|
!0
|
|
170
|
-
) : (this.parent && (this.parent.node[a.annotations] = [
|
|
170
|
+
) : (this.parent && (this.parent.node[a.annotations] = [y, ...f]), this.update(this.node.value, !0));
|
|
171
171
|
}
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
|
-
const
|
|
175
|
-
return new
|
|
176
|
-
r(a.immer.produce(t.stateless,
|
|
177
|
-
|
|
174
|
+
const o = (c) => n(c, c[w]);
|
|
175
|
+
return new O(
|
|
176
|
+
r(a.immer.produce(t.stateless, o)),
|
|
177
|
+
s(a.immer.produce(t.stateful, o))
|
|
178
178
|
);
|
|
179
179
|
}
|
|
180
180
|
function D(t, e) {
|
|
181
|
-
const n =
|
|
181
|
+
const n = P(t.stateful).forEach(function() {
|
|
182
182
|
if (this.key === a.annotations) {
|
|
183
183
|
this.block();
|
|
184
184
|
return;
|
|
@@ -189,14 +189,14 @@ function D(t, e) {
|
|
|
189
189
|
{
|
|
190
190
|
...this.node,
|
|
191
191
|
[a.annotations]: r.filter(
|
|
192
|
-
(
|
|
192
|
+
(s) => s.process !== e
|
|
193
193
|
)
|
|
194
194
|
},
|
|
195
195
|
!0
|
|
196
196
|
);
|
|
197
197
|
}
|
|
198
198
|
});
|
|
199
|
-
return new
|
|
199
|
+
return new O(t.stateless, n);
|
|
200
200
|
}
|
|
201
201
|
function Z(t) {
|
|
202
202
|
return l(
|
|
@@ -211,7 +211,7 @@ function Z(t) {
|
|
|
211
211
|
return Y(e, n);
|
|
212
212
|
},
|
|
213
213
|
produce(e) {
|
|
214
|
-
return (n, r) =>
|
|
214
|
+
return (n, r) => z(n, r, e);
|
|
215
215
|
},
|
|
216
216
|
dispatch([e, ...n]) {
|
|
217
217
|
if (e == null) return Promise.reject();
|
|
@@ -227,9 +227,9 @@ function Z(t) {
|
|
|
227
227
|
get validate() {
|
|
228
228
|
return t.model.current.validatable;
|
|
229
229
|
},
|
|
230
|
-
|
|
230
|
+
boundary: {
|
|
231
231
|
is(e) {
|
|
232
|
-
return t.model.current.stateless[
|
|
232
|
+
return t.model.current.stateless[w].boundary === e;
|
|
233
233
|
}
|
|
234
234
|
},
|
|
235
235
|
actions: {
|
|
@@ -247,34 +247,31 @@ function Z(t) {
|
|
|
247
247
|
function L(t) {
|
|
248
248
|
return l(() => {
|
|
249
249
|
const e = t.options.using.actions(t.actions.controller);
|
|
250
|
-
return Object.entries(e).forEach(([r,
|
|
250
|
+
return Object.entries(e).forEach(([r, s]) => t.dispatchers.attach(r, s)), e;
|
|
251
251
|
}, []);
|
|
252
252
|
}
|
|
253
253
|
function N(t) {
|
|
254
254
|
return t.startsWith("distributed");
|
|
255
255
|
}
|
|
256
|
-
function gt(t) {
|
|
257
|
-
return t instanceof B;
|
|
258
|
-
}
|
|
259
256
|
function bt(t) {
|
|
260
|
-
return t instanceof
|
|
257
|
+
return t instanceof I;
|
|
261
258
|
}
|
|
262
|
-
function
|
|
263
|
-
return t instanceof
|
|
259
|
+
function q(t) {
|
|
260
|
+
return t instanceof I || t instanceof Error ? t : new Error("Unknown error", { cause: t });
|
|
264
261
|
}
|
|
265
262
|
var v, E;
|
|
266
|
-
class
|
|
263
|
+
class I extends Error {
|
|
267
264
|
constructor(n, r = null) {
|
|
268
265
|
super(String(r));
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
266
|
+
S(this, v);
|
|
267
|
+
S(this, E);
|
|
268
|
+
x(this, v, n), x(this, E, r);
|
|
272
269
|
}
|
|
273
270
|
get type() {
|
|
274
|
-
return
|
|
271
|
+
return g(this, v);
|
|
275
272
|
}
|
|
276
273
|
get message() {
|
|
277
|
-
return
|
|
274
|
+
return g(this, E) || "";
|
|
278
275
|
}
|
|
279
276
|
}
|
|
280
277
|
v = new WeakMap(), E = new WeakMap();
|
|
@@ -284,41 +281,41 @@ function tt({
|
|
|
284
281
|
return t();
|
|
285
282
|
}
|
|
286
283
|
function et(t) {
|
|
287
|
-
return (e, n) => async (r = Promise.withResolvers(),
|
|
284
|
+
return (e, n) => async (r = Promise.withResolvers(), s) => {
|
|
288
285
|
if (typeof n != "function") return;
|
|
289
|
-
const
|
|
286
|
+
const o = Symbol("process"), c = n(...s);
|
|
290
287
|
try {
|
|
291
288
|
if (c == null) return;
|
|
292
289
|
if (typeof c == "function") {
|
|
293
|
-
const u = c(t.model.current,
|
|
294
|
-
t.model.current = D(u,
|
|
290
|
+
const u = c(t.model.current, o);
|
|
291
|
+
t.model.current = D(u, o), t.update.rerender(), r.resolve();
|
|
295
292
|
return;
|
|
296
293
|
}
|
|
297
294
|
for (; ; ) {
|
|
298
295
|
const { value: u, done: d } = await c.next();
|
|
299
296
|
if (d) {
|
|
300
|
-
const
|
|
301
|
-
t.model.current = D(
|
|
297
|
+
const y = u(t.model.current, o);
|
|
298
|
+
t.model.current = D(y, o), t.update.rerender();
|
|
302
299
|
break;
|
|
303
300
|
}
|
|
304
|
-
const
|
|
305
|
-
t.model.current =
|
|
301
|
+
const f = u;
|
|
302
|
+
t.model.current = f(t.model.current, o), t.update.rerender(), r.resolve();
|
|
306
303
|
}
|
|
307
304
|
} catch (u) {
|
|
308
|
-
D(t.model.current,
|
|
305
|
+
D(t.model.current, o), t.update.rerender(), t.unicast.emit(h.Error, r, [q(u)]);
|
|
309
306
|
}
|
|
310
307
|
};
|
|
311
308
|
}
|
|
312
309
|
function nt(t) {
|
|
313
|
-
const e =
|
|
310
|
+
const e = H(), n = l(() => new k(), []), r = et({ ...t, unicast: n });
|
|
314
311
|
return l(() => ({
|
|
315
|
-
attach(
|
|
316
|
-
const c = String(
|
|
317
|
-
N(c) ? e.appEmitter.on(c, r(
|
|
312
|
+
attach(s, o) {
|
|
313
|
+
const c = String(s);
|
|
314
|
+
N(c) ? e.appEmitter.on(c, r(s, o)) : n.on(c, r(s, o));
|
|
318
315
|
},
|
|
319
|
-
dispatch(
|
|
320
|
-
const u = String(
|
|
321
|
-
N(u) ? e.appEmitter.emit(u, c,
|
|
316
|
+
dispatch(s, o, c) {
|
|
317
|
+
const u = String(s);
|
|
318
|
+
N(u) ? e.appEmitter.emit(u, c, o) : n.emit(u, c, o);
|
|
322
319
|
}
|
|
323
320
|
}), []);
|
|
324
321
|
}
|
|
@@ -326,16 +323,16 @@ function rt() {
|
|
|
326
323
|
const t = i.useRef(null);
|
|
327
324
|
return l(() => ({ customElement: t }), []);
|
|
328
325
|
}
|
|
329
|
-
function
|
|
330
|
-
|
|
331
|
-
t.dispatchers.dispatch(
|
|
332
|
-
}, [t.options.using.props]),
|
|
326
|
+
function ot(t) {
|
|
327
|
+
A(() => {
|
|
328
|
+
t.dispatchers.dispatch(h.Derive, []);
|
|
329
|
+
}, [t.options.using.props]), A(() => (t.dispatchers.dispatch(h.Mount, []), t.dispatchers.dispatch(h.Node, [
|
|
333
330
|
t.elements.customElement.current
|
|
334
|
-
]), () => t.dispatchers.dispatch(
|
|
331
|
+
]), () => t.dispatchers.dispatch(h.Unmount, [])), []);
|
|
335
332
|
}
|
|
336
|
-
function
|
|
337
|
-
const e = l(() => ({ ...t.options.using.model ?? {}, [
|
|
338
|
-
return i.useRef(new
|
|
333
|
+
function st(t) {
|
|
334
|
+
const e = l(() => ({ ...t.options.using.model ?? {}, [w]: { boundary: j.Default } }), []);
|
|
335
|
+
return i.useRef(new O(e, e));
|
|
339
336
|
}
|
|
340
337
|
function ct() {
|
|
341
338
|
return i.useRef(/* @__PURE__ */ new Set());
|
|
@@ -349,9 +346,10 @@ const it = {
|
|
|
349
346
|
}, F = i.createContext(
|
|
350
347
|
null
|
|
351
348
|
);
|
|
352
|
-
function
|
|
349
|
+
function gt() {
|
|
353
350
|
const t = i.useContext(F);
|
|
354
|
-
if (!t)
|
|
351
|
+
if (!t)
|
|
352
|
+
throw new Error("useScoped is not being used within a scoped module.");
|
|
355
353
|
return t;
|
|
356
354
|
}
|
|
357
355
|
class at extends i.Component {
|
|
@@ -359,27 +357,27 @@ class at extends i.Component {
|
|
|
359
357
|
super(e), this.state = { error: null };
|
|
360
358
|
}
|
|
361
359
|
componentDidCatch(e) {
|
|
362
|
-
const n = Symbol("process"), r =
|
|
363
|
-
|
|
360
|
+
const n = Symbol("process"), r = z(this.props.model.current, n, (s, o) => {
|
|
361
|
+
o.boundary = j.Error;
|
|
364
362
|
});
|
|
365
|
-
this.props.model.current = r, this.props.update.rerender(), this.props.dispatchers.dispatch(
|
|
363
|
+
this.props.model.current = r, this.props.update.rerender(), this.props.dispatchers.dispatch(h.Error, [q(e)]);
|
|
366
364
|
}
|
|
367
365
|
render() {
|
|
368
|
-
return /* @__PURE__ */
|
|
366
|
+
return /* @__PURE__ */ M(tt, { children: this.props.children });
|
|
369
367
|
}
|
|
370
368
|
}
|
|
371
369
|
function lt({
|
|
372
370
|
options: t
|
|
373
371
|
}) {
|
|
374
|
-
const e = ut(), n = ct(), r = rt(),
|
|
375
|
-
broadcast:
|
|
372
|
+
const e = ut(), n = ct(), r = rt(), s = H(), o = st({ options: t }), c = nt({
|
|
373
|
+
broadcast: s,
|
|
376
374
|
options: t,
|
|
377
375
|
update: e,
|
|
378
|
-
model:
|
|
376
|
+
model: o,
|
|
379
377
|
queue: n
|
|
380
|
-
}), u = Z({ model:
|
|
381
|
-
return L({ options: t, dispatchers: c, actions: u }),
|
|
382
|
-
model:
|
|
378
|
+
}), u = Z({ model: o, dispatchers: c });
|
|
379
|
+
return L({ options: t, dispatchers: c, actions: u }), ot({ options: t, dispatchers: c, elements: r }), l(() => i.createElement(at, {
|
|
380
|
+
model: o,
|
|
383
381
|
dispatchers: c,
|
|
384
382
|
update: e,
|
|
385
383
|
module: u.view,
|
|
@@ -397,18 +395,17 @@ function lt({
|
|
|
397
395
|
}), [e.hash, m(t.using.props)]);
|
|
398
396
|
}
|
|
399
397
|
function dt(t) {
|
|
400
|
-
return /* @__PURE__ */
|
|
398
|
+
return /* @__PURE__ */ M(lt, { options: t });
|
|
401
399
|
}
|
|
402
|
-
const
|
|
400
|
+
const St = i.memo(dt, (t, e) => m(t) === m(e));
|
|
403
401
|
export {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
402
|
+
j as Boundary,
|
|
403
|
+
wt as Broadcaster,
|
|
404
|
+
h as Lifecycle,
|
|
405
|
+
St as Scope,
|
|
407
406
|
K as State,
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
gt as
|
|
411
|
-
|
|
412
|
-
xt as useModule,
|
|
413
|
-
wt as utils
|
|
407
|
+
I as TypedError,
|
|
408
|
+
bt as isTypedError,
|
|
409
|
+
gt as useScoped,
|
|
410
|
+
yt as utils
|
|
414
411
|
};
|
package/dist/chizu.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,i){typeof exports=="object"&&typeof module<"u"?i(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"],i):(s=typeof globalThis<"u"?globalThis:s||self,i(s.Chizu={},s.jsxRuntime,s.React,s.EventEmitter3,s.Immer,s.get,s.Traverse))})(this,function(s,i,d,
|
|
1
|
+
(function(s,i){typeof exports=="object"&&typeof module<"u"?i(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"],i):(s=typeof globalThis<"u"?globalThis:s||self,i(s.Chizu={},s.jsxRuntime,s.React,s.EventEmitter3,s.Immer,s.get,s.Traverse))})(this,function(s,i,d,y,U,E,P){"use strict";var ve=Object.defineProperty;var W=s=>{throw TypeError(s)};var be=(s,i,d)=>i in s?ve(s,i,{enumerable:!0,configurable:!0,writable:!0,value:d}):s[i]=d;var T=(s,i,d)=>be(s,typeof i!="symbol"?i+"":i,d),G=(s,i,d)=>i.has(s)||W("Cannot "+d);var k=(s,i,d)=>(G(s,i,"read from private field"),d?d.call(s):i.get(s)),_=(s,i,d)=>i.has(s)?W("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(s):i.set(s,d),q=(s,i,d,y)=>(G(s,i,"write to private field"),y?y.call(s,d):i.set(s,d),d);var w,g;function K(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 l=K(d);class A{constructor(t){this.value=t}}class B{static Draft(t){return new A(t)}}T(B,"Op",{Add:1,Remove:2,Update:4,Move:8,Replace:16});var m=(e=>(e.Mount="lifecycle/mount",e.Node="lifecycle/node",e.Derive="lifecycle/derive",e.Error="lifecycle/error",e.Unmount="lifecycle/unmount",e))(m||{}),S=(e=>(e[e.Default=0]="Default",e[e.Error=1]="Error",e))(S||{});function V(e){return new Promise(t=>setTimeout(t,e))}function X(e){return e?!!(e&&typeof e!="symbol"):Symbol(`pk.${Date.now()}.${crypto.randomUUID()}`)}function v(e){return JSON.stringify(e)}const j=Symbol("meta"),Y=Object.freeze(Object.defineProperty({__proto__:null,hash:v,meta:j,pk:X,sleep:V},Symbol.toStringTag,{value:"Module"}));function h(e,t){const n=l.useRef(null),r=l.useRef(null);return l.useMemo(()=>{const c=v(t);if(r.current!==c){r.current=c;const o=e();return n.current=o,o}return n.current},t)}function N(e,t){const n=l.useRef(null);l.useEffect(()=>{const r=v(t);if(n.current!==r)return n.current=r,e()},t)}const z=l.createContext({appEmitter:new y});function $(){return l.useContext(z)}function Z({children:e}){const t=h(()=>({appEmitter:new y}),[]);return i.jsx(z.Provider,{value:t,children:e})}const f={immer:new U.Immer,annotations:Symbol("annotations")};U.enablePatches(),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 L(e,t=[]){return new R(e,t)}class x{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 c=>{const o=O(e,t);if(!o)return!1;const u=new Set(o.flatMap(p=>p.operations));return!!(Array.from(u).reduce((p,b)=>p|(b??0),0)&c)};case"pending":return()=>!!O(e,t);case"draft":return()=>{const c=O(e,t);if(!c)return E(e,t);const o=c.flatMap(u=>u.operations).find(u=>u instanceof A);return o?o.value:E(e,t)}}return H(e,[...t,String(r)])}})}function O(e,t){const r=typeof E(e,t)=="object"?t:t.slice(0,-1),c=r.length===0?e:E(e,r),o=(c==null?void 0:c[f.annotations])??[];return o.length>0?o:null}function I(e,t,n){function r(u){return P(u).forEach(function(){if(this.key===f.annotations){this.block();return}this.node instanceof R&&this.update(this.node.value)})}function c(u){return P(u).forEach(function(){if(this.key===f.annotations){this.block();return}if(this.node instanceof R){const a=typeof this.node.value=="object",p=[...a?this.path:this.path.slice(0,-1),f.annotations],b=E(e.stateful,p)??[],D=this.node.attach(t);a?this.update({...this.node.value,[f.annotations]:[D,...b]},!0):(this.parent&&(this.parent.node[f.annotations]=[D,...b]),this.update(this.node.value,!0))}})}const o=u=>n(u,u[j]);return new x(r(f.immer.produce(e.stateless,o)),c(f.immer.produce(e.stateful,o)))}function M(e,t){const n=P(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(c=>c.process!==t)},!0)}});return new x(e.stateless,n)}function ee(e){return h(()=>({controller:{get model(){return e.model.current.stateful},queue:[],actions:{annotate(t,n){return L(t,n)},produce(t){return(n,r)=>I(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:{get model(){return e.model.current.stateless},get validate(){return e.model.current.validatable},boundary:{is(t){return e.model.current.stateless[j].boundary===t}},actions:{dispatch([t,...n]){if(t==null)return Promise.reject();const r=Promise.withResolvers();return e.dispatchers.dispatch(t,n,r),r.promise}}}}),[])}function te(e){return h(()=>{const t=e.options.using.actions(e.actions.controller);return Object.entries(t).forEach(([r,c])=>e.dispatchers.attach(r,c)),t},[])}function F(e){return e.startsWith("distributed")}function ne(e){return e instanceof C}function J(e){return e instanceof C||e instanceof Error?e:new Error("Unknown error",{cause:e})}class C extends Error{constructor(n,r=null){super(String(r));_(this,w);_(this,g);q(this,w,n),q(this,g,r)}get type(){return k(this,w)}get message(){return k(this,g)||""}}w=new WeakMap,g=new WeakMap;function re({children:e}){return e()}function se(e){return(t,n)=>async(r=Promise.withResolvers(),c)=>{if(typeof n!="function")return;const o=Symbol("process"),u=n(...c);try{if(u==null)return;if(typeof u=="function"){const a=u(e.model.current,o);e.model.current=M(a,o),e.update.rerender(),r.resolve();return}for(;;){const{value:a,done:p}=await u.next();if(p){const D=a(e.model.current,o);e.model.current=M(D,o),e.update.rerender();break}const b=a;e.model.current=b(e.model.current,o),e.update.rerender(),r.resolve()}}catch(a){M(e.model.current,o),e.update.rerender(),e.unicast.emit(m.Error,r,[J(a)])}}}function oe(e){const t=$(),n=h(()=>new y,[]),r=se({...e,unicast:n});return h(()=>({attach(c,o){const u=String(c);F(u)?t.appEmitter.on(u,r(c,o)):n.on(u,r(c,o))},dispatch(c,o,u){const a=String(c);F(a)?t.appEmitter.emit(a,u,o):n.emit(a,u,o)}}),[])}function ce(){const e=l.useRef(null);return h(()=>({customElement:e}),[])}function ue(e){N(()=>{e.dispatchers.dispatch(m.Derive,[])},[e.options.using.props]),N(()=>(e.dispatchers.dispatch(m.Mount,[]),e.dispatchers.dispatch(m.Node,[e.elements.customElement.current]),()=>e.dispatchers.dispatch(m.Unmount,[])),[])}function ie(e){const t=h(()=>({...e.options.using.model??{},[j]:{boundary:S.Default}}),[]);return l.useRef(new x(t,t))}function ae(){return l.useRef(new Set)}function le(){const[e,t]=l.useReducer(n=>n+1,0);return h(()=>({hash:e,rerender:t}),[e])}const de={elementName:"x-chizu"},Q=l.createContext(null);function fe(){const e=l.useContext(Q);if(!e)throw new Error("useScoped is not being used within a scoped module.");return e}class he extends l.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){const n=Symbol("process"),r=I(this.props.model.current,n,(c,o)=>{o.boundary=S.Error});this.props.model.current=r,this.props.update.rerender(),this.props.dispatchers.dispatch(m.Error,[J(t)])}render(){return i.jsx(re,{children:this.props.children})}}function me({options:e}){const t=le(),n=ae(),r=ce(),c=$(),o=ie({options:e}),u=oe({broadcast:c,options:e,update:t,model:o,queue:n}),a=ee({model:o,dispatchers:u});return te({options:e,dispatchers:u,actions:a}),ue({options:e,dispatchers:u,elements:r}),h(()=>l.createElement(he,{model:o,dispatchers:u,update:t,module:a.view,children(){return l.createElement(Q.Provider,{value:a.view,children:l.createElement(de.elementName,{ref:r.customElement,style:{display:"contents"},children:e.children(a.view)})})}}),[t.hash,v(e.using.props)])}function pe(e){return i.jsx(me,{options:e})}const ye=l.memo(pe,(e,t)=>v(e)===v(t));s.Boundary=S,s.Broadcaster=Z,s.Lifecycle=m,s.Scope=ye,s.State=B,s.TypedError=C,s.isTypedError=ne,s.useScoped=fe,s.utils=Y,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TypedError } 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, Meta, 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 | TypedError): 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;
|
package/dist/errors/utils.d.ts
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import { ModuleDefinition } from '../types/index.ts';
|
|
2
2
|
import { Props } from './types.ts';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Check if the error is an instance of TypedError.
|
|
5
|
+
*
|
|
6
|
+
* @param error {Error | TypedError}
|
|
7
|
+
* @returns {boolean}
|
|
8
|
+
*/
|
|
9
|
+
export declare function isTypedError(error: Error | TypedError): error is TypedError;
|
|
5
10
|
/**
|
|
6
11
|
* Convert an unknown error into a known error type.
|
|
7
12
|
*
|
|
8
13
|
* @function intoError
|
|
9
14
|
* @param error {unknown} - The error to convert to a known error type.
|
|
10
|
-
* @returns {Error |
|
|
15
|
+
* @returns {Error | TypedError}
|
|
11
16
|
*/
|
|
12
|
-
export declare function intoError(error: unknown): Error |
|
|
17
|
+
export declare function intoError(error: unknown): Error | TypedError;
|
|
13
18
|
/**
|
|
14
|
-
* @class
|
|
19
|
+
* @class TypedError
|
|
15
20
|
* @extends Error
|
|
16
21
|
* @param type {string} - The type of the error.
|
|
17
22
|
* @param message {string} - The error message.
|
|
18
23
|
*/
|
|
19
|
-
export declare class
|
|
24
|
+
export declare class TypedError extends Error {
|
|
20
25
|
#private;
|
|
21
26
|
constructor(type: number | string | symbol, message?: null | string);
|
|
22
27
|
get type(): number | string | symbol;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { ControllerDefinition } from './controller/types.ts';
|
|
2
|
-
import { ViewArgs
|
|
3
|
-
export { Lifecycle, State,
|
|
2
|
+
import { ViewArgs } from './view/types.ts';
|
|
3
|
+
export { Lifecycle, State, Boundary } from './types/index.ts';
|
|
4
4
|
export * as utils from './utils/index.ts';
|
|
5
|
-
export { default as
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export type
|
|
10
|
-
export type {
|
|
11
|
-
export type { ViewDefinition as View };
|
|
12
|
-
export type { ViewArgs as Within };
|
|
5
|
+
export { default as Scope } from './module/index.tsx';
|
|
6
|
+
export { Broadcaster } from './broadcast/index.tsx';
|
|
7
|
+
export { useScoped } from './module/renderer/utils.ts';
|
|
8
|
+
export { isTypedError, TypedError } from './errors/utils.ts';
|
|
9
|
+
export type { Schema, Pk } from './types/index.ts';
|
|
10
|
+
export type { ViewArgs as Scoped };
|
|
13
11
|
export type { ControllerDefinition as Actions };
|
package/dist/module/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ModuleDefinition } from '../types/index.ts';
|
|
2
2
|
import { UseOptions } from './types.ts';
|
|
3
3
|
import * as React from "react";
|
|
4
|
-
declare function
|
|
5
|
-
declare const _default: typeof
|
|
4
|
+
declare function Scope<M extends ModuleDefinition>(options: UseOptions<M>): React.ReactNode;
|
|
5
|
+
declare const _default: typeof Scope;
|
|
6
6
|
export default _default;
|
|
@@ -5,4 +5,4 @@ export declare const config: {
|
|
|
5
5
|
elementName: string;
|
|
6
6
|
};
|
|
7
7
|
export declare const Context: React.Context<ViewArgs<ModuleDefinition> | null>;
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function useScoped<M extends ModuleDefinition>(): ViewArgs<M>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare enum Lifecycle {
|
|
|
30
30
|
export type Model = Record<symbol | string, any>;
|
|
31
31
|
export type Actions = [] | [ActionName] | [ActionName, ...ActionPayload];
|
|
32
32
|
export type Props = Record<string, unknown>;
|
|
33
|
-
export type
|
|
33
|
+
export type Schema<M extends Model, A extends Actions = [], P extends Props = Record<string, never>> = {
|
|
34
34
|
Model: M;
|
|
35
35
|
Actions: A;
|
|
36
36
|
Props: P;
|
|
@@ -50,11 +50,11 @@ export type Queue<A extends ModuleDefinition["Actions"]> = {
|
|
|
50
50
|
export type Task = PromiseWithResolvers<void>;
|
|
51
51
|
export type Process = symbol;
|
|
52
52
|
export type Op = number;
|
|
53
|
-
export declare enum
|
|
53
|
+
export declare enum Boundary {
|
|
54
54
|
Default = 0,
|
|
55
55
|
Error = 1
|
|
56
56
|
}
|
|
57
57
|
export type Meta = {
|
|
58
|
-
|
|
58
|
+
boundary: Boundary;
|
|
59
59
|
};
|
|
60
60
|
export {};
|
package/dist/view/types.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Validatable } from '../module/renderer/model/types.ts';
|
|
2
|
-
import {
|
|
2
|
+
import { Boundary, ModuleDefinition } from '../types/index.ts';
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
export type ViewActions<M extends ModuleDefinition> = {
|
|
5
5
|
dispatch(action: M["Actions"]): Promise<void>;
|
|
6
6
|
};
|
|
7
7
|
export type ViewArgs<M extends ModuleDefinition> = Readonly<{
|
|
8
8
|
model: Readonly<M["Model"]>;
|
|
9
|
-
|
|
10
|
-
is(
|
|
9
|
+
boundary: {
|
|
10
|
+
is(boundary: Boundary): boolean;
|
|
11
11
|
};
|
|
12
12
|
validate: Readonly<Validatable<M["Model"]>>;
|
|
13
13
|
actions: Readonly<ViewActions<M>>;
|