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 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 events](#distributed-events)
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
- [Events.Name](name) {
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
- <Tree<Module> using={{ model, actions, props }}>
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([Events.Name, randomName()])}
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 *[Events.Name]() {
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
- <Tree<Module> using={{ model, actions, props }}>
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([Events.Name])}>
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 *[Events.Name]() {
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
- <Tree<Module> using={{ module, actions, props }}>
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([Events.Name])}
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
- *[Events.Name]() {
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 &ndash; 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 &ndash; 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 channel will be switched to `Channel.Error` which you detect using `module.channel.is(Channel.Error)` and switch to an alternative markup that _should_ render, within that you could display a button to attempt recovery &ndash; simply call an action again and update the meta to switch the channel back to `Channel.Default`:
168
+ Additionally when rendering an error may be thrown which prevents the DOM from updating as you'd expect &ndash; 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 &ndash; 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
- *[Events.Recover]() {
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.channel = Channel.Default;
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 `Channel.Error` again.
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 events
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 DistributedEvents {
196
+ export enum DistributedAction {
197
197
  SignedOut = "distributed/signed-out",
198
198
  }
199
199
 
200
- export type DistributedActions = [DistributedEvents.SignedOut];
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 events you simply need to augment the module actions union with the `DistributedActions` and use it as you do other actions:
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 | [Events.Task, string]; // etc...
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&hellip; but want to still fire events either the closest module or a distributed event, you can use the `useModule` hook:
211
+ In the eventuality that you have a component but don't want associated actions, models, etc&hellip; 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 = useModule<Module>();
214
+ const module = useScoped<Module>();
215
215
 
216
216
  // ...
217
217
 
218
- module.actions.dispatch([Event.Task, "My task that needs to be done."]);
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
- export declare function BroadcastProvider({ children }: Props): React.ReactNode;
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;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Check if the name is a broadcast event.
2
+ * Check if the name is a broadcast action.
3
3
  *
4
4
  * @param name {string}
5
5
  * @returns {boolean}
package/dist/chizu.js CHANGED
@@ -1,16 +1,16 @@
1
1
  var J = Object.defineProperty;
2
- var C = (t) => {
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 g = (t, e, n) => Q(t, typeof e != "symbol" ? e + "" : e, n), O = (t, e, n) => e.has(t) || C("Cannot " + n);
7
- var b = (t, e, n) => (O(t, e, "read from private field"), n ? n.call(t) : e.get(t)), x = (t, e, n) => e.has(t) ? C("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, n), R = (t, e, n, r) => (O(t, e, "write to private field"), r ? r.call(t, n) : e.set(t, n), n);
8
- import { jsx as k } from "react/jsx-runtime";
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 U from "eventemitter3";
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 M from "traverse";
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
- g(K, "Op", {
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 f = /* @__PURE__ */ ((t) => (t.Mount = "lifecycle/mount", t.Node = "lifecycle/node", t.Derive = "lifecycle/derive", t.Error = "lifecycle/error", t.Unmount = "lifecycle/unmount", t))(f || {}), j = /* @__PURE__ */ ((t) => (t[t.Default = 0] = "Default", t[t.Error = 1] = "Error", t))(j || {});
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 y = Symbol("meta"), wt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
41
+ const w = Symbol("meta"), yt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
42
42
  __proto__: null,
43
43
  hash: m,
44
- meta: y,
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 o = m(e);
52
- if (r.current !== o) {
53
- r.current = o;
54
- const s = t();
55
- return n.current = s, s;
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 _(t, e) {
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 H = i.createContext({
69
- appEmitter: new U()
68
+ const B = i.createContext({
69
+ appEmitter: new k()
70
70
  });
71
- function T() {
72
- return i.useContext(H);
71
+ function H() {
72
+ return i.useContext(B);
73
73
  }
74
- function yt({ children: t }) {
74
+ function wt({ children: t }) {
75
75
  const e = l(
76
76
  () => ({
77
- appEmitter: new U()
77
+ appEmitter: new k()
78
78
  }),
79
79
  []
80
80
  );
81
- return /* @__PURE__ */ k(H.Provider, { value: e, children: t });
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 P {
89
+ class C {
90
90
  constructor(e, n, r = null) {
91
- g(this, "process");
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 P(t, e);
99
+ return new C(t, e);
100
100
  }
101
- class A {
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 z(this.stateful);
106
+ return T(this.stateful);
107
107
  }
108
108
  }
109
- function z(t, e = []) {
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 (o) => {
115
- const s = S(t, e);
116
- if (!s) return !1;
114
+ return (s) => {
115
+ const o = R(t, e);
116
+ if (!o) return !1;
117
117
  const c = new Set(
118
- s.flatMap((d) => d.operations)
118
+ o.flatMap((d) => d.operations)
119
119
  );
120
120
  return !!(Array.from(c).reduce(
121
- (d, h) => d | (h ?? 0),
121
+ (d, f) => d | (f ?? 0),
122
122
  0
123
- ) & o);
123
+ ) & s);
124
124
  };
125
125
  case "pending":
126
- return () => !!S(t, e);
126
+ return () => !!R(t, e);
127
127
  case "draft":
128
128
  return () => {
129
- const o = S(t, e);
130
- if (!o) return p(t, e);
131
- const s = o.flatMap((c) => c.operations).find((c) => c instanceof $);
132
- return s ? s.value : p(t, e);
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 z(t, [...e, String(r)]);
135
+ return T(t, [...e, String(r)]);
136
136
  }
137
137
  });
138
138
  }
139
- function S(t, e) {
140
- 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[a.annotations]) ?? [];
141
- return s.length > 0 ? s : null;
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 q(t, e, n) {
143
+ function z(t, e, n) {
144
144
  function r(c) {
145
- return M(c).forEach(function() {
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 P && this.update(this.node.value);
150
+ this.node instanceof C && this.update(this.node.value);
151
151
  });
152
152
  }
153
- function o(c) {
154
- return M(c).forEach(function() {
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 P) {
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
- ], h = p(t.stateful, d) ?? [], w = this.node.attach(e);
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]: [w, ...h]
167
+ [a.annotations]: [y, ...f]
168
168
  },
169
169
  !0
170
- ) : (this.parent && (this.parent.node[a.annotations] = [w, ...h]), this.update(this.node.value, !0));
170
+ ) : (this.parent && (this.parent.node[a.annotations] = [y, ...f]), this.update(this.node.value, !0));
171
171
  }
172
172
  });
173
173
  }
174
- const s = (c) => n(c, c[y]);
175
- return new A(
176
- r(a.immer.produce(t.stateless, s)),
177
- o(a.immer.produce(t.stateful, s))
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 = M(t.stateful).forEach(function() {
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
- (o) => o.process !== e
192
+ (s) => s.process !== e
193
193
  )
194
194
  },
195
195
  !0
196
196
  );
197
197
  }
198
198
  });
199
- return new A(t.stateless, n);
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) => q(n, r, e);
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
- channel: {
230
+ boundary: {
231
231
  is(e) {
232
- return t.model.current.stateless[y].channel === e;
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, o]) => t.dispatchers.attach(r, o)), e;
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 B;
257
+ return t instanceof I;
261
258
  }
262
- function I(t) {
263
- return t instanceof B || t instanceof Error ? t : new Error("Unknown error", { cause: t });
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 B extends Error {
263
+ class I extends Error {
267
264
  constructor(n, r = null) {
268
265
  super(String(r));
269
- x(this, v);
270
- x(this, E);
271
- R(this, v, n), R(this, E, r);
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 b(this, v);
271
+ return g(this, v);
275
272
  }
276
273
  get message() {
277
- return b(this, E) || "";
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(), o) => {
284
+ return (e, n) => async (r = Promise.withResolvers(), s) => {
288
285
  if (typeof n != "function") return;
289
- const s = Symbol("process"), c = n(...o);
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, s);
294
- t.model.current = D(u, s), t.update.rerender(), r.resolve();
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 w = u(t.model.current, s);
301
- t.model.current = D(w, s), t.update.rerender();
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 h = u;
305
- t.model.current = h(t.model.current, s), t.update.rerender(), r.resolve();
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, s), t.update.rerender(), t.unicast.emit(f.Error, r, [I(u)]);
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 = T(), n = l(() => new U(), []), r = et({ ...t, unicast: n });
310
+ const e = H(), n = l(() => new k(), []), r = et({ ...t, unicast: n });
314
311
  return l(() => ({
315
- attach(o, s) {
316
- const c = String(o);
317
- N(c) ? e.appEmitter.on(c, r(o, s)) : n.on(c, r(o, s));
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(o, s, c) {
320
- const u = String(o);
321
- N(u) ? e.appEmitter.emit(u, c, s) : n.emit(u, c, s);
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 st(t) {
330
- _(() => {
331
- t.dispatchers.dispatch(f.Derive, []);
332
- }, [t.options.using.props]), _(() => (t.dispatchers.dispatch(f.Mount, []), t.dispatchers.dispatch(f.Node, [
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(f.Unmount, [])), []);
331
+ ]), () => t.dispatchers.dispatch(h.Unmount, [])), []);
335
332
  }
336
- function ot(t) {
337
- const e = l(() => ({ ...t.options.using.model ?? {}, [y]: { channel: j.Default } }), []);
338
- return i.useRef(new A(e, e));
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 xt() {
349
+ function gt() {
353
350
  const t = i.useContext(F);
354
- if (!t) throw new Error("useModule must be used within a module.");
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 = q(this.props.model.current, n, (o, s) => {
363
- s.channel = j.Error;
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(f.Error, [I(e)]);
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__ */ k(tt, { children: this.props.children });
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(), o = T(), s = ot({ options: t }), c = nt({
375
- broadcast: o,
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: s,
376
+ model: o,
379
377
  queue: n
380
- }), u = Z({ model: s, dispatchers: c });
381
- return L({ options: t, dispatchers: c, actions: u }), st({ options: t, dispatchers: c, elements: r }), l(() => i.createElement(at, {
382
- model: s,
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__ */ k(lt, { options: t });
398
+ return /* @__PURE__ */ M(lt, { options: t });
401
399
  }
402
- const Rt = i.memo(dt, (t, e) => m(t) === m(e));
400
+ const St = i.memo(dt, (t, e) => m(t) === m(e));
403
401
  export {
404
- yt as BroadcastProvider,
405
- j as Channel,
406
- f as Lifecycle,
402
+ j as Boundary,
403
+ wt as Broadcaster,
404
+ h as Lifecycle,
405
+ St as Scope,
407
406
  K as State,
408
- Rt as Tree,
409
- B as UserError,
410
- gt as isActionError,
411
- bt as isUserError,
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
  };
@@ -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,v,q,w,D){"use strict";var Ee=Object.defineProperty;var W=s=>{throw TypeError(s)};var we=(s,i,d)=>i in s?Ee(s,i,{enumerable:!0,configurable:!0,writable:!0,value:d}):s[i]=d;var k=(s,i,d)=>we(s,typeof i!="symbol"?i+"":i,d),G=(s,i,d)=>i.has(s)||W("Cannot "+d);var _=(s,i,d)=>(G(s,i,"read from private field"),d?d.call(s):i.get(s)),C=(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),T=(s,i,d,v)=>(G(s,i,"write to private field"),v?v.call(s,d):i.set(s,d),d);var b,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)}}k(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 y(e){return JSON.stringify(e)}const j=Symbol("meta"),Y=Object.freeze(Object.defineProperty({__proto__:null,hash:y,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=y(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=y(t);if(n.current!==r)return n.current=r,e()},t)}const z=l.createContext({appEmitter:new v});function $(){return l.useContext(z)}function Z({children:e}){const t=h(()=>({appEmitter:new v}),[]);return i.jsx(z.Provider,{value:t,children:e})}const f={immer:new q.Immer,annotations:Symbol("annotations")};q.enablePatches(),f.immer.setAutoFreeze(!1);class R{constructor(t,n,r=null){k(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 O{constructor(t,n=t){this.stateless=t,this.stateful=n}get validatable(){return H(this.stateful)}}function H(e,t=[]){return new Proxy(e,{get(n,r){switch(r){case"is":return c=>{const o=x(e,t);if(!o)return!1;const u=new Set(o.flatMap(p=>p.operations));return!!(Array.from(u).reduce((p,E)=>p|(E??0),0)&c)};case"pending":return()=>!!x(e,t);case"draft":return()=>{const c=x(e,t);if(!c)return w(e,t);const o=c.flatMap(u=>u.operations).find(u=>u instanceof A);return o?o.value:w(e,t)}}return H(e,[...t,String(r)])}})}function x(e,t){const r=typeof w(e,t)=="object"?t:t.slice(0,-1),c=r.length===0?e:w(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 D(u).forEach(function(){if(this.key===f.annotations){this.block();return}this.node instanceof R&&this.update(this.node.value)})}function c(u){return D(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],E=w(e.stateful,p)??[],M=this.node.attach(t);a?this.update({...this.node.value,[f.annotations]:[M,...E]},!0):(this.parent&&(this.parent.node[f.annotations]=[M,...E]),this.update(this.node.value,!0))}})}const o=u=>n(u,u[j]);return new O(r(f.immer.produce(e.stateless,o)),c(f.immer.produce(e.stateful,o)))}function U(e,t){const n=D(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 O(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},channel:{is(t){return e.model.current.stateless[j].channel===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 P}function re(e){return e instanceof P}function J(e){return e instanceof P||e instanceof Error?e:new Error("Unknown error",{cause:e})}class P extends Error{constructor(n,r=null){super(String(r));C(this,b);C(this,g);T(this,b,n),T(this,g,r)}get type(){return _(this,b)}get message(){return _(this,g)||""}}b=new WeakMap,g=new WeakMap;function se({children:e}){return e()}function oe(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=U(a,o),e.update.rerender(),r.resolve();return}for(;;){const{value:a,done:p}=await u.next();if(p){const M=a(e.model.current,o);e.model.current=U(M,o),e.update.rerender();break}const E=a;e.model.current=E(e.model.current,o),e.update.rerender(),r.resolve()}}catch(a){U(e.model.current,o),e.update.rerender(),e.unicast.emit(m.Error,r,[J(a)])}}}function ce(e){const t=$(),n=h(()=>new v,[]),r=oe({...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 ue(){const e=l.useRef(null);return h(()=>({customElement:e}),[])}function ie(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 ae(e){const t=h(()=>({...e.options.using.model??{},[j]:{channel:S.Default}}),[]);return l.useRef(new O(t,t))}function le(){return l.useRef(new Set)}function de(){const[e,t]=l.useReducer(n=>n+1,0);return h(()=>({hash:e,rerender:t}),[e])}const fe={elementName:"x-chizu"},Q=l.createContext(null);function he(){const e=l.useContext(Q);if(!e)throw new Error("useModule must be used within a module.");return e}class me 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.channel=S.Error});this.props.model.current=r,this.props.update.rerender(),this.props.dispatchers.dispatch(m.Error,[J(t)])}render(){return i.jsx(se,{children:this.props.children})}}function pe({options:e}){const t=de(),n=le(),r=ue(),c=$(),o=ae({options:e}),u=ce({broadcast:c,options:e,update:t,model:o,queue:n}),a=ee({model:o,dispatchers:u});return te({options:e,dispatchers:u,actions:a}),ie({options:e,dispatchers:u,elements:r}),h(()=>l.createElement(me,{model:o,dispatchers:u,update:t,module:a.view,children(){return l.createElement(Q.Provider,{value:a.view,children:l.createElement(fe.elementName,{ref:r.customElement,style:{display:"contents"},children:e.children(a.view)})})}}),[t.hash,y(e.using.props)])}function ve(e){return i.jsx(pe,{options:e})}const ye=l.memo(ve,(e,t)=>y(e)===y(t));s.BroadcastProvider=Z,s.Channel=S,s.Lifecycle=m,s.State=B,s.Tree=ye,s.UserError=P,s.isActionError=ne,s.isUserError=re,s.useModule=he,s.utils=Y,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
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 { UserError } from '../errors/utils.ts';
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 | UserError): ActionGenerator<M>;
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;
@@ -1,22 +1,27 @@
1
1
  import { ModuleDefinition } from '../types/index.ts';
2
2
  import { Props } from './types.ts';
3
- export declare function isActionError(error: Error | UserError): error is UserError;
4
- export declare function isUserError(error: Error | UserError): error is UserError;
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 | UserError}
15
+ * @returns {Error | TypedError}
11
16
  */
12
- export declare function intoError(error: unknown): Error | UserError;
17
+ export declare function intoError(error: unknown): Error | TypedError;
13
18
  /**
14
- * @class UserError
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 UserError extends Error {
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, ViewDefinition } from './view/types.ts';
3
- export { Lifecycle, State, Channel } from './types/index.ts';
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 Tree } from './module/index.tsx';
6
- export { BroadcastProvider } from './broadcast/index.tsx';
7
- export { useModule } from './module/renderer/utils.ts';
8
- export { isActionError, isUserError, UserError } from './errors/utils.ts';
9
- export type * as Typed from './types/index.ts';
10
- export type { Pk } from './types/index.ts';
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 };
@@ -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 Tree<M extends ModuleDefinition>(options: UseOptions<M>): React.ReactNode;
5
- declare const _default: typeof Tree;
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 useModule<M extends ModuleDefinition>(): ViewArgs<M>;
8
+ export declare function useScoped<M extends ModuleDefinition>(): ViewArgs<M>;
@@ -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 Module<M extends Model, A extends Actions = [], P extends Props = Record<string, never>> = {
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 Channel {
53
+ export declare enum Boundary {
54
54
  Default = 0,
55
55
  Error = 1
56
56
  }
57
57
  export type Meta = {
58
- channel: Channel;
58
+ boundary: Boundary;
59
59
  };
60
60
  export {};
@@ -1,13 +1,13 @@
1
1
  import { Validatable } from '../module/renderer/model/types.ts';
2
- import { Channel, ModuleDefinition } from '../types/index.ts';
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
- channel: {
10
- is(channel: Channel): boolean;
9
+ boundary: {
10
+ is(boundary: Boundary): boolean;
11
11
  };
12
12
  validate: Readonly<Validatable<M["Model"]>>;
13
13
  actions: Readonly<ViewActions<M>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chizu",
3
- "version": "0.2.21",
3
+ "version": "0.2.22",
4
4
  "type": "module",
5
5
  "main": "./dist/chizu.js",
6
6
  "types": "./dist/index.d.ts",