chizu 0.2.12 → 0.2.13
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 +63 -67
- package/dist/chizu.js +154 -205
- package/dist/chizu.umd.cjs +1 -1
- package/dist/context/index.d.ts +4 -0
- package/dist/{app → context}/types.d.ts +3 -0
- package/dist/controller/types.d.ts +1 -4
- package/dist/index.d.ts +4 -8
- package/dist/module/index.d.ts +4 -2
- package/dist/module/renderer/actions/types.d.ts +2 -6
- package/dist/module/renderer/controller/index.d.ts +1 -1
- package/dist/module/renderer/controller/types.d.ts +1 -1
- package/dist/module/renderer/dispatchers/types.d.ts +2 -2
- package/dist/module/renderer/lifecycles/types.d.ts +1 -3
- package/dist/module/renderer/model/types.d.ts +1 -1
- package/dist/module/renderer/types.d.ts +1 -5
- package/dist/module/types.d.ts +8 -6
- package/dist/types/index.d.ts +4 -12
- package/dist/view/types.d.ts +0 -1
- package/package.json +1 -1
- package/dist/app/index.d.ts +0 -4
- package/dist/module/renderer/props/index.d.ts +0 -4
- package/dist/module/renderer/props/types.d.ts +0 -9
- package/dist/module/renderer/router/index.d.ts +0 -6
- package/dist/module/renderer/router/types.d.ts +0 -15
package/README.md
CHANGED
|
@@ -18,19 +18,17 @@ Strongly typed React framework using generators and efficiently updated views al
|
|
|
18
18
|
- Mostly standard JavaScript without quirky rules and exceptions.
|
|
19
19
|
- Clear separation of concerns between business logic and markup.
|
|
20
20
|
- First-class support for skeleton loading using generators.
|
|
21
|
-
- Strongly typed throughout – styles,
|
|
21
|
+
- Strongly typed throughout – styles, actions and views.
|
|
22
22
|
- Avoid vendor lock-in with framework agnostic libraries such as [Shoelace](https://shoelace.style/).
|
|
23
|
-
- Easily communicate between
|
|
23
|
+
- Easily communicate between actions using distributed actions.
|
|
24
24
|
- State is mutated sequentially ([FIFO](<https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)>)) and deeply merged for queued mutations.
|
|
25
25
|
|
|
26
26
|
## Getting started
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<kbd>Controller</kbd>
|
|
28
|
+
Actions are responsible for mutating the state of the view. In the below example the `name` is dispatched from the view to the actions, the state is updated and the view is rendered with the updated value.
|
|
31
29
|
|
|
32
30
|
```tsx
|
|
33
|
-
export default (function
|
|
31
|
+
export default (function Actions(module) {
|
|
34
32
|
return {
|
|
35
33
|
async *[Events.Name](name) {
|
|
36
34
|
return module.actions.produce((draft) => {
|
|
@@ -38,33 +36,33 @@ export default (function ProfileController(module) {
|
|
|
38
36
|
});
|
|
39
37
|
},
|
|
40
38
|
};
|
|
41
|
-
} as
|
|
39
|
+
} as Actions<Module>);
|
|
42
40
|
```
|
|
43
41
|
|
|
44
|
-
<kbd>View</kbd>
|
|
45
|
-
|
|
46
42
|
```tsx
|
|
47
|
-
export default
|
|
43
|
+
export default function Profile(props: Props): React.ReactElement {
|
|
48
44
|
return (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
45
|
+
<Tree<Module> using={{ model, actions, props }}>
|
|
46
|
+
{(module) => (
|
|
47
|
+
<>
|
|
48
|
+
<p>Hey {module.model.name}</p>
|
|
49
|
+
|
|
50
|
+
<button
|
|
51
|
+
onClick={() => module.actions.dispatch([Events.Name, randomName()])}
|
|
52
|
+
>
|
|
53
|
+
Switch profile
|
|
54
|
+
</button>
|
|
55
|
+
</>
|
|
56
|
+
)}
|
|
57
|
+
</Tree>
|
|
58
58
|
);
|
|
59
|
-
}
|
|
59
|
+
}
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
<kbd>Controller</kbd>
|
|
62
|
+
You can perform asynchronous operations in the action which will cause the associated view to render a second time:
|
|
65
63
|
|
|
66
64
|
```tsx
|
|
67
|
-
export default (function
|
|
65
|
+
export default (function Actions(module) {
|
|
68
66
|
return {
|
|
69
67
|
async *[Events.Name]() {
|
|
70
68
|
yield module.actions.produce((draft) => {
|
|
@@ -78,31 +76,31 @@ export default (function ProfileController(module) {
|
|
|
78
76
|
});
|
|
79
77
|
},
|
|
80
78
|
};
|
|
81
|
-
} as
|
|
79
|
+
} as Actions<Module>);
|
|
82
80
|
```
|
|
83
81
|
|
|
84
|
-
<kbd>View</kbd>
|
|
85
|
-
|
|
86
82
|
```tsx
|
|
87
|
-
export default
|
|
83
|
+
export default function Profile(props: Props): React.ReactElement {
|
|
88
84
|
return (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
85
|
+
<Tree<Module> using={{ model, actions, props }}>
|
|
86
|
+
{(module) => (
|
|
87
|
+
<>
|
|
88
|
+
<p>Hey {module.model.name}</p>
|
|
89
|
+
|
|
90
|
+
<button onClick={() => module.actions.dispatch([Events.Name])}>
|
|
91
|
+
Switch profile
|
|
92
|
+
</button>
|
|
93
|
+
</>
|
|
94
|
+
)}
|
|
95
|
+
</Tree>
|
|
96
96
|
);
|
|
97
|
-
}
|
|
97
|
+
}
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
<kbd>Controller</kbd>
|
|
100
|
+
However in the above example where the name is fetched asynchronously, there is no feedback to the user – we can improve that significantly by using the `module.actions.annotate` and `module.validate` helpers:
|
|
103
101
|
|
|
104
102
|
```tsx
|
|
105
|
-
export default (function
|
|
103
|
+
export default (function Actions(module) {
|
|
106
104
|
return {
|
|
107
105
|
async *[Events.Name]() {
|
|
108
106
|
yield module.actions.produce((draft) => {
|
|
@@ -115,49 +113,49 @@ export default (function ProfileController(module) {
|
|
|
115
113
|
});
|
|
116
114
|
},
|
|
117
115
|
};
|
|
118
|
-
} as
|
|
116
|
+
} as Actions<Module>);
|
|
119
117
|
```
|
|
120
118
|
|
|
121
|
-
<kbd>View</kbd>
|
|
122
|
-
|
|
123
119
|
```tsx
|
|
124
|
-
export default
|
|
120
|
+
export default function ProfileView(props: Props): React.ReactElement {
|
|
125
121
|
return (
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
122
|
+
<Tree<Module> using={{ module, actions, props }}>
|
|
123
|
+
{(module) => (
|
|
124
|
+
<>
|
|
125
|
+
<p>Hey {module.model.name}</p>
|
|
126
|
+
|
|
127
|
+
{module.validate.name.pending() && <p>Switching profiles…</p>}
|
|
128
|
+
|
|
129
|
+
<button
|
|
130
|
+
disabled={module.validate.name.is(State.Op.Update)}
|
|
131
|
+
onClick={() => module.actions.dispatch([Events.Name])}
|
|
132
|
+
>
|
|
133
|
+
Switch profile
|
|
134
|
+
</button>
|
|
135
|
+
</>
|
|
136
|
+
)}
|
|
137
|
+
</Tree>
|
|
138
138
|
);
|
|
139
|
-
}
|
|
139
|
+
}
|
|
140
140
|
```
|
|
141
141
|
|
|
142
142
|
## Handling Errors
|
|
143
143
|
|
|
144
|
-
|
|
144
|
+
Actions can throw errors directly or in any of their associated `yield` actions – all unhandled errors are automatically caught and broadcast using the `Lifecycle.Error` action – you can render these [in a toast](https://github.com/fkhadra/react-toastify#readme) or similar UI.
|
|
145
145
|
|
|
146
146
|
You can also customise these errors a little further with your own error `enum` which describes the error type:
|
|
147
147
|
|
|
148
148
|
<kbd>Types</kbd>
|
|
149
149
|
|
|
150
|
-
```
|
|
150
|
+
```ts
|
|
151
151
|
export const enum Errors {
|
|
152
152
|
UserValidation,
|
|
153
153
|
IncorrectPassword,
|
|
154
154
|
}
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
-
<kbd>Controller</kbd>
|
|
158
|
-
|
|
159
157
|
```tsx
|
|
160
|
-
export default (function
|
|
158
|
+
export default (function Actions(module) {
|
|
161
159
|
return {
|
|
162
160
|
*[Events.Name]() {
|
|
163
161
|
yield module.actions.produce((draft) => {
|
|
@@ -173,15 +171,13 @@ export default (function ProfileController(module) {
|
|
|
173
171
|
});
|
|
174
172
|
},
|
|
175
173
|
};
|
|
176
|
-
}) as
|
|
174
|
+
}) as Actions<Module>;
|
|
177
175
|
```
|
|
178
176
|
|
|
179
177
|
However showing a toast message is not always relevant, you may want a more detailed error message such as a user not found message – although you could introduce another property for such errors in your model, you could mark the property as fallible by giving it a `Maybe` type because it then keeps everything nicely associated with the `name` property rather than creating another property:
|
|
180
178
|
|
|
181
|
-
<kbd>Controller</kbd>
|
|
182
|
-
|
|
183
179
|
```tsx
|
|
184
|
-
export default (function
|
|
180
|
+
export default (function Actions(module) {
|
|
185
181
|
return {
|
|
186
182
|
async *[Events.Name]() {
|
|
187
183
|
yield module.actions.produce((draft) => {
|
|
@@ -201,5 +197,5 @@ export default (function ProfileView(module) {
|
|
|
201
197
|
});
|
|
202
198
|
},
|
|
203
199
|
};
|
|
204
|
-
} as
|
|
200
|
+
} as Actions<Module>);
|
|
205
201
|
```
|
package/dist/chizu.js
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var T = Object.defineProperty;
|
|
2
|
+
var j = (t) => {
|
|
3
3
|
throw TypeError(t);
|
|
4
4
|
};
|
|
5
|
-
var z = (t, e, n) => e in t ?
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
5
|
+
var z = (t, e, n) => e in t ? T(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
6
|
+
var y = (t, e, n) => z(t, typeof e != "symbol" ? e + "" : e, n), k = (t, e, n) => e.has(t) || j("Cannot " + n);
|
|
7
|
+
var w = (t, e, n) => (k(t, e, "read from private field"), n ? n.call(t) : e.get(t)), E = (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) => (k(t, e, "write to private field"), r ? r.call(t, n) : e.set(t, n), n);
|
|
8
|
+
import { Immer as N } from "immer";
|
|
9
|
+
import p from "lodash/get";
|
|
10
|
+
import R from "traverse";
|
|
11
|
+
import { jsx as $ } from "react/jsx-runtime";
|
|
12
12
|
import * as a from "react";
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
class C {
|
|
13
|
+
import M from "eventemitter3";
|
|
14
|
+
class O {
|
|
16
15
|
constructor(e) {
|
|
17
16
|
this.value = e;
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
|
-
class
|
|
19
|
+
class q {
|
|
21
20
|
static Draft(e) {
|
|
22
|
-
return new
|
|
21
|
+
return new O(e);
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
|
-
|
|
24
|
+
y(q, "Op", {
|
|
26
25
|
Add: 1,
|
|
27
26
|
Remove: 2,
|
|
28
27
|
Update: 4,
|
|
@@ -30,240 +29,234 @@ E($, "Op", {
|
|
|
30
29
|
Replace: 16
|
|
31
30
|
});
|
|
32
31
|
var m = /* @__PURE__ */ ((t) => (t.Mount = "lifecycle/mount", t.Node = "lifecycle/node", t.Derive = "lifecycle/derive", t.Error = "distributed/lifecycle/error", t.Unmount = "lifecycle/unmount", t))(m || {});
|
|
33
|
-
const
|
|
34
|
-
immer: new
|
|
32
|
+
const c = {
|
|
33
|
+
immer: new N(),
|
|
35
34
|
annotations: Symbol("annotations")
|
|
36
35
|
};
|
|
37
|
-
|
|
38
|
-
class
|
|
36
|
+
c.immer.setAutoFreeze(!1);
|
|
37
|
+
class S {
|
|
39
38
|
constructor(e, n, r = null) {
|
|
40
|
-
|
|
39
|
+
y(this, "process");
|
|
41
40
|
this.value = e, this.operations = n, this.field = r, this.process = null;
|
|
42
41
|
}
|
|
43
42
|
attach(e) {
|
|
44
43
|
return this.process = e, this;
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
|
-
function
|
|
48
|
-
return new
|
|
46
|
+
function I(t, e = []) {
|
|
47
|
+
return new S(t, e);
|
|
49
48
|
}
|
|
50
|
-
class
|
|
49
|
+
class P {
|
|
51
50
|
constructor(e, n = e) {
|
|
52
51
|
this.stateless = e, this.stateful = n;
|
|
53
52
|
}
|
|
54
53
|
get validatable() {
|
|
55
|
-
return
|
|
54
|
+
return U(this.stateful);
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
|
-
function
|
|
57
|
+
function U(t, e = []) {
|
|
59
58
|
return new Proxy(t, {
|
|
60
59
|
get(n, r) {
|
|
61
60
|
switch (r) {
|
|
62
61
|
case "is":
|
|
63
|
-
return (
|
|
64
|
-
const
|
|
65
|
-
if (!
|
|
62
|
+
return (o) => {
|
|
63
|
+
const s = x(t, e);
|
|
64
|
+
if (!s) return !1;
|
|
66
65
|
const u = new Set(
|
|
67
|
-
|
|
66
|
+
s.flatMap((l) => l.operations)
|
|
68
67
|
);
|
|
69
68
|
return !!(Array.from(u).reduce(
|
|
70
|
-
(
|
|
69
|
+
(l, d) => l | (d ?? 0),
|
|
71
70
|
0
|
|
72
|
-
) &
|
|
71
|
+
) & o);
|
|
73
72
|
};
|
|
74
73
|
case "pending":
|
|
75
|
-
return () => !!
|
|
74
|
+
return () => !!x(t, e);
|
|
76
75
|
case "draft":
|
|
77
76
|
return () => {
|
|
78
|
-
const
|
|
79
|
-
if (!
|
|
80
|
-
const
|
|
81
|
-
return
|
|
77
|
+
const o = x(t, e);
|
|
78
|
+
if (!o) return p(t, e);
|
|
79
|
+
const s = o.flatMap((u) => u.operations).find((u) => u instanceof O);
|
|
80
|
+
return s ? s.value : p(t, e);
|
|
82
81
|
};
|
|
83
82
|
}
|
|
84
|
-
return
|
|
83
|
+
return U(t, [...e, String(r)]);
|
|
85
84
|
}
|
|
86
85
|
});
|
|
87
86
|
}
|
|
88
|
-
function
|
|
89
|
-
const r = typeof
|
|
90
|
-
return
|
|
87
|
+
function x(t, e) {
|
|
88
|
+
const r = typeof p(t, e) == "object" ? e : e.slice(0, -1), o = r.length === 0 ? t : p(t, r), s = (o == null ? void 0 : o[c.annotations]) ?? [];
|
|
89
|
+
return s.length > 0 ? s : null;
|
|
91
90
|
}
|
|
92
|
-
function
|
|
93
|
-
function r(
|
|
94
|
-
return
|
|
95
|
-
if (this.key ===
|
|
91
|
+
function F(t, e, n) {
|
|
92
|
+
function r(s) {
|
|
93
|
+
return R(s).forEach(function() {
|
|
94
|
+
if (this.key === c.annotations) {
|
|
96
95
|
this.block();
|
|
97
96
|
return;
|
|
98
97
|
}
|
|
99
|
-
this.node instanceof
|
|
98
|
+
this.node instanceof S && this.update(this.node.value);
|
|
100
99
|
});
|
|
101
100
|
}
|
|
102
|
-
function s
|
|
103
|
-
return
|
|
104
|
-
if (this.key ===
|
|
101
|
+
function o(s) {
|
|
102
|
+
return R(s).forEach(function() {
|
|
103
|
+
if (this.key === c.annotations) {
|
|
105
104
|
this.block();
|
|
106
105
|
return;
|
|
107
106
|
}
|
|
108
|
-
if (this.node instanceof
|
|
109
|
-
const u = typeof this.node.value == "object",
|
|
107
|
+
if (this.node instanceof S) {
|
|
108
|
+
const u = typeof this.node.value == "object", i = [
|
|
110
109
|
...u ? this.path : this.path.slice(0, -1),
|
|
111
|
-
|
|
112
|
-
],
|
|
110
|
+
c.annotations
|
|
111
|
+
], l = p(t.stateful, i) ?? [], d = this.node.attach(e);
|
|
113
112
|
u ? this.update(
|
|
114
113
|
{
|
|
115
114
|
...this.node.value,
|
|
116
|
-
[
|
|
115
|
+
[c.annotations]: [d, ...l]
|
|
117
116
|
},
|
|
118
117
|
!0
|
|
119
|
-
) : (this.parent && (this.parent.node[
|
|
118
|
+
) : (this.parent && (this.parent.node[c.annotations] = [d, ...l]), this.update(this.node.value, !0));
|
|
120
119
|
}
|
|
121
120
|
});
|
|
122
121
|
}
|
|
123
|
-
return new
|
|
124
|
-
r(
|
|
125
|
-
|
|
122
|
+
return new P(
|
|
123
|
+
r(c.immer.produce(t.stateless, n)),
|
|
124
|
+
o(c.immer.produce(t.stateful, n))
|
|
126
125
|
);
|
|
127
126
|
}
|
|
128
|
-
function
|
|
129
|
-
const n =
|
|
130
|
-
if (this.key ===
|
|
127
|
+
function D(t, e) {
|
|
128
|
+
const n = R(t.stateful).forEach(function() {
|
|
129
|
+
if (this.key === c.annotations) {
|
|
131
130
|
this.block();
|
|
132
131
|
return;
|
|
133
132
|
}
|
|
134
|
-
if (this.node && this.node[
|
|
135
|
-
const r = this.node[
|
|
133
|
+
if (this.node && this.node[c.annotations]) {
|
|
134
|
+
const r = this.node[c.annotations];
|
|
136
135
|
this.update(
|
|
137
136
|
{
|
|
138
137
|
...this.node,
|
|
139
|
-
[
|
|
140
|
-
(
|
|
138
|
+
[c.annotations]: r.filter(
|
|
139
|
+
(o) => o.process !== e
|
|
141
140
|
)
|
|
142
141
|
},
|
|
143
142
|
!0
|
|
144
143
|
);
|
|
145
144
|
}
|
|
146
145
|
});
|
|
147
|
-
return new
|
|
146
|
+
return new P(t.stateless, n);
|
|
148
147
|
}
|
|
149
|
-
function
|
|
150
|
-
return (e, n) => async (r = Promise.withResolvers(),
|
|
148
|
+
function J(t) {
|
|
149
|
+
return (e, n) => async (r = Promise.withResolvers(), o) => {
|
|
151
150
|
if (typeof n != "function") return;
|
|
152
|
-
const
|
|
151
|
+
const s = Symbol("process"), u = n(...o);
|
|
153
152
|
if (u == null)
|
|
154
153
|
return void r.resolve();
|
|
155
154
|
if (typeof u == "function") {
|
|
156
|
-
const
|
|
157
|
-
return t.model.current =
|
|
155
|
+
const i = u(t.model.current, s);
|
|
156
|
+
return t.model.current = D(i, s), t.update.rerender(), void r.resolve();
|
|
158
157
|
}
|
|
159
158
|
for (; ; ) {
|
|
160
|
-
const { value:
|
|
161
|
-
if (
|
|
162
|
-
const
|
|
163
|
-
t.model.current =
|
|
159
|
+
const { value: i, done: l } = await u.next();
|
|
160
|
+
if (l) {
|
|
161
|
+
const H = i(t.model.current, s);
|
|
162
|
+
t.model.current = D(H, s), t.update.rerender();
|
|
164
163
|
break;
|
|
165
164
|
}
|
|
166
|
-
const
|
|
167
|
-
t.model.current =
|
|
165
|
+
const d = i;
|
|
166
|
+
t.model.current = d(t.model.current, s), t.update.rerender();
|
|
168
167
|
}
|
|
169
168
|
r.resolve();
|
|
170
169
|
};
|
|
171
170
|
}
|
|
172
|
-
function
|
|
171
|
+
function A(t) {
|
|
173
172
|
return t.startsWith("distributed");
|
|
174
173
|
}
|
|
175
|
-
var
|
|
176
|
-
class
|
|
174
|
+
var v, g;
|
|
175
|
+
class Q extends Error {
|
|
177
176
|
constructor(n, r = null) {
|
|
178
177
|
super(String(r));
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
178
|
+
E(this, v);
|
|
179
|
+
E(this, g);
|
|
180
|
+
b(this, v, n), b(this, g, r);
|
|
182
181
|
}
|
|
183
182
|
get type() {
|
|
184
|
-
return
|
|
183
|
+
return w(this, v);
|
|
185
184
|
}
|
|
186
185
|
get message() {
|
|
187
|
-
return
|
|
186
|
+
return w(this, g) || "";
|
|
188
187
|
}
|
|
189
188
|
}
|
|
190
|
-
|
|
191
|
-
function
|
|
189
|
+
v = new WeakMap(), g = new WeakMap();
|
|
190
|
+
function W(t) {
|
|
192
191
|
return new Promise((e) => setTimeout(e, t));
|
|
193
192
|
}
|
|
194
|
-
function
|
|
193
|
+
function G(t) {
|
|
195
194
|
return t ? !!(t && typeof t != "symbol") : Symbol(`pk.${Date.now()}.${crypto.randomUUID()}`);
|
|
196
195
|
}
|
|
197
|
-
function
|
|
198
|
-
return t instanceof
|
|
196
|
+
function K(t) {
|
|
197
|
+
return t instanceof Q;
|
|
199
198
|
}
|
|
200
|
-
function
|
|
199
|
+
function h(t) {
|
|
201
200
|
return JSON.stringify(t);
|
|
202
201
|
}
|
|
203
|
-
const
|
|
202
|
+
const ft = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
204
203
|
__proto__: null,
|
|
205
|
-
hash:
|
|
206
|
-
isEventError:
|
|
207
|
-
pk:
|
|
208
|
-
sleep:
|
|
204
|
+
hash: h,
|
|
205
|
+
isEventError: K,
|
|
206
|
+
pk: G,
|
|
207
|
+
sleep: W
|
|
209
208
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
210
|
-
function
|
|
209
|
+
function f(t, e) {
|
|
211
210
|
const n = a.useRef(null), r = a.useRef(null);
|
|
212
211
|
return a.useMemo(() => {
|
|
213
|
-
const
|
|
214
|
-
if (r.current !==
|
|
215
|
-
r.current =
|
|
216
|
-
const
|
|
217
|
-
return n.current =
|
|
212
|
+
const o = h(e);
|
|
213
|
+
if (r.current !== o) {
|
|
214
|
+
r.current = o;
|
|
215
|
+
const s = t();
|
|
216
|
+
return n.current = s, s;
|
|
218
217
|
}
|
|
219
218
|
return n.current;
|
|
220
219
|
}, e);
|
|
221
220
|
}
|
|
222
|
-
function
|
|
221
|
+
function C(t, e) {
|
|
223
222
|
const n = a.useRef(null);
|
|
224
223
|
a.useEffect(() => {
|
|
225
|
-
const r =
|
|
224
|
+
const r = h(e);
|
|
226
225
|
if (n.current !== r)
|
|
227
226
|
return n.current = r, t();
|
|
228
227
|
}, e);
|
|
229
228
|
}
|
|
230
|
-
const
|
|
231
|
-
appEmitter: new
|
|
229
|
+
const _ = a.createContext({
|
|
230
|
+
appEmitter: new M()
|
|
232
231
|
});
|
|
233
|
-
function
|
|
234
|
-
return a.useContext(
|
|
232
|
+
function B() {
|
|
233
|
+
return a.useContext(_);
|
|
235
234
|
}
|
|
236
|
-
function
|
|
235
|
+
function dt({ children: t }) {
|
|
237
236
|
return () => {
|
|
238
|
-
const e =
|
|
237
|
+
const e = f(
|
|
239
238
|
() => ({
|
|
240
|
-
appEmitter: new
|
|
239
|
+
appEmitter: new M()
|
|
241
240
|
}),
|
|
242
241
|
[]
|
|
243
242
|
);
|
|
244
|
-
return /* @__PURE__ */
|
|
243
|
+
return /* @__PURE__ */ $(_.Provider, { value: e, children: t });
|
|
245
244
|
};
|
|
246
245
|
}
|
|
247
|
-
function
|
|
248
|
-
return
|
|
246
|
+
function V(t) {
|
|
247
|
+
return f(
|
|
249
248
|
() => ({
|
|
250
249
|
controller: {
|
|
251
250
|
get model() {
|
|
252
251
|
return t.model.current.stateful;
|
|
253
252
|
},
|
|
254
|
-
get props() {
|
|
255
|
-
return t.props.current;
|
|
256
|
-
},
|
|
257
|
-
get router() {
|
|
258
|
-
return t.router.current;
|
|
259
|
-
},
|
|
260
253
|
queue: [],
|
|
261
254
|
actions: {
|
|
262
255
|
annotate(e, n) {
|
|
263
|
-
return
|
|
256
|
+
return I(e, n);
|
|
264
257
|
},
|
|
265
258
|
produce(e) {
|
|
266
|
-
return (n, r) =>
|
|
259
|
+
return (n, r) => F(n, r, e);
|
|
267
260
|
},
|
|
268
261
|
dispatch([e, ...n]) {
|
|
269
262
|
if (e == null) return Promise.reject();
|
|
@@ -276,9 +269,6 @@ function Z(t) {
|
|
|
276
269
|
get model() {
|
|
277
270
|
return t.model.current.stateless;
|
|
278
271
|
},
|
|
279
|
-
get props() {
|
|
280
|
-
return t.props.current;
|
|
281
|
-
},
|
|
282
272
|
get validate() {
|
|
283
273
|
return t.model.current.validatable;
|
|
284
274
|
},
|
|
@@ -294,111 +284,70 @@ function Z(t) {
|
|
|
294
284
|
[]
|
|
295
285
|
);
|
|
296
286
|
}
|
|
297
|
-
function
|
|
298
|
-
return
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
return e ? (Object.entries(e).forEach(([o, u]) => t.dispatchers.attach(o, u)), e) : void 0;
|
|
287
|
+
function X(t) {
|
|
288
|
+
return f(() => {
|
|
289
|
+
const e = t.options.using.actions(t.actions.controller);
|
|
290
|
+
return Object.entries(e).forEach(([r, o]) => t.dispatchers.attach(r, o)), e;
|
|
302
291
|
}, []);
|
|
303
292
|
}
|
|
304
|
-
function
|
|
305
|
-
const e =
|
|
306
|
-
return
|
|
307
|
-
const r = new
|
|
293
|
+
function Y(t) {
|
|
294
|
+
const e = B(), n = J(t);
|
|
295
|
+
return f(() => {
|
|
296
|
+
const r = new M(), o = e.appEmitter;
|
|
308
297
|
return {
|
|
309
|
-
attach(
|
|
310
|
-
const
|
|
311
|
-
|
|
298
|
+
attach(s, u) {
|
|
299
|
+
const i = String(s);
|
|
300
|
+
A(i) ? o.on(i, n(s, u)) : r.on(i, n(s, u));
|
|
312
301
|
},
|
|
313
|
-
dispatch(
|
|
314
|
-
const
|
|
315
|
-
|
|
302
|
+
dispatch(s, u, i) {
|
|
303
|
+
const l = String(s);
|
|
304
|
+
A(l) ? o.emit(l, i, u) : r.emit(l, i, u);
|
|
316
305
|
}
|
|
317
306
|
};
|
|
318
307
|
}, []);
|
|
319
308
|
}
|
|
320
|
-
function
|
|
309
|
+
function Z() {
|
|
321
310
|
const t = a.useRef(null);
|
|
322
|
-
return
|
|
311
|
+
return f(() => ({ customElement: t }), []);
|
|
323
312
|
}
|
|
324
|
-
function
|
|
325
|
-
|
|
326
|
-
j(() => {
|
|
313
|
+
function L(t) {
|
|
314
|
+
C(() => {
|
|
327
315
|
t.dispatchers.dispatch(m.Derive, []);
|
|
328
|
-
}, [
|
|
329
|
-
t.options.props,
|
|
330
|
-
(e = t.router.current) == null ? void 0 : e.location,
|
|
331
|
-
(n = t.router.current) == null ? void 0 : n.params,
|
|
332
|
-
(s = (r = t.router.current) == null ? void 0 : r.search) == null ? void 0 : s[0]
|
|
333
|
-
]), j(() => (t.dispatchers.dispatch(m.Mount, []), t.dispatchers.dispatch(m.Node, [
|
|
316
|
+
}, [t.options.using.props]), C(() => (t.dispatchers.dispatch(m.Mount, []), t.dispatchers.dispatch(m.Node, [
|
|
334
317
|
t.elements.customElement.current
|
|
335
318
|
]), () => t.dispatchers.dispatch(m.Unmount, [])), []);
|
|
336
319
|
}
|
|
337
|
-
function
|
|
338
|
-
const e =
|
|
339
|
-
return a.useRef(new
|
|
340
|
-
}
|
|
341
|
-
function ot(t) {
|
|
342
|
-
const e = a.useRef(t.options.props);
|
|
343
|
-
return j(() => {
|
|
344
|
-
e.current = t.options.props, t.update.rerender();
|
|
345
|
-
}, [t.options.props]), e;
|
|
320
|
+
function tt(t) {
|
|
321
|
+
const e = f(() => t.options.using.model ?? {}, []);
|
|
322
|
+
return a.useRef(new P(e, e));
|
|
346
323
|
}
|
|
347
|
-
function
|
|
324
|
+
function et() {
|
|
348
325
|
return a.useRef(/* @__PURE__ */ new Set());
|
|
349
326
|
}
|
|
350
|
-
function
|
|
351
|
-
return a.useRef(null);
|
|
352
|
-
}
|
|
353
|
-
function ct({ using: t, children: e }) {
|
|
354
|
-
return h.useInRouterContext() ? /* @__PURE__ */ p(it, { using: t, children: e }) : e();
|
|
355
|
-
}
|
|
356
|
-
function it({ using: t, children: e }) {
|
|
357
|
-
return t.current = {
|
|
358
|
-
navigate: h.useNavigate(),
|
|
359
|
-
location: h.useLocation(),
|
|
360
|
-
params: h.useParams(),
|
|
361
|
-
search: h.useSearchParams()
|
|
362
|
-
}, /* @__PURE__ */ p(F, { children: e() });
|
|
363
|
-
}
|
|
364
|
-
function at() {
|
|
327
|
+
function nt() {
|
|
365
328
|
const [t, e] = a.useReducer((n) => n + 1, 0);
|
|
366
|
-
return
|
|
329
|
+
return f(() => ({ hash: t, rerender: e }), [t]);
|
|
367
330
|
}
|
|
368
|
-
function
|
|
331
|
+
function rt({
|
|
369
332
|
options: t
|
|
370
333
|
}) {
|
|
371
|
-
const e =
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
model: c,
|
|
375
|
-
dispatchers: i,
|
|
376
|
-
router: o,
|
|
377
|
-
props: u
|
|
378
|
-
});
|
|
379
|
-
return L({ options: t, dispatchers: i, actions: f }), nt({ options: t, dispatchers: i, elements: s, router: o, update: n }), d(() => a.createElement(t.name, {
|
|
380
|
-
ref: s.customElement,
|
|
334
|
+
const e = B(), n = nt(), r = et(), o = Z(), s = tt({ options: t }), u = Y({ app: e, options: t, update: n, model: s, queue: r }), i = V({ app: e, options: t, model: s, dispatchers: u });
|
|
335
|
+
return X({ options: t, dispatchers: u, actions: i }), L({ options: t, dispatchers: u, elements: o, update: n }), f(() => a.createElement("x-chizu", {
|
|
336
|
+
ref: o.customElement,
|
|
381
337
|
style: { display: "contents" },
|
|
382
|
-
children:
|
|
383
|
-
}), [n.hash]);
|
|
338
|
+
children: t.children(i.view)
|
|
339
|
+
}), [n.hash, h(t.using.props)]);
|
|
384
340
|
}
|
|
385
|
-
function
|
|
386
|
-
return (
|
|
387
|
-
(n) => lt({
|
|
388
|
-
options: {
|
|
389
|
-
...e,
|
|
390
|
-
name: t.join(""),
|
|
391
|
-
props: n
|
|
392
|
-
}
|
|
393
|
-
}),
|
|
394
|
-
(n, r) => g(n) === g(r)
|
|
395
|
-
);
|
|
341
|
+
function st(t) {
|
|
342
|
+
return rt({ options: t });
|
|
396
343
|
}
|
|
397
|
-
const
|
|
344
|
+
const ht = a.memo(st, (t, e) => h(t) === h(e));
|
|
398
345
|
export {
|
|
399
|
-
|
|
346
|
+
dt as Context,
|
|
347
|
+
Q as EventError,
|
|
400
348
|
m as Lifecycle,
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
349
|
+
q as State,
|
|
350
|
+
ht as Tree,
|
|
351
|
+
B as useContext,
|
|
352
|
+
ft as utils
|
|
404
353
|
};
|
package/dist/chizu.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("
|
|
1
|
+
(function(s,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("immer"),require("lodash/get"),require("traverse"),require("react/jsx-runtime"),require("react"),require("eventemitter3")):typeof define=="function"&&define.amd?define(["exports","immer","lodash/get","traverse","react/jsx-runtime","react","eventemitter3"],u):(s=typeof globalThis<"u"?globalThis:s||self,u(s.Chizu={},s.Immer,s.get,s.Traverse,s.jsxRuntime,s.React,s.EventEmitter3))})(this,function(s,u,a,p,N,I,E){"use strict";var ae=Object.defineProperty;var B=s=>{throw TypeError(s)};var le=(s,u,a)=>u in s?ae(s,u,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[u]=a;var O=(s,u,a)=>le(s,typeof u!="symbol"?u+"":u,a),H=(s,u,a)=>u.has(s)||B("Cannot "+a);var M=(s,u,a)=>(H(s,u,"read from private field"),a?a.call(s):u.get(s)),P=(s,u,a)=>u.has(s)?B("Cannot add the same private member more than once"):u instanceof WeakSet?u.add(s):u.set(s,a),D=(s,u,a,p)=>(H(s,u,"write to private field"),p?p.call(s,a):u.set(s,a),a);var g,w;function $(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 f=$(I);class k{constructor(t){this.value=t}}class T{static Draft(t){return new k(t)}}O(T,"Op",{Add:1,Remove:2,Update:4,Move:8,Replace:16});var v=(e=>(e.Mount="lifecycle/mount",e.Node="lifecycle/node",e.Derive="lifecycle/derive",e.Error="distributed/lifecycle/error",e.Unmount="lifecycle/unmount",e))(v||{});const d={immer:new u.Immer,annotations:Symbol("annotations")};d.immer.setAutoFreeze(!1);class j{constructor(t,n,r=null){O(this,"process");this.value=t,this.operations=n,this.field=r,this.process=null}attach(t){return this.process=t,this}}function F(e,t=[]){return new j(e,t)}class S{constructor(t,n=t){this.stateless=t,this.stateful=n}get validatable(){return _(this.stateful)}}function _(e,t=[]){return new Proxy(e,{get(n,r){switch(r){case"is":return i=>{const o=R(e,t);if(!o)return!1;const c=new Set(o.flatMap(h=>h.operations));return!!(Array.from(c).reduce((h,b)=>h|(b??0),0)&i)};case"pending":return()=>!!R(e,t);case"draft":return()=>{const i=R(e,t);if(!i)return a(e,t);const o=i.flatMap(c=>c.operations).find(c=>c instanceof k);return o?o.value:a(e,t)}}return _(e,[...t,String(r)])}})}function R(e,t){const r=typeof a(e,t)=="object"?t:t.slice(0,-1),i=r.length===0?e:a(e,r),o=(i==null?void 0:i[d.annotations])??[];return o.length>0?o:null}function J(e,t,n){function r(o){return p(o).forEach(function(){if(this.key===d.annotations){this.block();return}this.node instanceof j&&this.update(this.node.value)})}function i(o){return p(o).forEach(function(){if(this.key===d.annotations){this.block();return}if(this.node instanceof j){const c=typeof this.node.value=="object",l=[...c?this.path:this.path.slice(0,-1),d.annotations],h=a(e.stateful,l)??[],b=this.node.attach(t);c?this.update({...this.node.value,[d.annotations]:[b,...h]},!0):(this.parent&&(this.parent.node[d.annotations]=[b,...h]),this.update(this.node.value,!0))}})}return new S(r(d.immer.produce(e.stateless,n)),i(d.immer.produce(e.stateful,n)))}function q(e,t){const n=p(e.stateful).forEach(function(){if(this.key===d.annotations){this.block();return}if(this.node&&this.node[d.annotations]){const r=this.node[d.annotations];this.update({...this.node,[d.annotations]:r.filter(i=>i.process!==t)},!0)}});return new S(e.stateless,n)}function Q(e){return(t,n)=>async(r=Promise.withResolvers(),i)=>{if(typeof n!="function")return;const o=Symbol("process"),c=n(...i);if(c==null)return void r.resolve();if(typeof c=="function"){const l=c(e.model.current,o);return e.model.current=q(l,o),e.update.rerender(),void r.resolve()}for(;;){const{value:l,done:h}=await c.next();if(h){const ce=l(e.model.current,o);e.model.current=q(ce,o),e.update.rerender();break}const b=l;e.model.current=b(e.model.current,o),e.update.rerender()}r.resolve()}}function C(e){return e.startsWith("distributed")}class A extends Error{constructor(n,r=null){super(String(r));P(this,g);P(this,w);D(this,g,n),D(this,w,r)}get type(){return M(this,g)}get message(){return M(this,w)||""}}g=new WeakMap,w=new WeakMap;function W(e){return new Promise(t=>setTimeout(t,e))}function G(e){return e?!!(e&&typeof e!="symbol"):Symbol(`pk.${Date.now()}.${crypto.randomUUID()}`)}function K(e){return e instanceof A}function y(e){return JSON.stringify(e)}const V=Object.freeze(Object.defineProperty({__proto__:null,hash:y,isEventError:K,pk:G,sleep:W},Symbol.toStringTag,{value:"Module"}));function m(e,t){const n=f.useRef(null),r=f.useRef(null);return f.useMemo(()=>{const i=y(t);if(r.current!==i){r.current=i;const o=e();return n.current=o,o}return n.current},t)}function U(e,t){const n=f.useRef(null);f.useEffect(()=>{const r=y(t);if(n.current!==r)return n.current=r,e()},t)}const z=f.createContext({appEmitter:new E});function x(){return f.useContext(z)}function X({children:e}){return()=>{const t=m(()=>({appEmitter:new E}),[]);return N.jsx(z.Provider,{value:t,children:e})}}function Y(e){return m(()=>({controller:{get model(){return e.model.current.stateful},queue:[],actions:{annotate(t,n){return F(t,n)},produce(t){return(n,r)=>J(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},actions:{dispatch([t,...n]){if(t==null)return Promise.reject();const r=Promise.withResolvers();return e.dispatchers.dispatch(t,n,r),r.promise}}}}),[])}function Z(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 L(e){const t=x(),n=Q(e);return m(()=>{const r=new E,i=t.appEmitter;return{attach(o,c){const l=String(o);C(l)?i.on(l,n(o,c)):r.on(l,n(o,c))},dispatch(o,c,l){const h=String(o);C(h)?i.emit(h,l,c):r.emit(h,l,c)}}},[])}function ee(){const e=f.useRef(null);return m(()=>({customElement:e}),[])}function te(e){U(()=>{e.dispatchers.dispatch(v.Derive,[])},[e.options.using.props]),U(()=>(e.dispatchers.dispatch(v.Mount,[]),e.dispatchers.dispatch(v.Node,[e.elements.customElement.current]),()=>e.dispatchers.dispatch(v.Unmount,[])),[])}function ne(e){const t=m(()=>e.options.using.model??{},[]);return f.useRef(new S(t,t))}function re(){return f.useRef(new Set)}function se(){const[e,t]=f.useReducer(n=>n+1,0);return m(()=>({hash:e,rerender:t}),[e])}function oe({options:e}){const t=x(),n=se(),r=re(),i=ee(),o=ne({options:e}),c=L({app:t,options:e,update:n,model:o,queue:r}),l=Y({app:t,options:e,model:o,dispatchers:c});return Z({options:e,dispatchers:c,actions:l}),te({options:e,dispatchers:c,elements:i,update:n}),m(()=>f.createElement("x-chizu",{ref:i.customElement,style:{display:"contents"},children:e.children(l.view)}),[n.hash,y(e.using.props)])}function ue(e){return oe({options:e})}const ie=f.memo(ue,(e,t)=>y(e)===y(t));s.Context=X,s.EventError=A,s.Lifecycle=v,s.State=T,s.Tree=ie,s.useContext=x,s.utils=V,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { EventError } from '../module/renderer/dispatchers/utils.ts';
|
|
2
2
|
import { Models } from '../module/renderer/model/utils.ts';
|
|
3
3
|
import { Head } from '../module/renderer/types.ts';
|
|
4
|
-
import { Actions, Draft, Lifecycle, ModuleDefinition, Op,
|
|
5
|
-
import * as Router from "../module/renderer/router/types.ts";
|
|
4
|
+
import { Actions, Draft, Lifecycle, ModuleDefinition, Op, Queue } from '../types/index.ts';
|
|
6
5
|
export type ControllerActions<M extends ModuleDefinition> = {
|
|
7
6
|
annotate<T>(value: T, operations?: (Op | Draft<T>)[]): T;
|
|
8
7
|
produce(ƒ: (model: M["Model"]) => void): (models: Models<M["Model"]>, process: Symbol) => Models<M["Model"]>;
|
|
@@ -11,9 +10,7 @@ export type ControllerActions<M extends ModuleDefinition> = {
|
|
|
11
10
|
export type ControllerArgs<M extends ModuleDefinition> = Readonly<{
|
|
12
11
|
model: Readonly<M["Model"]>;
|
|
13
12
|
queue: Readonly<Queue<M["Actions"]>>;
|
|
14
|
-
router: M["Query"] extends NonNullable<Query> ? Readonly<Router.Context<M["Query"]>> : null;
|
|
15
13
|
actions: Readonly<ControllerActions<M>>;
|
|
16
|
-
props: Readonly<M["Props"]>;
|
|
17
14
|
}>;
|
|
18
15
|
export type ActionEvent<M extends ModuleDefinition> = (...args: M["Actions"][number]) => ActionGenerator<M>;
|
|
19
16
|
type ActionEvents<M extends ModuleDefinition> = {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import { default as app } from './app/index.tsx';
|
|
2
1
|
import { ControllerDefinition } from './controller/types.ts';
|
|
3
|
-
import { default as module } from './module/index.tsx';
|
|
4
2
|
import { ViewArgs, ViewDefinition } from './view/types.ts';
|
|
5
3
|
export { Lifecycle, State } from './types/index.ts';
|
|
6
4
|
export * as utils from './utils/index.ts';
|
|
7
|
-
export declare const create: {
|
|
8
|
-
app: typeof app;
|
|
9
|
-
module: typeof module;
|
|
10
|
-
};
|
|
11
5
|
export { EventError } from './module/renderer/dispatchers/utils.ts';
|
|
12
|
-
export
|
|
6
|
+
export { default as Tree } from './module/index.tsx';
|
|
7
|
+
export { AppContext as Context, useApp as useContext, } from './context/index.tsx';
|
|
8
|
+
export type * as Typed from './types/index.ts';
|
|
13
9
|
export type { Pk } from './types/index.ts';
|
|
14
10
|
export type { ViewDefinition as View };
|
|
15
11
|
export type { ViewArgs as Within };
|
|
16
|
-
export type { ControllerDefinition as
|
|
12
|
+
export type { ControllerDefinition as Actions };
|
package/dist/module/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ModuleDefinition } from '../types/index.ts';
|
|
2
|
-
import {
|
|
2
|
+
import { UseOptions } from './types.ts';
|
|
3
3
|
import * as React from "react";
|
|
4
|
-
|
|
4
|
+
declare function Tree<M extends ModuleDefinition>(options: UseOptions<M>): React.ReactNode;
|
|
5
|
+
declare const _default: typeof Tree;
|
|
6
|
+
export default _default;
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import { UseApp } from '../../../
|
|
1
|
+
import { UseApp } from '../../../context/types.ts';
|
|
2
2
|
import { ControllerArgs } from '../../../controller/types.ts';
|
|
3
3
|
import { ModuleDefinition } from '../../../types/index.ts';
|
|
4
4
|
import { ViewArgs } from '../../../view/types.ts';
|
|
5
|
+
import { UseOptions } from '../../types.ts';
|
|
5
6
|
import { UseDispatchers } from '../dispatchers/types.ts';
|
|
6
7
|
import { UseModel } from '../model/types.ts';
|
|
7
|
-
import { UseProps } from '../props/types.ts';
|
|
8
|
-
import { UseRouter } from '../router/types.ts';
|
|
9
|
-
import { UseOptions } from '../types.ts';
|
|
10
8
|
export type Props<M extends ModuleDefinition> = {
|
|
11
9
|
app: UseApp;
|
|
12
10
|
options: UseOptions<M>;
|
|
13
11
|
model: UseModel;
|
|
14
12
|
dispatchers: UseDispatchers;
|
|
15
|
-
router: UseRouter;
|
|
16
|
-
props: UseProps;
|
|
17
13
|
};
|
|
18
14
|
export type UseActions<M extends ModuleDefinition> = {
|
|
19
15
|
controller: ControllerArgs<M>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ModuleDefinition } from '../../../types/index.ts';
|
|
2
2
|
import { Props } from './types.ts';
|
|
3
|
-
export default function useController<M extends ModuleDefinition>(props: Props<M>): import('../../../controller/types.ts').ControllerInstance<M
|
|
3
|
+
export default function useController<M extends ModuleDefinition>(props: Props<M>): import('../../../controller/types.ts').ControllerInstance<M>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ModuleDefinition } from '../../../types/index.ts';
|
|
2
|
+
import { UseOptions } from '../../types.ts';
|
|
2
3
|
import { UseActions } from '../actions/types.ts';
|
|
3
4
|
import { UseDispatchers } from '../dispatchers/types.ts';
|
|
4
|
-
import { UseOptions } from '../types.ts';
|
|
5
5
|
import { default as useController } from './index.ts';
|
|
6
6
|
export type Props<M extends ModuleDefinition> = {
|
|
7
7
|
actions: UseActions<M>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { UseApp } from '../../../
|
|
1
|
+
import { UseApp } from '../../../context/types.ts';
|
|
2
2
|
import { ModuleDefinition } from '../../../types/index.ts';
|
|
3
|
+
import { UseOptions } from '../../types.ts';
|
|
3
4
|
import { UseModel } from '../model/types.ts';
|
|
4
5
|
import { UseQueue } from '../queue/types.ts';
|
|
5
|
-
import { UseOptions } from '../types.ts';
|
|
6
6
|
import { UseUpdate } from '../update/types.ts';
|
|
7
7
|
import { default as useDispatchers } from './index.ts';
|
|
8
8
|
export type Props<M extends ModuleDefinition> = {
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { ModuleDefinition } from '../../../types/index.ts';
|
|
2
|
+
import { UseOptions } from '../../types.ts';
|
|
2
3
|
import { UseDispatchers } from '../dispatchers/types.ts';
|
|
3
4
|
import { UseElements } from '../elements/types.ts';
|
|
4
|
-
import { UseRouter } from '../router/types.ts';
|
|
5
|
-
import { UseOptions } from '../types.ts';
|
|
6
5
|
import { UseUpdate } from '../update/types.ts';
|
|
7
6
|
import { default as useLifecycles } from './index.ts';
|
|
8
7
|
export type Props<M extends ModuleDefinition> = {
|
|
9
8
|
options: UseOptions<M>;
|
|
10
9
|
elements: UseElements;
|
|
11
10
|
dispatchers: UseDispatchers;
|
|
12
|
-
router: UseRouter;
|
|
13
11
|
update: UseUpdate;
|
|
14
12
|
};
|
|
15
13
|
export type UseLifecycles = ReturnType<typeof useLifecycles>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { default as useModel } from '.';
|
|
2
2
|
import { ModuleDefinition, State } from '../../../types/index.ts';
|
|
3
|
-
import { UseOptions } from '
|
|
3
|
+
import { UseOptions } from '../../types.ts';
|
|
4
4
|
export type Props<M extends ModuleDefinition> = {
|
|
5
5
|
options: UseOptions<M>;
|
|
6
6
|
};
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { ModuleDefinition } from '../../types/index.ts';
|
|
2
|
-
import {
|
|
2
|
+
import { UseOptions } from '../types.ts';
|
|
3
3
|
export type ElementName = string;
|
|
4
4
|
export type Props<M extends ModuleDefinition> = {
|
|
5
5
|
options: UseOptions<M>;
|
|
6
6
|
};
|
|
7
|
-
export type UseOptions<M extends ModuleDefinition> = Options<M> & {
|
|
8
|
-
name: ElementName;
|
|
9
|
-
props: M["Props"];
|
|
10
|
-
};
|
|
11
7
|
export type Head<T extends any[]> = T extends [infer X, ...any[]] ? X : never;
|
|
12
8
|
export type Tail<T extends any[]> = T extends [any, ...infer XS] ? XS : never;
|
package/dist/module/types.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { ControllerDefinition } from '../controller/types.ts';
|
|
2
2
|
import { ModuleDefinition } from '../types/index.ts';
|
|
3
|
-
import {
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import { ViewArgs } from '../view/types.ts';
|
|
4
|
+
export type UseOptions<M extends ModuleDefinition> = {
|
|
5
|
+
using: {
|
|
6
|
+
model: M["Model"];
|
|
7
|
+
actions: ControllerDefinition<M>;
|
|
8
|
+
props?: M["Props"];
|
|
9
|
+
};
|
|
10
|
+
children(module: ViewArgs<M>): React.ReactNode;
|
|
9
11
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -30,23 +30,15 @@ export declare enum Lifecycle {
|
|
|
30
30
|
export type Model = Record<string, any>;
|
|
31
31
|
export type Actions = [] | [ActionName] | [ActionName, ...ActionPayload];
|
|
32
32
|
export type Props = Record<string, unknown>;
|
|
33
|
-
export type
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
Props?: Props;
|
|
38
|
-
Query?: Query;
|
|
39
|
-
} = {}> = {
|
|
40
|
-
Model: T["Model"] extends Model ? T["Model"] : {};
|
|
41
|
-
Actions: T["Actions"] extends Actions ? T["Actions"] : [];
|
|
42
|
-
Props: T["Props"] extends Props ? T["Props"] : {};
|
|
43
|
-
Query: T["Query"] extends Query ? T["Query"] : null;
|
|
33
|
+
export type Module<M extends Model, A extends Actions = [], P extends Props = {}> = {
|
|
34
|
+
Model: M;
|
|
35
|
+
Actions: A;
|
|
36
|
+
Props: P;
|
|
44
37
|
};
|
|
45
38
|
export type ModuleDefinition = {
|
|
46
39
|
Model: Model;
|
|
47
40
|
Actions: Actions;
|
|
48
41
|
Props: Props;
|
|
49
|
-
Query: Query;
|
|
50
42
|
};
|
|
51
43
|
export type Pk<T> = undefined | Symbol | T;
|
|
52
44
|
export type Queue<A extends ModuleDefinition["Actions"]> = {
|
package/dist/view/types.d.ts
CHANGED
|
@@ -8,6 +8,5 @@ export type ViewArgs<M extends ModuleDefinition> = Readonly<{
|
|
|
8
8
|
model: Readonly<M["Model"]>;
|
|
9
9
|
validate: Readonly<Validatable<M["Model"]>>;
|
|
10
10
|
actions: Readonly<ViewActions<M>>;
|
|
11
|
-
props: Readonly<M["Props"]>;
|
|
12
11
|
}>;
|
|
13
12
|
export type ViewDefinition<M extends ModuleDefinition> = (actions: ViewArgs<M>) => React.ReactNode;
|
package/package.json
CHANGED
package/dist/app/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ModuleDefinition } from '../../../types/index.ts';
|
|
2
|
-
import { UseOptions } from '../types.ts';
|
|
3
|
-
import { UseUpdate } from '../update/types.ts';
|
|
4
|
-
import { default as useProps } from './index.ts';
|
|
5
|
-
export type Props<M extends ModuleDefinition> = {
|
|
6
|
-
options: UseOptions<M>;
|
|
7
|
-
update: UseUpdate;
|
|
8
|
-
};
|
|
9
|
-
export type UseProps = ReturnType<typeof useProps>;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Query } from '../../../types/index.ts';
|
|
2
|
-
import { Context, Props } from './types.ts';
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
export declare function useRouter(): React.RefObject<Partial<Context<Query>> | null>;
|
|
5
|
-
export declare function Router({ using, children }: Props): React.ReactNode;
|
|
6
|
-
export declare function Setup({ using, children }: Props): React.ReactNode;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Query } from '../../../types/index.ts';
|
|
2
|
-
import { useRouter } from './index.ts';
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import * as ReactRouterDOM from "react-router-dom";
|
|
5
|
-
export type Props = {
|
|
6
|
-
using: UseRouter;
|
|
7
|
-
children(): React.ReactNode;
|
|
8
|
-
};
|
|
9
|
-
export type UseRouter = ReturnType<typeof useRouter>;
|
|
10
|
-
export type Context<Q extends null | Query> = {
|
|
11
|
-
navigate: ReactRouterDOM.NavigateFunction;
|
|
12
|
-
location: ReactRouterDOM.Location;
|
|
13
|
-
params: Q extends NonNullable<Query> ? Readonly<ReactRouterDOM.Params<Q>> : null;
|
|
14
|
-
search: [URLSearchParams, ReactRouterDOM.SetURLSearchParams];
|
|
15
|
-
};
|