chizu 0.2.2 → 0.2.3
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 +28 -28
- package/dist/chizu.js +240 -2948
- package/dist/chizu.umd.cjs +1 -12
- package/dist/controller/types.d.ts +12 -9
- package/dist/module/renderer/controller/index.d.ts +1 -1
- package/dist/module/renderer/lifecycles/types.d.ts +2 -0
- package/dist/module/renderer/router/index.d.ts +4 -3
- package/dist/module/renderer/router/types.d.ts +6 -3
- package/dist/module/renderer/types.d.ts +2 -2
- package/dist/module/types.d.ts +2 -2
- package/dist/types/index.d.ts +19 -13
- package/dist/view/types.d.ts +4 -5
- package/package.json +2 -6
package/README.md
CHANGED
|
@@ -30,10 +30,10 @@ Controllers are responsible for mutating the state of the view. In the below exa
|
|
|
30
30
|
<kbd>Controller</kbd>
|
|
31
31
|
|
|
32
32
|
```tsx
|
|
33
|
-
export default create.controller<Module>((
|
|
33
|
+
export default create.controller<Module>((module) => {
|
|
34
34
|
return {
|
|
35
35
|
async *[Events.Name](name) {
|
|
36
|
-
return
|
|
36
|
+
return module.actions.produce((draft) => {
|
|
37
37
|
draft.name = name;
|
|
38
38
|
});
|
|
39
39
|
},
|
|
@@ -44,13 +44,13 @@ export default create.controller<Module>((self) => {
|
|
|
44
44
|
<kbd>View</kbd>
|
|
45
45
|
|
|
46
46
|
```tsx
|
|
47
|
-
export default create.view<Module>((
|
|
47
|
+
export default create.view<Module>((module) => {
|
|
48
48
|
return (
|
|
49
49
|
<>
|
|
50
|
-
<p>Hey {
|
|
50
|
+
<p>Hey {module.model.name}</p>
|
|
51
51
|
|
|
52
52
|
<button
|
|
53
|
-
onClick={() =>
|
|
53
|
+
onClick={() => module.actions.dispatch([Events.Name, randomName()])}
|
|
54
54
|
>
|
|
55
55
|
Switch profile
|
|
56
56
|
</button>
|
|
@@ -64,16 +64,16 @@ Fetching the name from an external source using an `actions.io` causes the contr
|
|
|
64
64
|
<kbd>Controller</kbd>
|
|
65
65
|
|
|
66
66
|
```tsx
|
|
67
|
-
export default create.controller<Module>((
|
|
67
|
+
export default create.controller<Module>((module) => {
|
|
68
68
|
return {
|
|
69
69
|
async *[Events.Name]() {
|
|
70
|
-
yield
|
|
70
|
+
yield module.actions.produce((draft) => {
|
|
71
71
|
draft.name = null;
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
const name = await fetch(/* ... */);
|
|
75
75
|
|
|
76
|
-
return
|
|
76
|
+
return module.actions.produce((draft) => {
|
|
77
77
|
draft.name = name;
|
|
78
78
|
});
|
|
79
79
|
},
|
|
@@ -84,12 +84,12 @@ export default create.controller<Module>((self) => {
|
|
|
84
84
|
<kbd>View</kbd>
|
|
85
85
|
|
|
86
86
|
```tsx
|
|
87
|
-
export default create.view<Module>((
|
|
87
|
+
export default create.view<Module>((module) => {
|
|
88
88
|
return (
|
|
89
89
|
<>
|
|
90
|
-
<p>Hey {
|
|
90
|
+
<p>Hey {module.model.name}</p>
|
|
91
91
|
|
|
92
|
-
<button onClick={() =>
|
|
92
|
+
<button onClick={() => module.actions.dispatch([Events.Name])}>
|
|
93
93
|
Switch profile
|
|
94
94
|
</button>
|
|
95
95
|
</>
|
|
@@ -97,20 +97,20 @@ export default create.view<Module>((self) => {
|
|
|
97
97
|
});
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
<!-- In the above example the name is fetched asynchronously – however there is no feedback to the user, we can improve that by using the `
|
|
100
|
+
<!-- In the above example the name is fetched asynchronously – however there is no feedback to the user, we can improve that by using the `module.actions.state` and `module.validate` helpers: -->
|
|
101
101
|
|
|
102
102
|
<kbd>Controller</kbd>
|
|
103
103
|
|
|
104
104
|
```tsx
|
|
105
|
-
export default create.controller<Module>((
|
|
105
|
+
export default create.controller<Module>((module) => {
|
|
106
106
|
return {
|
|
107
107
|
async *[Events.Name]() {
|
|
108
|
-
yield
|
|
109
|
-
draft.name =
|
|
108
|
+
yield module.actions.produce((draft) => {
|
|
109
|
+
draft.name = module.actions.annotate(null, [State.Op.Update]);
|
|
110
110
|
});
|
|
111
111
|
|
|
112
112
|
const name = await fetch(/* ... */);
|
|
113
|
-
return
|
|
113
|
+
return module.actions.produce((draft) => {
|
|
114
114
|
draft.name = name;
|
|
115
115
|
});
|
|
116
116
|
},
|
|
@@ -121,16 +121,16 @@ export default create.controller<Module>((self) => {
|
|
|
121
121
|
<kbd>View</kbd>
|
|
122
122
|
|
|
123
123
|
```tsx
|
|
124
|
-
export default create.view<Module>((
|
|
124
|
+
export default create.view<Module>((module) => {
|
|
125
125
|
return (
|
|
126
126
|
<>
|
|
127
|
-
<p>Hey {
|
|
127
|
+
<p>Hey {module.model.name}</p>
|
|
128
128
|
|
|
129
|
-
{
|
|
129
|
+
{module.validate.name.pending() && <p>Switching profiles…</p>}
|
|
130
130
|
|
|
131
131
|
<button
|
|
132
|
-
disabled={
|
|
133
|
-
onClick={() =>
|
|
132
|
+
disabled={module.validate.name.is(State.Op.Update)}
|
|
133
|
+
onClick={() => module.actions.dispatch([Events.Name])}
|
|
134
134
|
>
|
|
135
135
|
Switch profile
|
|
136
136
|
</button>
|
|
@@ -157,10 +157,10 @@ export const enum Errors {
|
|
|
157
157
|
<kbd>Controller</kbd>
|
|
158
158
|
|
|
159
159
|
```tsx
|
|
160
|
-
export default create.controller<Module>((
|
|
160
|
+
export default create.controller<Module>((module) => {
|
|
161
161
|
return {
|
|
162
162
|
*[Events.Name]() {
|
|
163
|
-
yield
|
|
163
|
+
yield module.actions.produce((draft) => {
|
|
164
164
|
draft.name = null;
|
|
165
165
|
});
|
|
166
166
|
|
|
@@ -168,7 +168,7 @@ export default create.controller<Module>((self) => {
|
|
|
168
168
|
|
|
169
169
|
if (!name) throw new EventError(Errors.UserValidation);
|
|
170
170
|
|
|
171
|
-
return
|
|
171
|
+
return module.actions.produce((draft) => {
|
|
172
172
|
draft.name = name;
|
|
173
173
|
});
|
|
174
174
|
},
|
|
@@ -181,22 +181,22 @@ However showing a toast message is not always relevant, you may want a more deta
|
|
|
181
181
|
<kbd>Controller</kbd>
|
|
182
182
|
|
|
183
183
|
```tsx
|
|
184
|
-
export default create.controller<Module>((
|
|
184
|
+
export default create.controller<Module>((module) => {
|
|
185
185
|
return {
|
|
186
186
|
async *[Events.Name]() {
|
|
187
|
-
yield
|
|
187
|
+
yield module.actions.produce((draft) => {
|
|
188
188
|
draft.name = Maybe.of(null);
|
|
189
189
|
});
|
|
190
190
|
|
|
191
191
|
const name = await fetch(/* ... */);
|
|
192
192
|
|
|
193
193
|
if (!name) {
|
|
194
|
-
return
|
|
194
|
+
return module.actions.produce((draft) => {
|
|
195
195
|
draft.name = Maybe.of(new EventError(Errors.UserValidation));
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
return
|
|
199
|
+
return module.actions.produce((draft) => {
|
|
200
200
|
draft.name = Maybe.of(name);
|
|
201
201
|
});
|
|
202
202
|
},
|