@actdim/dynstruct 0.9.8 → 1.0.2
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 +18 -14
- package/dist/appDomain/appContracts.d.ts +6 -0
- package/dist/appDomain/appContracts.d.ts.map +1 -1
- package/dist/appDomain/appContracts.es.js +7 -6
- package/dist/appDomain/appContracts.es.js.map +1 -1
- package/dist/appDomain/security/securityProvider.d.ts.map +1 -1
- package/dist/appDomain/security/securityProvider.es.js +6 -6
- package/dist/appDomain/security/securityProvider.es.js.map +1 -1
- package/dist/componentModel/componentModel.d.ts +15 -15
- package/dist/componentModel/componentModel.d.ts.map +1 -1
- package/dist/componentModel/componentModel.es.js +75 -76
- package/dist/componentModel/componentModel.es.js.map +1 -1
- package/dist/componentModel/scope.d.ts +0 -5
- package/dist/componentModel/scope.d.ts.map +1 -1
- package/dist/componentModel/scope.es.js +26 -68
- package/dist/componentModel/scope.es.js.map +1 -1
- package/dist/net/client.es.js +22 -22
- package/dist/net/client.es.js.map +1 -1
- package/dist/net/request.d.ts.map +1 -1
- package/dist/net/request.es.js +32 -27
- package/dist/net/request.es.js.map +1 -1
- package/package.json +38 -34
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
const P = {
|
|
1
|
+
import { useLayoutEffect as k, useEffect as B } from "react";
|
|
2
|
+
import { observer as R } from "mobx-react-lite";
|
|
3
|
+
import { observable as P, runInAction as E } from "mobx";
|
|
4
|
+
import { useLazyRef as G } from "../reactHooks.es.js";
|
|
5
|
+
const O = {
|
|
7
6
|
$isBinding: Symbol("$isBinding")
|
|
8
7
|
};
|
|
9
|
-
class
|
|
8
|
+
class $ {
|
|
10
9
|
// getter
|
|
11
10
|
get;
|
|
12
11
|
// setter
|
|
@@ -14,58 +13,58 @@ class k {
|
|
|
14
13
|
converter;
|
|
15
14
|
validator;
|
|
16
15
|
readOnly;
|
|
17
|
-
constructor(t, o, i,
|
|
18
|
-
this.get = t, this.set = o, this.converter = i, this.validator =
|
|
16
|
+
constructor(t, o, i, l) {
|
|
17
|
+
this.get = t, this.set = o, this.converter = i, this.validator = l, this.readOnly = !!o, this[O.$isBinding] = !0;
|
|
19
18
|
}
|
|
20
|
-
[
|
|
19
|
+
[O.$isBinding];
|
|
21
20
|
}
|
|
22
|
-
function
|
|
23
|
-
return e[
|
|
21
|
+
function w(e) {
|
|
22
|
+
return e[O.$isBinding] === !0;
|
|
24
23
|
}
|
|
25
|
-
function
|
|
26
|
-
return new
|
|
24
|
+
function V(e, t, o, i) {
|
|
25
|
+
return new $(e, t, o, i);
|
|
27
26
|
}
|
|
28
|
-
function
|
|
29
|
-
return new
|
|
27
|
+
function _(e, t) {
|
|
28
|
+
return new $(
|
|
30
29
|
() => e[t],
|
|
31
30
|
(o) => {
|
|
32
31
|
e[t] = o;
|
|
33
32
|
}
|
|
34
33
|
);
|
|
35
34
|
}
|
|
36
|
-
const
|
|
37
|
-
function
|
|
38
|
-
const i = o.onPropChanging,
|
|
35
|
+
const j = "onGet", I = "onChanging", L = "onChange";
|
|
36
|
+
function N(e, t, o) {
|
|
37
|
+
const i = o.onPropChanging, l = o.onPropChange;
|
|
39
38
|
return new Proxy(e, {
|
|
40
|
-
get(
|
|
41
|
-
const C = o[
|
|
39
|
+
get(c, u, g) {
|
|
40
|
+
const C = o[u]?.onGet;
|
|
42
41
|
if (C)
|
|
43
42
|
return C();
|
|
44
|
-
const
|
|
45
|
-
return
|
|
43
|
+
const a = t.get(String(u));
|
|
44
|
+
return a ? a.get() : Reflect.get(c, u, g);
|
|
46
45
|
},
|
|
47
|
-
set(
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
46
|
+
set(c, u, g, C) {
|
|
47
|
+
const a = c[u], y = o[u]?.onChanging;
|
|
48
|
+
if (y && !y(a, g) || i && !i(u, a, g))
|
|
50
49
|
return !0;
|
|
51
|
-
const
|
|
52
|
-
n?.set && n.set(
|
|
53
|
-
const r = o[
|
|
54
|
-
return r && r(
|
|
50
|
+
const b = E(() => Reflect.set(c, u, g, C)), n = t.get(u);
|
|
51
|
+
n?.set && n.set(g);
|
|
52
|
+
const r = o[u]?.onChange;
|
|
53
|
+
return r && r(g), l && l(u, g), b;
|
|
55
54
|
}
|
|
56
55
|
});
|
|
57
56
|
}
|
|
58
|
-
function
|
|
57
|
+
function v(e) {
|
|
59
58
|
return e.replace(/^./, e[0].toUpperCase());
|
|
60
59
|
}
|
|
61
|
-
function
|
|
62
|
-
const o = e.msgBus, i = e.view,
|
|
63
|
-
let
|
|
60
|
+
function S(e, t) {
|
|
61
|
+
const o = e.msgBus, i = e.view, l = R((n) => typeof i == "function" ? i(n) : /* @__PURE__ */ React.createElement(React.Fragment, null, n.children));
|
|
62
|
+
let c = {
|
|
64
63
|
...e.props,
|
|
65
64
|
...e.methods,
|
|
66
65
|
// view: component.view,
|
|
67
66
|
// View: ViewerFC,
|
|
68
|
-
View:
|
|
67
|
+
View: l,
|
|
69
68
|
msgBus: o
|
|
70
69
|
};
|
|
71
70
|
if (e.children)
|
|
@@ -73,42 +72,42 @@ function F(e, t) {
|
|
|
73
72
|
if (typeof r == "function") {
|
|
74
73
|
const s = (h) => {
|
|
75
74
|
const f = r(h);
|
|
76
|
-
return /* @__PURE__ */
|
|
75
|
+
return /* @__PURE__ */ React.createElement(f.View, null);
|
|
77
76
|
};
|
|
78
|
-
Reflect.set(
|
|
77
|
+
Reflect.set(c, v(n), s);
|
|
79
78
|
} else
|
|
80
|
-
Reflect.set(
|
|
79
|
+
Reflect.set(c, n, r);
|
|
81
80
|
if (e.msgBroker) {
|
|
82
81
|
const n = e.msgBroker.provide;
|
|
83
82
|
if (n)
|
|
84
83
|
for (const [s, h] of Object.entries(n))
|
|
85
|
-
for (const [f,
|
|
84
|
+
for (const [f, d] of Object.entries(h))
|
|
86
85
|
o.provide({
|
|
87
|
-
...
|
|
86
|
+
...d,
|
|
88
87
|
channel: s,
|
|
89
88
|
group: f
|
|
90
89
|
});
|
|
91
90
|
const r = e.msgBroker.subscribe;
|
|
92
91
|
if (r)
|
|
93
92
|
for (const [s, h] of Object.entries(r))
|
|
94
|
-
for (const [f,
|
|
93
|
+
for (const [f, d] of Object.entries(h))
|
|
95
94
|
o.on({
|
|
96
|
-
...
|
|
95
|
+
...d,
|
|
97
96
|
channel: s,
|
|
98
97
|
group: f
|
|
99
98
|
});
|
|
100
99
|
}
|
|
101
|
-
const
|
|
100
|
+
const u = /* @__PURE__ */ new Map();
|
|
102
101
|
for (const [n, r] of Object.entries(t))
|
|
103
|
-
|
|
104
|
-
const
|
|
102
|
+
w(r) ? u.set(n, r) : Reflect.set(c, n, r);
|
|
103
|
+
const g = {};
|
|
105
104
|
if (e.props)
|
|
106
105
|
for (const n of Object.keys(e.props))
|
|
107
|
-
|
|
106
|
+
g[n] = P.ref;
|
|
108
107
|
if (e.methods)
|
|
109
108
|
for (const n of Object.keys(e.methods))
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
g[n] = !1;
|
|
110
|
+
g.View = !1, g.msgBus = !1;
|
|
112
111
|
const C = {
|
|
113
112
|
onPropChanging: t?.onPropChanging || e.events?.onPropChanging ? (n, r, s) => {
|
|
114
113
|
let h = !0, f = t.onPropChanging;
|
|
@@ -118,19 +117,19 @@ function F(e, t) {
|
|
|
118
117
|
t.onPropChange?.(String(n), r), e.events.onPropChange?.(String(n), r);
|
|
119
118
|
} : void 0
|
|
120
119
|
};
|
|
121
|
-
function
|
|
122
|
-
const r = `${
|
|
120
|
+
function a(n) {
|
|
121
|
+
const r = `${j}${v(n)}`;
|
|
123
122
|
return t[r] || e.events[r];
|
|
124
123
|
}
|
|
125
|
-
function
|
|
126
|
-
const r = `${
|
|
124
|
+
function y(n) {
|
|
125
|
+
const r = `${I}${v(n)}`;
|
|
127
126
|
return ((s, h) => {
|
|
128
|
-
let f = !0,
|
|
129
|
-
return
|
|
127
|
+
let f = !0, d = t[r];
|
|
128
|
+
return d && (f = d(s, h)), f && (d = e.events[r], d && (f = d(s, h))), f;
|
|
130
129
|
});
|
|
131
130
|
}
|
|
132
|
-
function
|
|
133
|
-
const r = `${
|
|
131
|
+
function b(n) {
|
|
132
|
+
const r = `${L}${v(n)}`;
|
|
134
133
|
return ((s) => {
|
|
135
134
|
t[r]?.(s), e.events[r]?.(s);
|
|
136
135
|
});
|
|
@@ -138,46 +137,46 @@ function F(e, t) {
|
|
|
138
137
|
if (e.props)
|
|
139
138
|
for (const n of Object.keys(e.props))
|
|
140
139
|
C[n] = {
|
|
141
|
-
onGet:
|
|
142
|
-
onChanging:
|
|
143
|
-
onChange:
|
|
140
|
+
onGet: a(n),
|
|
141
|
+
onChanging: y(n),
|
|
142
|
+
onChange: b(n)
|
|
144
143
|
};
|
|
145
|
-
return
|
|
144
|
+
return c = P(c, g), c = N(c, u, C), e.events?.onInit && e.events.onInit(c), t?.onInit && t.onInit(c), c;
|
|
146
145
|
}
|
|
147
|
-
function
|
|
148
|
-
const o =
|
|
149
|
-
return
|
|
146
|
+
function z(e, t) {
|
|
147
|
+
const o = G(() => S(e, t)), i = o.current;
|
|
148
|
+
return k(() => {
|
|
150
149
|
try {
|
|
151
150
|
e.events?.onLayout?.(i), t?.onLayout?.(i);
|
|
152
|
-
} catch (
|
|
153
|
-
e.events?.onError?.(i,
|
|
151
|
+
} catch (l) {
|
|
152
|
+
e.events?.onError?.(i, l), t?.onError?.(i, l);
|
|
154
153
|
}
|
|
155
154
|
return () => {
|
|
156
155
|
e.events?.onLayoutDestroy?.(i), t?.onLayoutDestroy?.(i), o.current = null;
|
|
157
156
|
};
|
|
158
|
-
}, []),
|
|
157
|
+
}, []), B(() => {
|
|
159
158
|
try {
|
|
160
159
|
e.events?.onReady?.(i), t?.onReady?.(i);
|
|
161
|
-
} catch (
|
|
162
|
-
e.events?.onError?.(i,
|
|
160
|
+
} catch (l) {
|
|
161
|
+
e.events?.onError?.(i, l), t?.onError?.(i, l);
|
|
163
162
|
}
|
|
164
163
|
return () => {
|
|
165
164
|
e.events?.onDestroy?.(i), t?.onDestroy?.(i);
|
|
166
165
|
};
|
|
167
166
|
}, []), o.current;
|
|
168
167
|
}
|
|
169
|
-
function
|
|
168
|
+
function H(e) {
|
|
170
169
|
return (o) => {
|
|
171
170
|
const i = e(o);
|
|
172
|
-
return /* @__PURE__ */
|
|
171
|
+
return /* @__PURE__ */ React.createElement(i.View, { ...o });
|
|
173
172
|
};
|
|
174
173
|
}
|
|
175
174
|
export {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
175
|
+
V as bind,
|
|
176
|
+
_ as bindProp,
|
|
177
|
+
H as getFC,
|
|
178
|
+
w as isBinding,
|
|
179
|
+
O as symbols,
|
|
180
|
+
z as useComponent
|
|
182
181
|
};
|
|
183
182
|
//# sourceMappingURL=componentModel.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"componentModel.es.js","sources":["../../src/componentModel/componentModel.tsx"],"sourcesContent":["import {\r\n AllHTMLAttributes,\r\n PropsWithChildren,\r\n useEffect,\r\n useLayoutEffect,\r\n useMemo,\r\n useRef,\r\n useState,\r\n FC,\r\n ReactNode,\r\n CSSProperties\r\n} from \"react\";\r\nimport { v4 as uuidv4 } from \"uuid\";\r\nimport { $CG_IN, $CG_OUT, MsgBus, MsgBusProviderParams, MsgBusStruct, MsgBusSubscriberParams } from \"@actdim/msgmesh/msgBusCore\";\r\nimport { MaybePromise, SafeKey, Skip } from \"@actdim/utico/typeCore\";\r\nimport { observer } from \"mobx-react-lite\";\r\nimport { observable, observe, runInAction } from \"mobx\";\r\nimport { useLazyRef } from \"@/reactHooks\";\r\n\r\nexport type MsgBusChannelGroupProviderParams<\r\n TStruct extends MsgBusStruct = MsgBusStruct,\r\n TChannel extends keyof TStruct = keyof TStruct,\r\n TGroup extends keyof TStruct[TChannel] = typeof $CG_IN // keyof TStruct[TChannel]\r\n> = Skip<MsgBusProviderParams<TStruct, TChannel, TGroup>, \"channel\" | \"group\">;\r\n\r\nexport type MsgBusChannelGroupSubscriberParams<\r\n TStruct extends MsgBusStruct = MsgBusStruct,\r\n TChannel extends keyof TStruct = keyof TStruct,\r\n TGroup extends keyof TStruct[TChannel] = typeof $CG_IN // keyof TStruct[TChannel]\r\n> = Skip<MsgBusSubscriberParams<TStruct, TChannel, TGroup>, \"channel\" | \"group\">;\r\n\r\n// MsgBusScope\r\nexport type MsgBusBrokerScope<\r\n TStruct extends MsgBusStruct /*= MsgBusStruct*/,\r\n TKeysToProvide extends keyof TStruct = keyof TStruct,\r\n TKeysToSubscribe extends keyof TStruct = keyof TStruct,\r\n TKeysToPublish extends keyof TStruct = keyof TStruct\r\n> = {\r\n provide?: TKeysToProvide;\r\n // consume\r\n subscribe?: TKeysToSubscribe;\r\n // produce\r\n publish?: TKeysToPublish;\r\n};\r\n\r\nexport type ComponentPropStruct = Record<string, any>;\r\n// export type ComponentPropStruct = {\r\n// [prop: string]: any;\r\n// };\r\n\r\nexport type ComponentMethodStruct = Record<string, Function>;\r\n// export type ComponentMethodStruct = {\r\n// [action: string]: Function;\r\n// };\r\n\r\n// export type ComponentRefStruct = Record<string, ComponentStruct<TMsgBusStruct, T>>;\r\nexport type ComponentRefStruct = {\r\n [name: string]: ComponentStruct | ((params: any) => ComponentStruct);\r\n};\r\n\r\nexport type ComponentStructBase<\r\n TMsgBusStruct extends MsgBusStruct = MsgBusStruct,\r\n TPropStruct extends ComponentPropStruct = ComponentPropStruct,\r\n TMsgScope extends MsgBusBrokerScope<TMsgBusStruct> = MsgBusBrokerScope<TMsgBusStruct>\r\n> = {\r\n props?: TPropStruct;\r\n methods?: ComponentMethodStruct;\r\n children?: ComponentRefStruct;\r\n msgScope?: TMsgScope;\r\n};\r\n\r\n// ComponentShape\r\nexport type ComponentStruct<\r\n TMsgBusStruct extends MsgBusStruct = MsgBusStruct,\r\n T extends ComponentStructBase<TMsgBusStruct> = ComponentStructBase<TMsgBusStruct>\r\n> = T & {\r\n msgBus: TMsgBusStruct;\r\n};\r\n\r\nexport type MsgBusBroker<TStructToProvide extends MsgBusStruct = MsgBusStruct, TStructToSubscribe extends MsgBusStruct = MsgBusStruct> = {\r\n // providers\r\n provide?: {\r\n [TChannel in keyof TStructToProvide]: {\r\n [TGroup in keyof Skip<TStructToProvide[TChannel], typeof $CG_OUT>]?: MsgBusChannelGroupProviderParams<\r\n TStructToProvide,\r\n TChannel,\r\n TGroup\r\n >;\r\n };\r\n };\r\n // subscribers\r\n subscribe?: {\r\n [TChannel in keyof TStructToSubscribe]: {\r\n [TGroup in keyof TStructToSubscribe[TChannel]]?: MsgBusChannelGroupSubscriberParams<TStructToSubscribe, TChannel, TGroup>;\r\n };\r\n };\r\n};\r\n\r\ntype ValueConverter<TTo, TFrom> = {\r\n // ConvertFrom\r\n convert(value: TFrom): TTo;\r\n // ConvertTo\r\n convertBack(value: TTo): TFrom;\r\n};\r\n\r\ntype ValidationResult = {\r\n valid: boolean;\r\n message: string;\r\n};\r\n\r\ntype Validator<T> = {\r\n options: {\r\n blur: boolean;\r\n };\r\n validate: (value: T) => MaybePromise<ValidationResult>;\r\n};\r\n\r\nexport const symbols = {\r\n $isBinding: Symbol(\"$isBinding\")\r\n};\r\n\r\nexport interface IBinding<T = any, TFrom = any> {\r\n // getter\r\n readonly get: () => T;\r\n // setter\r\n readonly set: (value: T) => void;\r\n readonly converter: ValueConverter<T, TFrom>;\r\n readonly validator: Validator<T>;\r\n readonly readOnly: boolean;\r\n [symbols.$isBinding]: boolean;\r\n}\r\n\r\nclass Binding<T = any, TFrom = any> implements IBinding<any, any> {\r\n // getter\r\n readonly get: () => T;\r\n // setter\r\n readonly set: (value: T) => void;\r\n readonly converter: ValueConverter<T, TFrom>;\r\n readonly validator: Validator<T>;\r\n readonly readOnly: boolean;\r\n constructor(get: () => T, set?: (value: T) => void, converter?: ValueConverter<T, TFrom>, validator?: Validator<T>) {\r\n this.get = get;\r\n this.set = set;\r\n this.converter = converter;\r\n this.validator = validator;\r\n this.readOnly = !!set;\r\n this[symbols.$isBinding] = true;\r\n }\r\n [symbols.$isBinding]: boolean;\r\n}\r\n\r\nexport function isBinding(obj: any): obj is IBinding {\r\n return obj[symbols.$isBinding] === true;\r\n}\r\n\r\nexport function bind<T, TFrom = any>(\r\n get: () => T,\r\n set?: (value: T) => void,\r\n converter?: ValueConverter<T, TFrom>,\r\n validator?: Validator<T>\r\n) {\r\n return new Binding(get, set, converter, validator);\r\n}\r\n\r\nexport function bindProp<T extends object, P extends keyof T>(obj: T, prop: P) {\r\n return new Binding(\r\n () => obj[prop],\r\n (value: T[P]) => {\r\n obj[prop] = value;\r\n }\r\n );\r\n}\r\n\r\nexport type ComponentPropSource<T> = T | Binding<T>;\r\n\r\nexport type ComponentPropParams<TPropStruct extends ComponentPropStruct> = {\r\n [P in keyof TPropStruct]?: ComponentPropSource<TPropStruct[P]>;\r\n};\r\n\r\n// const $ON_PROP_CHANGING = \"onPropChanging\";\r\n// const $ON_PROP_CHANGE = \"onPropChange\";\r\n\r\nconst $ON_GET = \"onGet\";\r\n// const $ON_BEFORE_SET = \"onBeforeSet\";\r\nconst $ON_CHANGING = \"onChanging\";\r\nconst $ON_CHANGE = \"onChange\";\r\n// const $ON_SET = \"onSet\";\r\n\r\ntype PropValueChangingHandler<TProp = PropKey> = (prop: TProp, oldValue: any, newValue: any) => boolean;\r\ntype PropValueChangeHandler<TProp = PropKey> = (prop: TProp, value: any) => void;\r\n\r\n// BeforeValueSetHandler\r\ntype ValueChangingHandler<T = any> = (oldValue: T, newValue: T) => boolean;\r\n// ValueSetHandler\r\ntype ValueChangeHandler<T = any> = (value: T) => void;\r\n\r\ntype ComponentEvents<TStruct extends ComponentStruct = ComponentStruct> = {\r\n onPropChanging?: PropValueChangingHandler<keyof TStruct[\"props\"]>;\r\n onPropChange?: PropValueChangeHandler<keyof TStruct[\"props\"]>;\r\n onInit?: (model: ComponentModel<TStruct>) => void;\r\n onLayout?: (model: ComponentModel<TStruct>) => void;\r\n onReady?: (model: ComponentModel<TStruct>) => void;\r\n onLayoutDestroy?: (model: ComponentModel<TStruct>) => void; // onLayoutCleanup\r\n onDestroy?: (model: ComponentModel<TStruct>) => void; // onDispose/onCleanup\r\n onError?: (model: ComponentModel<TStruct>, error: any) => void;\r\n} & {\r\n [P in keyof TStruct[\"props\"] as `${typeof $ON_GET}${Capitalize<P & string>}`]?: () => TStruct[\"props\"][P];\r\n} & {\r\n [P in keyof TStruct[\"props\"] as `${typeof $ON_CHANGING}${Capitalize<P & string>}`]?: ValueChangingHandler<TStruct[\"props\"]>;\r\n} & {\r\n [P in keyof TStruct[\"props\"] as `${typeof $ON_CHANGE}${Capitalize<P & string>}`]?: ValueChangeHandler<TStruct[\"props\"]>;\r\n};\r\n\r\n// AllHTMLAttributes<JSX.Element>\r\n\r\n// type ComponentViewerProps = {\r\n// render?: boolean;\r\n// view?: () => ReactNode;\r\n// } & PropsWithChildren;\r\n\r\ntype ComponentViewProps = {\r\n render?: boolean;\r\n} & PropsWithChildren;\r\n\r\ntype ComponentViewFn = (props?: ComponentViewProps) => ReactNode; // JSX.Element\r\n\r\ntype PublicKeys<T> = {\r\n [K in keyof T]: K extends `_${string}` ? never : K;\r\n}[keyof T];\r\n\r\nexport type Component<TStruct extends ComponentStruct> = {\r\n props?: TStruct[\"props\"];\r\n methods?: TStruct[\"methods\"];\r\n children?: ComponentChildren<TStruct[\"children\"]>;\r\n events?: ComponentEvents<TStruct>;\r\n // msgs?\r\n msgBroker?: MsgBusBroker<\r\n Pick<TStruct[\"msgBus\"], SafeKey<TStruct[\"msgBus\"], TStruct[\"msgScope\"][\"provide\"]>>,\r\n Pick<TStruct[\"msgBus\"], SafeKey<TStruct[\"msgBus\"], TStruct[\"msgScope\"][\"subscribe\"]>>\r\n >;\r\n msgBus?: MsgBus<\r\n // TStruct[\"msgBus\"]\r\n Pick<\r\n TStruct[\"msgBus\"],\r\n | SafeKey<TStruct[\"msgBus\"], TStruct[\"msgScope\"][\"provide\"]>\r\n | SafeKey<TStruct[\"msgBus\"], TStruct[\"msgScope\"][\"subscribe\"]>\r\n | SafeKey<TStruct[\"msgBus\"], TStruct[\"msgScope\"][\"publish\"]>\r\n >\r\n >;\r\n view?: ComponentViewFn;\r\n};\r\n\r\ntype ComponentChildren<TRefStruct extends ComponentRefStruct> = {\r\n [P in keyof TRefStruct]: TRefStruct[P] extends (params: infer TParams) => infer T\r\n ? T extends ComponentStruct\r\n ? (params: TParams) => ComponentModel<T>\r\n : never\r\n : TRefStruct[P] extends ComponentStruct\r\n ? ComponentModel<TRefStruct[P]>\r\n : never;\r\n};\r\n\r\ntype ComponentModelChildren<TRefStruct extends ComponentRefStruct> = {\r\n [P in keyof TRefStruct as TRefStruct[P] extends Function ? `${Capitalize<P & string>}` : P]: TRefStruct[P] extends (\r\n params: infer TParams\r\n ) => infer T\r\n ? T extends ComponentStruct\r\n ? FC<ComponentParams<T> & TParams>\r\n : never\r\n : TRefStruct[P] extends ComponentStruct\r\n ? ComponentModel<TRefStruct[P]>\r\n : never;\r\n};\r\n\r\nexport type ComponentModelBase<TStruct extends ComponentStruct = ComponentStruct> = {\r\n readonly msgBus?: MsgBus<\r\n // TStruct[\"msgBus\"]\r\n Pick<\r\n TStruct[\"msgBus\"],\r\n | SafeKey<TStruct[\"msgBus\"], TStruct[\"msgScope\"][\"provide\"]>\r\n | SafeKey<TStruct[\"msgBus\"], TStruct[\"msgScope\"][\"subscribe\"]>\r\n | SafeKey<TStruct[\"msgBus\"], TStruct[\"msgScope\"][\"publish\"]>\r\n >\r\n >;\r\n\r\n readonly View: ComponentViewFn;\r\n};\r\n\r\nexport type ComponentModel<TStruct extends ComponentStruct = ComponentStruct> = TStruct[\"props\"] &\r\n TStruct[\"methods\"] &\r\n ComponentModelChildren<TStruct[\"children\"]> &\r\n ComponentModelBase<TStruct>;\r\n\r\n// style: CSSProperties;\r\n\r\ntype PropEventHandlers = {\r\n onGet?: () => any;\r\n onChanging?: (oldValue: any, newValue: any) => boolean;\r\n onChange?: (value: any) => void;\r\n};\r\n\r\ntype PropKey = string | symbol;\r\ntype ProxyEventHandlers = {\r\n onPropChanging?: PropValueChangingHandler<PropKey>;\r\n onPropChange?: PropValueChangeHandler<PropKey>;\r\n} & Record<PropKey, PropEventHandlers>;\r\n\r\n// ComponentConfig\r\nexport type ComponentParams<TStruct extends ComponentStruct = ComponentStruct> = ComponentPropParams<TStruct[\"props\"]> &\r\n ComponentEvents<TStruct>; // & PropsWithChildren\r\n\r\nconst blankView = () => null;\r\n\r\nfunction createProxy(state: any, bindings: Map<PropKey, IBinding>, proxyEventHandlers: ProxyEventHandlers) {\r\n const onPropChanging = proxyEventHandlers.onPropChanging;\r\n const onPropChange = proxyEventHandlers.onPropChange;\r\n return new Proxy(state, {\r\n get(obj, prop, receiver) {\r\n const onGet = proxyEventHandlers[prop]?.onGet;\r\n if (onGet) {\r\n return onGet();\r\n }\r\n const binding = bindings.get(String(prop));\r\n if (binding) {\r\n return binding.get();\r\n }\r\n return Reflect.get(obj, prop, receiver);\r\n },\r\n set(obj, prop, value, receiver) {\r\n const oldValue = obj[prop];\r\n\r\n const onChanging = proxyEventHandlers[prop]?.onChanging;\r\n if (onChanging) {\r\n const shouldChange = onChanging(oldValue, value);\r\n if (!shouldChange) {\r\n return true;\r\n }\r\n }\r\n\r\n if (onPropChanging) {\r\n const shouldChange = onPropChanging(prop, oldValue, value);\r\n if (!shouldChange) {\r\n return true;\r\n }\r\n }\r\n\r\n const result = runInAction(() => {\r\n return Reflect.set(obj, prop, value, receiver);\r\n });\r\n\r\n const binding = bindings.get(prop);\r\n\r\n if (binding?.set) {\r\n binding.set(value);\r\n }\r\n\r\n const onChange = proxyEventHandlers[prop]?.onChange;\r\n if (onChange) {\r\n onChange(value);\r\n }\r\n\r\n if (onPropChange) {\r\n onPropChange(prop, value);\r\n }\r\n\r\n return result;\r\n }\r\n });\r\n}\r\n\r\nfunction capitalize(name: string) {\r\n return name.replace(/^./, name[0].toUpperCase());\r\n}\r\n\r\nfunction asyncToGeneratorFlow(asyncFn: (...args: any[]) => Promise<any>) {\r\n return function* (...args: any[]) {\r\n const result = yield asyncFn(...args);\r\n return result;\r\n };\r\n}\r\n\r\n// const ViewerFC = observer((props: ComponentViewerProps) => {\r\n// if (typeof props.view === \"function\") {\r\n// return props.view();\r\n// }\r\n// return <>{props.children}</>;\r\n// });\r\n\r\nfunction createModel<TStruct extends ComponentStruct = ComponentStruct>(\r\n component: Component<TStruct>,\r\n params: ComponentParams<TStruct>\r\n): ComponentModel<TStruct> {\r\n const msgBus = component.msgBus;\r\n const view = component.view;\r\n\r\n const ViewFC = observer((props: ComponentViewProps) => {\r\n if (typeof view === \"function\") {\r\n return view(props);\r\n }\r\n return <>{props.children}</>;\r\n });\r\n\r\n let model: ComponentModel<TStruct> = {\r\n ...component.props,\r\n ...component.methods,\r\n // view: component.view,\r\n // View: ViewerFC,\r\n View: ViewFC,\r\n msgBus: msgBus\r\n };\r\n if (component.children) {\r\n for (const [key, value] of Object.entries(component.children)) {\r\n if (typeof value == \"function\") {\r\n // observer\r\n const ChildViewFC: ComponentViewFn = (props) => {\r\n const model = value(props) as ComponentModel;\r\n return <model.View />;\r\n // if (typeof model.view === \"function\") {\r\n // return model.view(props);\r\n // }\r\n // return <>{props.children}</>;\r\n // return <ViewerFC view={model.view} />;\r\n };\r\n Reflect.set(model, capitalize(key), ChildViewFC);\r\n } else {\r\n Reflect.set(model, key, value);\r\n }\r\n }\r\n }\r\n if (component.msgBroker) {\r\n const providers = component.msgBroker.provide;\r\n if (providers) {\r\n for (const [channel, providerGroups] of Object.entries(providers)) {\r\n for (const [group, provider] of Object.entries(providerGroups)) {\r\n msgBus.provide({\r\n ...provider,\r\n channel: channel,\r\n group: group\r\n });\r\n }\r\n }\r\n }\r\n const subscribers = component.msgBroker.subscribe;\r\n if (subscribers) {\r\n for (const [channel, subscriberGroups] of Object.entries(subscribers)) {\r\n for (const [group, subscriber] of Object.entries(subscriberGroups)) {\r\n msgBus.on({\r\n ...subscriber,\r\n channel: channel,\r\n group: group\r\n });\r\n }\r\n }\r\n }\r\n }\r\n\r\n const bindings = new Map<PropKey, IBinding>();\r\n // Reflect.ownKeys\r\n for (const [key, value] of Object.entries(params)) {\r\n if (isBinding(value)) {\r\n bindings.set(key, value);\r\n } else {\r\n Reflect.set(model, key, value);\r\n }\r\n }\r\n\r\n // decorators\r\n const annotationMap: Record<string, any> = {};\r\n\r\n if (component.props) {\r\n for (const key of Object.keys(component.props)) {\r\n annotationMap[key] = observable.ref;\r\n }\r\n }\r\n if (component.methods) {\r\n for (const key of Object.keys(component.methods)) {\r\n annotationMap[key] = false;\r\n }\r\n }\r\n\r\n annotationMap[\"View\" satisfies keyof ComponentModelBase<TStruct>] = false;\r\n annotationMap[\"msgBus\" satisfies keyof ComponentModelBase<TStruct>] = false;\r\n // annotationMap[\"view\" satisfies keyof Component<TStruct>] = false;\r\n\r\n const proxyEventHandlers: Pick<ProxyEventHandlers, \"onPropChanging\" | \"onPropChange\"> = {\r\n onPropChanging:\r\n params?.onPropChanging || component.events?.onPropChanging\r\n ? (prop, oldValue, newValue) => {\r\n let result = true;\r\n let handler = params.onPropChanging;\r\n if (handler) {\r\n result = handler(String(prop), oldValue, newValue);\r\n }\r\n if (result) {\r\n handler = component.events?.onPropChanging;\r\n if (handler) {\r\n result = handler(String(prop), oldValue, newValue);\r\n }\r\n }\r\n return result;\r\n }\r\n : undefined,\r\n onPropChange:\r\n params?.onPropChange || component.events?.onPropChange\r\n ? (prop, value) => {\r\n params.onPropChange?.(String(prop), value);\r\n component.events.onPropChange?.(String(prop), value);\r\n }\r\n : undefined\r\n };\r\n\r\n function resolveOnGetEventHandler(prop: string) {\r\n const key = `${$ON_GET}${capitalize(prop)}`;\r\n return params[key] || component.events[key];\r\n }\r\n\r\n function resolveOnChangingEventHandler(prop: string) {\r\n const key = `${$ON_CHANGING}${capitalize(prop)}`;\r\n return ((oldValue: any, newValue: any) => {\r\n let result = true;\r\n let handler = params[key] as ValueChangingHandler<any>;\r\n if (handler) {\r\n result = handler(oldValue, newValue);\r\n }\r\n if (result) {\r\n handler = component.events[key] as ValueChangingHandler<any>;\r\n if (handler) {\r\n result = handler(oldValue, newValue);\r\n }\r\n }\r\n return result;\r\n }) as ValueChangingHandler;\r\n }\r\n\r\n function resolveOnChangeEventHandler(prop: string) {\r\n const key = `${$ON_CHANGE}${capitalize(prop)}`;\r\n return ((value: any) => {\r\n (params[key] as ValueChangeHandler<any>)?.(value);\r\n (component.events[key] as ValueChangeHandler<any>)?.(value);\r\n }) as ValueChangeHandler;\r\n }\r\n\r\n if (component.props) {\r\n for (const prop of Object.keys(component.props)) {\r\n proxyEventHandlers[prop] = {\r\n onGet: resolveOnGetEventHandler(prop),\r\n onChanging: resolveOnChangingEventHandler(prop),\r\n onChange: resolveOnChangeEventHandler(prop)\r\n };\r\n }\r\n }\r\n\r\n model = observable(model, annotationMap);\r\n\r\n model = createProxy(model, bindings, proxyEventHandlers);\r\n\r\n if (component.events?.onInit) {\r\n component.events.onInit(model);\r\n }\r\n\r\n if (params?.onInit) {\r\n params.onInit(model);\r\n }\r\n\r\n return model;\r\n}\r\n\r\nexport function useComponent<TStruct extends ComponentStruct = ComponentStruct>(\r\n component: Component<TStruct>,\r\n params: ComponentParams<TStruct>\r\n): ComponentModel<TStruct> {\r\n const ref = useLazyRef(() => createModel(component, params));\r\n const model = ref.current;\r\n\r\n useLayoutEffect(() => {\r\n try {\r\n component.events?.onLayout?.(model);\r\n params?.onLayout?.(model);\r\n } catch (err) {\r\n component.events?.onError?.(model, err);\r\n params?.onError?.(model, err);\r\n }\r\n\r\n return () => {\r\n component.events?.onLayoutDestroy?.(model);\r\n params?.onLayoutDestroy?.(model);\r\n // ref.current?.dispose();\r\n ref.current = null;\r\n };\r\n }, []);\r\n\r\n useEffect(() => {\r\n try {\r\n component.events?.onReady?.(model);\r\n params?.onReady?.(model);\r\n } catch (err) {\r\n component.events?.onError?.(model, err);\r\n params?.onError?.(model, err);\r\n }\r\n return () => {\r\n component.events?.onDestroy?.(model);\r\n params?.onDestroy?.(model);\r\n };\r\n }, []);\r\n\r\n return ref.current;\r\n}\r\n\r\n// asFC/toFC\r\nexport function getFC<TStruct extends ComponentStruct>(\r\n factory: (params: ComponentParams<TStruct>) => ComponentModel<TStruct>\r\n): FC<ComponentParams<TStruct>> {\r\n // observer\r\n const fc = (params: ComponentParams<TStruct> & PropsWithChildren) => {\r\n // modelHook\r\n const model = factory(params); // without useRef!\r\n // return model.view();\r\n return <model.View {...params} />;\r\n // return <ViewerFC {...params} view={model.view} />;\r\n };\r\n return fc;\r\n}\r\n"],"names":["symbols","Binding","get","set","converter","validator","isBinding","obj","bind","bindProp","prop","value","$ON_GET","$ON_CHANGING","$ON_CHANGE","createProxy","state","bindings","proxyEventHandlers","onPropChanging","onPropChange","receiver","onGet","binding","oldValue","onChanging","result","runInAction","onChange","capitalize","name","createModel","component","params","msgBus","view","ViewFC","observer","props","jsx","Fragment","model","key","ChildViewFC","providers","channel","providerGroups","group","provider","subscribers","subscriberGroups","subscriber","annotationMap","observable","newValue","handler","resolveOnGetEventHandler","resolveOnChangingEventHandler","resolveOnChangeEventHandler","useComponent","ref","useLazyRef","useLayoutEffect","err","useEffect","getFC","factory"],"mappings":";;;;;AAqHO,MAAMA,IAAU;AAAA,EACnB,YAAY,OAAO,YAAY;AACnC;AAaA,MAAMC,EAA4D;AAAA;AAAA,EAErD;AAAA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACT,YAAYC,GAAcC,GAA0BC,GAAsCC,GAA0B;AAChH,SAAK,MAAMH,GACX,KAAK,MAAMC,GACX,KAAK,YAAYC,GACjB,KAAK,YAAYC,GACjB,KAAK,WAAW,CAAC,CAACF,GAClB,KAAKH,EAAQ,UAAU,IAAI;AAAA,EAC/B;AAAA,EACA,CAACA,EAAQ,UAAU;AACvB;AAEO,SAASM,EAAUC,GAA2B;AACjD,SAAOA,EAAIP,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C,CAAM,CAAC,GACrDQ,IAAQmB,EAAI;AAElB,SAAAE,EAAgB,MAAM;AAClB,QAAI;AACA,MAAA9B,EAAU,QAAQ,WAAWS,CAAK,GAClCR,GAAQ,WAAWQ,CAAK;AAAA,IAC5B,SAASsB,GAAK;AACV,MAAA/B,EAAU,QAAQ,UAAUS,GAAOsB,CAAG,GACtC9B,GAAQ,UAAUQ,GAAOsB,CAAG;AAAA,IAChC;AAEA,WAAO,MAAM;AACT,MAAA/B,EAAU,QAAQ,kBAAkBS,CAAK,GACzCR,GAAQ,kBAAkBQ,CAAK,GAE/BmB,EAAI,UAAU;AAAA,IAClB;AAAA,EACJ,GAAG,CAAA,CAAE,GAELI,EAAU,MAAM;AACZ,QAAI;AACA,MAAAhC,EAAU,QAAQ,UAAUS,CAAK,GACjCR,GAAQ,UAAUQ,CAAK;AAAA,IAC3B,SAASsB,GAAK;AACV,MAAA/B,EAAU,QAAQ,UAAUS,GAAOsB,CAAG,GACtC9B,GAAQ,UAAUQ,GAAOsB,CAAG;AAAA,IAChC;AACA,WAAO,MAAM;AACT,MAAA/B,EAAU,QAAQ,YAAYS,CAAK,GACnCR,GAAQ,YAAYQ,CAAK;AAAA,IAC7B;AAAA,EACJ,GAAG,CAAA,CAAE,GAEEmB,EAAI;AACf;AAGO,SAASK,EACZC,GAC4B;AAS5B,SAPW,CAACjC,MAAyD;AAEjE,UAAMQ,IAAQyB,EAAQjC,CAAM;AAE5B,WAAO,gBAAAM,EAACE,EAAM,MAAN,EAAY,GAAGR,EAAA,CAAQ;AAAA,EAEnC;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"componentModel.es.js","sources":["../../src/componentModel/componentModel.tsx"],"sourcesContent":["import { PropsWithChildren, useEffect, useLayoutEffect, FC, ReactNode } from 'react';\r\nimport { v4 as uuidv4 } from 'uuid';\r\nimport {\r\n $CG_IN,\r\n $CG_OUT,\r\n MsgBus,\r\n MsgBusProviderParams,\r\n MsgBusStruct,\r\n MsgBusSubscriberParams,\r\n} from '@actdim/msgmesh/msgBusCore';\r\nimport { MaybePromise, SafeKey, Skip } from '@actdim/utico/typeCore';\r\nimport { observer } from 'mobx-react-lite';\r\nimport { observable, runInAction } from 'mobx';\r\nimport { useLazyRef } from '@/reactHooks';\r\n\r\nexport type MsgBusChannelGroupProviderParams<\r\n TStruct extends MsgBusStruct = MsgBusStruct,\r\n TChannel extends keyof TStruct = keyof TStruct,\r\n TGroup extends keyof TStruct[TChannel] = typeof $CG_IN, // keyof TStruct[TChannel]\r\n> = Skip<MsgBusProviderParams<TStruct, TChannel, TGroup>, 'channel' | 'group'>;\r\n\r\nexport type MsgBusChannelGroupSubscriberParams<\r\n TStruct extends MsgBusStruct = MsgBusStruct,\r\n TChannel extends keyof TStruct = keyof TStruct,\r\n TGroup extends keyof TStruct[TChannel] = typeof $CG_IN, // keyof TStruct[TChannel]\r\n> = Skip<MsgBusSubscriberParams<TStruct, TChannel, TGroup>, 'channel' | 'group'>;\r\n\r\n// MsgBusScope\r\nexport type MsgBusBrokerScope<\r\n TStruct extends MsgBusStruct /*= MsgBusStruct*/,\r\n TKeysToProvide extends keyof TStruct = keyof TStruct,\r\n TKeysToSubscribe extends keyof TStruct = keyof TStruct,\r\n TKeysToPublish extends keyof TStruct = keyof TStruct,\r\n> = {\r\n provide?: TKeysToProvide;\r\n // consume\r\n subscribe?: TKeysToSubscribe;\r\n // produce\r\n publish?: TKeysToPublish;\r\n};\r\n\r\nexport type ComponentPropStruct = Record<string, any>;\r\n// export type ComponentPropStruct = {\r\n// [prop: string]: any;\r\n// };\r\n\r\nexport type ComponentMethodStruct = Record<string, Function>;\r\n// export type ComponentMethodStruct = {\r\n// [action: string]: Function;\r\n// };\r\n\r\n// export type ComponentRefStruct = Record<string, ComponentStruct<TMsgBusStruct, T>>;\r\nexport type ComponentRefStruct = {\r\n [name: string]: ComponentStruct | ((params: any) => ComponentStruct);\r\n};\r\n\r\nexport type ComponentStructBase<\r\n TMsgBusStruct extends MsgBusStruct = MsgBusStruct,\r\n TPropStruct extends ComponentPropStruct = ComponentPropStruct,\r\n TMsgScope extends MsgBusBrokerScope<TMsgBusStruct> = MsgBusBrokerScope<TMsgBusStruct>,\r\n> = {\r\n props?: TPropStruct;\r\n methods?: ComponentMethodStruct;\r\n children?: ComponentRefStruct;\r\n msgScope?: TMsgScope;\r\n};\r\n\r\n// ComponentShape\r\nexport type ComponentStruct<\r\n TMsgBusStruct extends MsgBusStruct = MsgBusStruct,\r\n T extends ComponentStructBase<TMsgBusStruct> = ComponentStructBase<TMsgBusStruct>,\r\n> = T & {\r\n msgBus: TMsgBusStruct;\r\n};\r\n\r\nexport type MsgBusBroker<\r\n TStructToProvide extends MsgBusStruct = MsgBusStruct,\r\n TStructToSubscribe extends MsgBusStruct = MsgBusStruct,\r\n> = {\r\n // providers\r\n provide?: {\r\n [TChannel in keyof TStructToProvide]: {\r\n [TGroup in keyof Skip<\r\n TStructToProvide[TChannel],\r\n typeof $CG_OUT\r\n >]?: MsgBusChannelGroupProviderParams<TStructToProvide, TChannel, TGroup>;\r\n };\r\n };\r\n // subscribers\r\n subscribe?: {\r\n [TChannel in keyof TStructToSubscribe]: {\r\n [TGroup in keyof TStructToSubscribe[TChannel]]?: MsgBusChannelGroupSubscriberParams<\r\n TStructToSubscribe,\r\n TChannel,\r\n TGroup\r\n >;\r\n };\r\n };\r\n};\r\n\r\ntype ValueConverter<TTo, TFrom> = {\r\n // ConvertFrom\r\n convert(value: TFrom): TTo;\r\n // ConvertTo\r\n convertBack(value: TTo): TFrom;\r\n};\r\n\r\ntype ValidationResult = {\r\n valid: boolean;\r\n message: string;\r\n};\r\n\r\ntype Validator<T> = {\r\n options: {\r\n blur: boolean;\r\n };\r\n validate: (value: T) => MaybePromise<ValidationResult>;\r\n};\r\n\r\nexport const symbols = {\r\n $isBinding: Symbol('$isBinding'),\r\n};\r\n\r\nexport interface IBinding<T = any, TFrom = any> {\r\n // getter\r\n readonly get: () => T;\r\n // setter\r\n readonly set: (value: T) => void;\r\n readonly converter: ValueConverter<T, TFrom>;\r\n readonly validator: Validator<T>;\r\n readonly readOnly: boolean;\r\n [symbols.$isBinding]: boolean;\r\n}\r\n\r\nclass Binding<T = any, TFrom = any> implements IBinding<any, any> {\r\n // getter\r\n readonly get: () => T;\r\n // setter\r\n readonly set: (value: T) => void;\r\n readonly converter: ValueConverter<T, TFrom>;\r\n readonly validator: Validator<T>;\r\n readonly readOnly: boolean;\r\n constructor(\r\n get: () => T,\r\n set?: (value: T) => void,\r\n converter?: ValueConverter<T, TFrom>,\r\n validator?: Validator<T>\r\n ) {\r\n this.get = get;\r\n this.set = set;\r\n this.converter = converter;\r\n this.validator = validator;\r\n this.readOnly = !!set;\r\n this[symbols.$isBinding] = true;\r\n }\r\n [symbols.$isBinding]: boolean;\r\n}\r\n\r\nexport function isBinding(obj: any): obj is IBinding {\r\n return obj[symbols.$isBinding] === true;\r\n}\r\n\r\nexport function bind<T, TFrom = any>(\r\n get: () => T,\r\n set?: (value: T) => void,\r\n converter?: ValueConverter<T, TFrom>,\r\n validator?: Validator<T>\r\n) {\r\n return new Binding(get, set, converter, validator);\r\n}\r\n\r\nexport function bindProp<T extends object, P extends keyof T>(obj: T, prop: P) {\r\n return new Binding(\r\n () => obj[prop],\r\n (value: T[P]) => {\r\n obj[prop] = value;\r\n }\r\n );\r\n}\r\n\r\nexport type ComponentPropSource<T> = T | Binding<T>;\r\n\r\nexport type ComponentPropParams<TPropStruct extends ComponentPropStruct> = {\r\n [P in keyof TPropStruct]?: ComponentPropSource<TPropStruct[P]>;\r\n};\r\n\r\n// const $ON_PROP_CHANGING = \"onPropChanging\";\r\n// const $ON_PROP_CHANGE = \"onPropChange\";\r\n\r\nconst $ON_GET = 'onGet';\r\n// const $ON_BEFORE_SET = \"onBeforeSet\";\r\nconst $ON_CHANGING = 'onChanging';\r\nconst $ON_CHANGE = 'onChange';\r\n// const $ON_SET = \"onSet\";\r\n\r\ntype PropValueChangingHandler<TProp = PropKey> = (\r\n prop: TProp,\r\n oldValue: any,\r\n newValue: any\r\n) => boolean;\r\ntype PropValueChangeHandler<TProp = PropKey> = (prop: TProp, value: any) => void;\r\n\r\n// BeforeValueSetHandler\r\ntype ValueChangingHandler<T = any> = (oldValue: T, newValue: T) => boolean;\r\n// ValueSetHandler\r\ntype ValueChangeHandler<T = any> = (value: T) => void;\r\n\r\ntype ComponentEvents<TStruct extends ComponentStruct = ComponentStruct> = {\r\n onPropChanging?: PropValueChangingHandler<keyof TStruct['props']>;\r\n onPropChange?: PropValueChangeHandler<keyof TStruct['props']>;\r\n onInit?: (model: ComponentModel<TStruct>) => void;\r\n onLayout?: (model: ComponentModel<TStruct>) => void;\r\n onReady?: (model: ComponentModel<TStruct>) => void;\r\n onLayoutDestroy?: (model: ComponentModel<TStruct>) => void; // onLayoutCleanup\r\n onDestroy?: (model: ComponentModel<TStruct>) => void; // onDispose/onCleanup\r\n onError?: (model: ComponentModel<TStruct>, error: any) => void;\r\n} & {\r\n [P in keyof TStruct['props'] as `${typeof $ON_GET}${Capitalize<P & string>}`]?: () => TStruct['props'][P];\r\n} & {\r\n [P in keyof TStruct['props'] as `${typeof $ON_CHANGING}${Capitalize<P & string>}`]?: ValueChangingHandler<\r\n TStruct['props']\r\n >;\r\n} & {\r\n [P in keyof TStruct['props'] as `${typeof $ON_CHANGE}${Capitalize<P & string>}`]?: ValueChangeHandler<\r\n TStruct['props']\r\n >;\r\n};\r\n\r\n// AllHTMLAttributes<JSX.Element>\r\n\r\n// type ComponentViewerProps = {\r\n// render?: boolean;\r\n// view?: () => ReactNode;\r\n// } & PropsWithChildren;\r\n\r\ntype ComponentViewProps = {\r\n render?: boolean;\r\n} & PropsWithChildren;\r\n\r\ntype ComponentViewFn = (props?: ComponentViewProps) => ReactNode; // JSX.Element\r\n\r\ntype PublicKeys<T> = {\r\n [K in keyof T]: K extends `_${string}` ? never : K;\r\n}[keyof T];\r\n\r\nexport type Component<TStruct extends ComponentStruct> = {\r\n props?: TStruct['props'];\r\n methods?: TStruct['methods'];\r\n children?: ComponentChildren<TStruct['children']>;\r\n events?: ComponentEvents<TStruct>;\r\n // msgs?\r\n msgBroker?: MsgBusBroker<\r\n Pick<TStruct['msgBus'], SafeKey<TStruct['msgBus'], TStruct['msgScope']['provide']>>,\r\n Pick<TStruct['msgBus'], SafeKey<TStruct['msgBus'], TStruct['msgScope']['subscribe']>>\r\n >;\r\n msgBus?: MsgBus<\r\n // TStruct[\"msgBus\"]\r\n Pick<\r\n TStruct['msgBus'],\r\n | SafeKey<TStruct['msgBus'], TStruct['msgScope']['provide']>\r\n | SafeKey<TStruct['msgBus'], TStruct['msgScope']['subscribe']>\r\n | SafeKey<TStruct['msgBus'], TStruct['msgScope']['publish']>\r\n >\r\n >;\r\n view?: ComponentViewFn;\r\n};\r\n\r\ntype ComponentChildren<TRefStruct extends ComponentRefStruct> = {\r\n [P in keyof TRefStruct]: TRefStruct[P] extends (params: infer TParams) => infer T\r\n ? T extends ComponentStruct\r\n ? (params: TParams) => ComponentModel<T>\r\n : never\r\n : TRefStruct[P] extends ComponentStruct\r\n ? ComponentModel<TRefStruct[P]>\r\n : never;\r\n};\r\n\r\ntype ComponentModelChildren<TRefStruct extends ComponentRefStruct> = {\r\n [P in keyof TRefStruct as TRefStruct[P] extends Function\r\n ? `${Capitalize<P & string>}`\r\n : P]: TRefStruct[P] extends (params: infer TParams) => infer T\r\n ? T extends ComponentStruct\r\n ? FC<ComponentParams<T> & TParams>\r\n : never\r\n : TRefStruct[P] extends ComponentStruct\r\n ? ComponentModel<TRefStruct[P]>\r\n : never;\r\n};\r\n\r\nexport type ComponentModelBase<TStruct extends ComponentStruct = ComponentStruct> = {\r\n readonly msgBus?: MsgBus<\r\n // TStruct[\"msgBus\"]\r\n Pick<\r\n TStruct['msgBus'],\r\n | SafeKey<TStruct['msgBus'], TStruct['msgScope']['provide']>\r\n | SafeKey<TStruct['msgBus'], TStruct['msgScope']['subscribe']>\r\n | SafeKey<TStruct['msgBus'], TStruct['msgScope']['publish']>\r\n >\r\n >;\r\n\r\n readonly View: ComponentViewFn;\r\n};\r\n\r\nexport type ComponentModel<TStruct extends ComponentStruct = ComponentStruct> = TStruct['props'] &\r\n TStruct['methods'] &\r\n ComponentModelChildren<TStruct['children']> &\r\n ComponentModelBase<TStruct>;\r\n\r\n// style: CSSProperties;\r\n\r\ntype PropEventHandlers = {\r\n onGet?: () => any;\r\n onChanging?: (oldValue: any, newValue: any) => boolean;\r\n onChange?: (value: any) => void;\r\n};\r\n\r\ntype PropKey = string | symbol;\r\ntype ProxyEventHandlers = {\r\n onPropChanging?: PropValueChangingHandler<PropKey>;\r\n onPropChange?: PropValueChangeHandler<PropKey>;\r\n} & Record<PropKey, PropEventHandlers>;\r\n\r\n// ComponentConfig\r\nexport type ComponentParams<TStruct extends ComponentStruct = ComponentStruct> =\r\n ComponentPropParams<TStruct['props']> & ComponentEvents<TStruct>; // & PropsWithChildren\r\n\r\nconst blankView = () => null;\r\n\r\nfunction createProxy(\r\n state: any,\r\n bindings: Map<PropKey, IBinding>,\r\n proxyEventHandlers: ProxyEventHandlers\r\n) {\r\n const onPropChanging = proxyEventHandlers.onPropChanging;\r\n const onPropChange = proxyEventHandlers.onPropChange;\r\n return new Proxy(state, {\r\n get(obj, prop, receiver) {\r\n const onGet = proxyEventHandlers[prop]?.onGet;\r\n if (onGet) {\r\n return onGet();\r\n }\r\n const binding = bindings.get(String(prop));\r\n if (binding) {\r\n return binding.get();\r\n }\r\n return Reflect.get(obj, prop, receiver);\r\n },\r\n set(obj, prop, value, receiver) {\r\n const oldValue = obj[prop];\r\n\r\n const onChanging = proxyEventHandlers[prop]?.onChanging;\r\n if (onChanging) {\r\n const shouldChange = onChanging(oldValue, value);\r\n if (!shouldChange) {\r\n return true;\r\n }\r\n }\r\n\r\n if (onPropChanging) {\r\n const shouldChange = onPropChanging(prop, oldValue, value);\r\n if (!shouldChange) {\r\n return true;\r\n }\r\n }\r\n\r\n const result = runInAction(() => {\r\n return Reflect.set(obj, prop, value, receiver);\r\n });\r\n\r\n const binding = bindings.get(prop);\r\n\r\n if (binding?.set) {\r\n binding.set(value);\r\n }\r\n\r\n const onChange = proxyEventHandlers[prop]?.onChange;\r\n if (onChange) {\r\n onChange(value);\r\n }\r\n\r\n if (onPropChange) {\r\n onPropChange(prop, value);\r\n }\r\n\r\n return result;\r\n },\r\n });\r\n}\r\n\r\nfunction capitalize(name: string) {\r\n return name.replace(/^./, name[0].toUpperCase());\r\n}\r\n\r\nfunction asyncToGeneratorFlow(asyncFn: (...args: any[]) => Promise<any>) {\r\n return function* (...args: any[]) {\r\n const result = yield asyncFn(...args);\r\n return result;\r\n };\r\n}\r\n\r\n// const ViewerFC = observer((props: ComponentViewerProps) => {\r\n// if (typeof props.view === \"function\") {\r\n// return props.view();\r\n// }\r\n// return <>{props.children}</>;\r\n// });\r\n\r\nfunction createModel<TStruct extends ComponentStruct = ComponentStruct>(\r\n component: Component<TStruct>,\r\n params: ComponentParams<TStruct>\r\n): ComponentModel<TStruct> {\r\n const msgBus = component.msgBus;\r\n const view = component.view;\r\n\r\n const ViewFC = observer((props: ComponentViewProps) => {\r\n if (typeof view === 'function') {\r\n return view(props);\r\n }\r\n return <>{props.children}</>;\r\n });\r\n\r\n let model: ComponentModel<TStruct> = {\r\n ...component.props,\r\n ...component.methods,\r\n // view: component.view,\r\n // View: ViewerFC,\r\n View: ViewFC,\r\n msgBus: msgBus,\r\n };\r\n if (component.children) {\r\n for (const [key, value] of Object.entries(component.children)) {\r\n if (typeof value == 'function') {\r\n // observer\r\n const ChildViewFC: ComponentViewFn = (props) => {\r\n const model = value(props) as ComponentModel;\r\n return <model.View />;\r\n // if (typeof model.view === \"function\") {\r\n // return model.view(props);\r\n // }\r\n // return <>{props.children}</>;\r\n // return <ViewerFC view={model.view} />;\r\n };\r\n Reflect.set(model, capitalize(key), ChildViewFC);\r\n } else {\r\n Reflect.set(model, key, value);\r\n }\r\n }\r\n }\r\n if (component.msgBroker) {\r\n const providers = component.msgBroker.provide;\r\n if (providers) {\r\n for (const [channel, providerGroups] of Object.entries(providers)) {\r\n for (const [group, provider] of Object.entries(providerGroups)) {\r\n msgBus.provide({\r\n ...provider,\r\n channel: channel,\r\n group: group,\r\n });\r\n }\r\n }\r\n }\r\n const subscribers = component.msgBroker.subscribe;\r\n if (subscribers) {\r\n for (const [channel, subscriberGroups] of Object.entries(subscribers)) {\r\n for (const [group, subscriber] of Object.entries(subscriberGroups)) {\r\n msgBus.on({\r\n ...subscriber,\r\n channel: channel,\r\n group: group,\r\n });\r\n }\r\n }\r\n }\r\n }\r\n\r\n const bindings = new Map<PropKey, IBinding>();\r\n // Reflect.ownKeys\r\n for (const [key, value] of Object.entries(params)) {\r\n if (isBinding(value)) {\r\n bindings.set(key, value);\r\n } else {\r\n Reflect.set(model, key, value);\r\n }\r\n }\r\n\r\n // decorators\r\n const annotationMap: Record<string, any> = {};\r\n\r\n if (component.props) {\r\n for (const key of Object.keys(component.props)) {\r\n annotationMap[key] = observable.ref;\r\n }\r\n }\r\n if (component.methods) {\r\n for (const key of Object.keys(component.methods)) {\r\n annotationMap[key] = false;\r\n }\r\n }\r\n\r\n annotationMap['View' satisfies keyof ComponentModelBase<TStruct>] = false;\r\n annotationMap['msgBus' satisfies keyof ComponentModelBase<TStruct>] = false;\r\n // annotationMap[\"view\" satisfies keyof Component<TStruct>] = false;\r\n\r\n const proxyEventHandlers: Pick<ProxyEventHandlers, 'onPropChanging' | 'onPropChange'> = {\r\n onPropChanging:\r\n params?.onPropChanging || component.events?.onPropChanging\r\n ? (prop, oldValue, newValue) => {\r\n let result = true;\r\n let handler = params.onPropChanging;\r\n if (handler) {\r\n result = handler(String(prop), oldValue, newValue);\r\n }\r\n if (result) {\r\n handler = component.events?.onPropChanging;\r\n if (handler) {\r\n result = handler(String(prop), oldValue, newValue);\r\n }\r\n }\r\n return result;\r\n }\r\n : undefined,\r\n onPropChange:\r\n params?.onPropChange || component.events?.onPropChange\r\n ? (prop, value) => {\r\n params.onPropChange?.(String(prop), value);\r\n component.events.onPropChange?.(String(prop), value);\r\n }\r\n : undefined,\r\n };\r\n\r\n function resolveOnGetEventHandler(prop: string) {\r\n const key = `${$ON_GET}${capitalize(prop)}`;\r\n return params[key] || component.events[key];\r\n }\r\n\r\n function resolveOnChangingEventHandler(prop: string) {\r\n const key = `${$ON_CHANGING}${capitalize(prop)}`;\r\n return ((oldValue: any, newValue: any) => {\r\n let result = true;\r\n let handler = params[key] as ValueChangingHandler<any>;\r\n if (handler) {\r\n result = handler(oldValue, newValue);\r\n }\r\n if (result) {\r\n handler = component.events[key] as ValueChangingHandler<any>;\r\n if (handler) {\r\n result = handler(oldValue, newValue);\r\n }\r\n }\r\n return result;\r\n }) as ValueChangingHandler;\r\n }\r\n\r\n function resolveOnChangeEventHandler(prop: string) {\r\n const key = `${$ON_CHANGE}${capitalize(prop)}`;\r\n return ((value: any) => {\r\n (params[key] as ValueChangeHandler<any>)?.(value);\r\n (component.events[key] as ValueChangeHandler<any>)?.(value);\r\n }) as ValueChangeHandler;\r\n }\r\n\r\n if (component.props) {\r\n for (const prop of Object.keys(component.props)) {\r\n proxyEventHandlers[prop] = {\r\n onGet: resolveOnGetEventHandler(prop),\r\n onChanging: resolveOnChangingEventHandler(prop),\r\n onChange: resolveOnChangeEventHandler(prop),\r\n };\r\n }\r\n }\r\n\r\n model = observable(model, annotationMap);\r\n\r\n model = createProxy(model, bindings, proxyEventHandlers);\r\n\r\n if (component.events?.onInit) {\r\n component.events.onInit(model);\r\n }\r\n\r\n if (params?.onInit) {\r\n params.onInit(model);\r\n }\r\n\r\n return model;\r\n}\r\n\r\nexport function useComponent<TStruct extends ComponentStruct = ComponentStruct>(\r\n component: Component<TStruct>,\r\n params: ComponentParams<TStruct>\r\n): ComponentModel<TStruct> {\r\n const ref = useLazyRef(() => createModel(component, params));\r\n const model = ref.current;\r\n\r\n useLayoutEffect(() => {\r\n try {\r\n component.events?.onLayout?.(model);\r\n params?.onLayout?.(model);\r\n } catch (err) {\r\n component.events?.onError?.(model, err);\r\n params?.onError?.(model, err);\r\n }\r\n\r\n return () => {\r\n component.events?.onLayoutDestroy?.(model);\r\n params?.onLayoutDestroy?.(model);\r\n // ref.current?.dispose();\r\n ref.current = null;\r\n };\r\n }, []);\r\n\r\n useEffect(() => {\r\n try {\r\n component.events?.onReady?.(model);\r\n params?.onReady?.(model);\r\n } catch (err) {\r\n component.events?.onError?.(model, err);\r\n params?.onError?.(model, err);\r\n }\r\n return () => {\r\n component.events?.onDestroy?.(model);\r\n params?.onDestroy?.(model);\r\n };\r\n }, []);\r\n\r\n return ref.current;\r\n}\r\n\r\n// asFC/toFC\r\nexport function getFC<TStruct extends ComponentStruct>(\r\n factory: (params: ComponentParams<TStruct>) => ComponentModel<TStruct>\r\n): FC<ComponentParams<TStruct>> {\r\n // observer\r\n const fc = (params: ComponentParams<TStruct> & PropsWithChildren) => {\r\n // modelHook\r\n const model = factory(params); // without useRef!\r\n // return model.view();\r\n return <model.View {...params} />;\r\n // return <ViewerFC {...params} view={model.view} />;\r\n };\r\n return fc;\r\n}\r\n"],"names":["symbols","Binding","get","set","converter","validator","isBinding","obj","bind","bindProp","prop","value","$ON_GET","$ON_CHANGING","$ON_CHANGE","createProxy","state","bindings","proxyEventHandlers","onPropChanging","onPropChange","receiver","onGet","binding","oldValue","onChanging","result","runInAction","onChange","capitalize","name","createModel","component","params","msgBus","view","ViewFC","observer","props","model","key","ChildViewFC","providers","channel","providerGroups","group","provider","subscribers","subscriberGroups","subscriber","annotationMap","observable","newValue","handler","resolveOnGetEventHandler","resolveOnChangingEventHandler","resolveOnChangeEventHandler","useComponent","ref","useLazyRef","useLayoutEffect","err","useEffect","getFC","factory"],"mappings":";;;;AAuHO,MAAMA,IAAU;AAAA,EACnB,YAAY,OAAO,YAAY;AACnC;AAaA,MAAMC,EAA4D;AAAA;AAAA,EAErD;AAAA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACT,YACIC,GACAC,GACAC,GACAC,GACF;AACE,SAAK,M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ected registerDisposable(disposable: IDisposable): () => void;
|
|
27
27
|
dispose(): void;
|
|
28
28
|
}
|
|
29
|
-
export declare class DisposableModel extends DisposableComponent {
|
|
30
|
-
isBusy: boolean;
|
|
31
|
-
protected withBusyAsync<T>(asyncAction: () => Promise<T>): Promise<T>;
|
|
32
|
-
protected withBusy<T>(action: () => T): T;
|
|
33
|
-
}
|
|
34
29
|
//# sourceMappingURL=scope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../src/componentModel/scope.ts"],"names":[],"mappings":"AACA,OAAO,EAGH,MAAM,EACN,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAEhB,YAAY,EACZ,aAAa,EAEb,eAAe,EAClB,MAAM,MAAM,CAAC;AACd,OAAO,EAAe,SAAS,EAAE,MAAM,YAAY,CAAC;AAGpD,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,gBAAgB,GAAG;IAC9C,IAAI,EAAE,MAAM,CAAC,CAAC;IACd,MAAM,EAAE,CAAC,CAAC;CACb,CAAC;AAEF,MAAM,WAAW,WAAW;IACxB,OAAO,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,qBAAa,mBAAoB,YAAW,WAAW;IAEnD,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,SAAS,EAAE,CAAC;IAE3C,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC;IAEvB,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;;IAQnC,SAAS,CAAC,WAAW,CAAC,CAAC,GAAG,GAAG,EACzB,MAAM,EAAE,CAAC,EAET,QAAQ,EAAE,CAAC,MAAM,EAAE,gBAAgB,GAAG,YAAY,GAAG,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,IAAI,GACnG,SAAS;IAMZ,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC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E,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,eAAe,KAAK,IAAI,EACrD,IAAI,GAAE,gBAAgB,CAAC,CAAC,EAAE,OAAO,CAAa,EAC9C,gBAAgB,IAAI,GAAG,MAAM,IAAI,SAEhC,GACF,iBAAiB,EAAE;IAiBtB,SAAS,CAAC,kBAAkB,CAAC,GAAG,OAAO,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE;IAKvD,SAAS,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,IAAI,SAAJ,IAAI;IAK9C,SAAS,CAAC,kBAAkB,CAAC,UAAU,EAAE,WAAW,SALV,IAAI;IASvC,OAAO;CAoBjB"}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { deepObserve as
|
|
3
|
-
|
|
4
|
-
for (var s = void 0, t = o.length - 1, a; t >= 0; t--)
|
|
5
|
-
(a = o[t]) && (s = a(e, r, s) || s);
|
|
6
|
-
return s && p(e, r, s), s;
|
|
7
|
-
};
|
|
8
|
-
class v {
|
|
1
|
+
import { autorun as h, observe as o, reaction as l } from "mobx";
|
|
2
|
+
import { deepObserve as c } from "mobx-utils";
|
|
3
|
+
class z {
|
|
9
4
|
// finalizers
|
|
10
5
|
finalizers;
|
|
11
6
|
isDisposed;
|
|
@@ -14,16 +9,16 @@ class v {
|
|
|
14
9
|
this.isDisposed = !1, this.finalizers = [], this.handlers = /* @__PURE__ */ new Set();
|
|
15
10
|
}
|
|
16
11
|
deepObserve(e, r) {
|
|
17
|
-
const
|
|
18
|
-
return this.registerFinalizers(
|
|
12
|
+
const s = c(e, r);
|
|
13
|
+
return this.registerFinalizers(s), s;
|
|
19
14
|
}
|
|
20
15
|
autorun(e, r) {
|
|
21
|
-
const i = c(e, r);
|
|
22
|
-
return this.registerFinalizers(i), i;
|
|
23
|
-
}
|
|
24
|
-
observe(e, r, i = !0) {
|
|
25
16
|
const s = h(e, r);
|
|
26
|
-
return
|
|
17
|
+
return this.registerFinalizers(s), s;
|
|
18
|
+
}
|
|
19
|
+
observe(e, r, s = !0) {
|
|
20
|
+
const i = o(e, r);
|
|
21
|
+
return s && this.registerFinalizers(i), i;
|
|
27
22
|
}
|
|
28
23
|
async allHandlersAsync() {
|
|
29
24
|
await Promise.all(this.handlers);
|
|
@@ -32,38 +27,38 @@ class v {
|
|
|
32
27
|
if (this.isDisposed)
|
|
33
28
|
throw new Error("Cannot access a disposed object");
|
|
34
29
|
}
|
|
35
|
-
observeAsync(e, r,
|
|
30
|
+
observeAsync(e, r, s = !0, i = this.handlers) {
|
|
36
31
|
this.validateState();
|
|
37
|
-
const t =
|
|
32
|
+
const t = o(e, (a) => {
|
|
38
33
|
let n = null;
|
|
39
34
|
n = (async () => {
|
|
40
|
-
await r(a),
|
|
41
|
-
})(),
|
|
35
|
+
await r(a), i.delete(n);
|
|
36
|
+
})(), i.add(n);
|
|
42
37
|
});
|
|
43
|
-
return
|
|
38
|
+
return s && this.registerFinalizers(t), t;
|
|
44
39
|
}
|
|
45
|
-
multiObserve(e, r,
|
|
40
|
+
multiObserve(e, r, s, i = (t) => {
|
|
46
41
|
this.registerFinalizer(t);
|
|
47
42
|
}) {
|
|
48
43
|
const t = [];
|
|
49
44
|
for (const a of e) {
|
|
50
|
-
const n =
|
|
51
|
-
t.push(n),
|
|
45
|
+
const n = o(a, r, s);
|
|
46
|
+
t.push(n), i && i(n);
|
|
52
47
|
}
|
|
53
48
|
return t;
|
|
54
49
|
}
|
|
55
|
-
reaction(e, r,
|
|
56
|
-
const
|
|
57
|
-
return this.registerFinalizers(
|
|
50
|
+
reaction(e, r, s) {
|
|
51
|
+
const i = l(e, r, s);
|
|
52
|
+
return this.registerFinalizers(i), i;
|
|
58
53
|
}
|
|
59
|
-
multiReaction(e, r,
|
|
54
|
+
multiReaction(e, r, s = void 0, i = (t) => {
|
|
60
55
|
this.registerFinalizer(t);
|
|
61
56
|
}) {
|
|
62
57
|
const t = [];
|
|
63
|
-
|
|
58
|
+
s || (s = void 0);
|
|
64
59
|
for (const a of e) {
|
|
65
|
-
const n =
|
|
66
|
-
t.push(n),
|
|
60
|
+
const n = l(a, r, s);
|
|
61
|
+
t.push(n), i && i(n);
|
|
67
62
|
}
|
|
68
63
|
return t;
|
|
69
64
|
}
|
|
@@ -90,44 +85,7 @@ class v {
|
|
|
90
85
|
}
|
|
91
86
|
}
|
|
92
87
|
}
|
|
93
|
-
class z extends v {
|
|
94
|
-
isBusy = !0;
|
|
95
|
-
// isLoading
|
|
96
|
-
async withBusyAsync(e) {
|
|
97
|
-
l(() => {
|
|
98
|
-
this.isBusy = !0;
|
|
99
|
-
});
|
|
100
|
-
try {
|
|
101
|
-
return await e();
|
|
102
|
-
} finally {
|
|
103
|
-
l(() => {
|
|
104
|
-
this.isBusy = !1;
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
withBusy(e) {
|
|
109
|
-
l(() => {
|
|
110
|
-
this.isBusy = !0;
|
|
111
|
-
});
|
|
112
|
-
try {
|
|
113
|
-
return e();
|
|
114
|
-
} finally {
|
|
115
|
-
l(() => {
|
|
116
|
-
this.isBusy = !1;
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
// createViewModel = <T = any>(model: T, options?: IViewModelOptions<T>): T & IRootViewModel<T> => {
|
|
121
|
-
// const vm = createViewModel(model, options);
|
|
122
|
-
// this.registerFinalizer(vm.$().dispose);
|
|
123
|
-
// return vm;
|
|
124
|
-
// };
|
|
125
|
-
}
|
|
126
|
-
y([
|
|
127
|
-
f.ref
|
|
128
|
-
], z.prototype, "isBusy");
|
|
129
88
|
export {
|
|
130
|
-
|
|
131
|
-
z as DisposableModel
|
|
89
|
+
z as DisposableComponent
|
|
132
90
|
};
|
|
133
91
|
//# sourceMappingURL=scope.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.es.js","sources":["../../src/componentModel/scope.ts"],"sourcesContent":["// import { createViewModel } from \"@/componentModel\";\r\nimport {\r\n reaction,\r\n observe,\r\n Lambda,\r\n IReactionPublic,\r\n IReactionOptions,\r\n IReactionDisposer,\r\n IObjectDidChange,\r\n // IArrayChange,\r\n IArraySplice,\r\n IMapDidChange,\r\n autorun,\r\n IAutorunOptions\r\n} from \"mobx\";\r\nimport { deepObserve, IDisposer } from \"mobx-utils\";\r\nimport { observable, transaction } from \"mobx\";\r\n\r\nexport type IObjectChange<T> = IObjectDidChange & {\r\n name: keyof T;\r\n object: T;\r\n};\r\n\r\nexport interface IDisposable {\r\n dispose: () => void;\r\n}\r\n\r\nexport class DisposableComponent implements IDisposable {\r\n // finalizers\r\n protected readonly finalizers: IDisposer[];\r\n\r\n protected isDisposed: boolean;\r\n\r\n public handlers: Set<Promise<any>>;\r\n\r\n constructor() {\r\n this.isDisposed = false;\r\n this.finalizers = [];\r\n this.handlers = new Set<Promise<any>>();\r\n }\r\n\r\n protected deepObserve<T = any>(\r\n target: T,\r\n // | IArrayChange\r\n listener: (change: IObjectDidChange | IArraySplice | IMapDidChange, path: string, root: T) => void\r\n ): IDisposer {\r\n const releaser = deepObserve(target, listener);\r\n this.registerFinalizers(releaser);\r\n return releaser;\r\n }\r\n\r\n protected autorun(view: (r: IReactionPublic) => any, opts?: IAutorunOptions): IReactionDisposer {\r\n const releaser = autorun(view, opts);\r\n this.registerFinalizers(releaser);\r\n return releaser;\r\n }\r\n\r\n protected observe<T = Object>(object: T, listener: (change: IObjectChange<T>) => void, registerDisposer = true): Lambda {\r\n const releaser = observe(object, listener);\r\n if (registerDisposer) {\r\n this.registerFinalizers(releaser);\r\n }\r\n return releaser;\r\n }\r\n\r\n public async allHandlersAsync(): Promise<void> {\r\n await Promise.all(this.handlers);\r\n }\r\n\r\n protected validateState() {\r\n if (this.isDisposed) {\r\n throw new Error(\"Cannot access a disposed object\");\r\n }\r\n }\r\n \r\n protected observeAsync<T = Object>(\r\n object: T,\r\n listener: (change: IObjectChange<T>) => Promise<any>,\r\n registerDisposer = true,\r\n handlers = this.handlers\r\n ): Lambda {\r\n this.validateState(); \r\n const releaser = observe(object, (change) => {\r\n let task: Promise<any> = null;\r\n task = (async () => {\r\n await listener(change as IObjectChange<T>);\r\n handlers.delete(task);\r\n })();\r\n handlers.add(task);\r\n });\r\n if (registerDisposer) {\r\n this.registerFinalizers(releaser);\r\n }\r\n return releaser;\r\n }\r\n\r\n protected multiObserve(\r\n objects: Object[],\r\n listener: (change: IObjectDidChange) => void,\r\n fireImmediately?: boolean,\r\n registerDisposer = (d: () => void) => {\r\n this.registerFinalizer(d);\r\n }\r\n ): Lambda[] {\r\n const releasers: Lambda[] = [];\r\n for (const object of objects) {\r\n const releaser = observe(object, listener, fireImmediately);\r\n releasers.push(releaser);\r\n if (registerDisposer) {\r\n registerDisposer(releaser);\r\n }\r\n }\r\n return releasers;\r\n }\r\n\r\n protected reaction<T>(\r\n expression: (r: IReactionPublic) => T,\r\n effect: (arg: T, prev: T, r: IReactionPublic) => void,\r\n opts?: IReactionOptions<T, boolean>\r\n ): IReactionDisposer {\r\n const releaser = reaction(expression, effect, opts);\r\n this.registerFinalizers(releaser);\r\n return releaser;\r\n }\r\n\r\n protected multiReaction<T>(\r\n expressions: ((r: IReactionPublic) => T)[],\r\n effect: (arg: T, prev: T, r: IReactionPublic) => void,\r\n opts: IReactionOptions<T, boolean> = undefined,\r\n registerDisposer = (d: () => void) => {\r\n this.registerFinalizer(d);\r\n }\r\n ): IReactionDisposer[] {\r\n const releasers: IReactionDisposer[] = [];\r\n if (!opts) {\r\n opts = undefined;\r\n }\r\n for (const expression of expressions) {\r\n const releaser = reaction(expression, effect, opts);\r\n releasers.push(releaser);\r\n if (registerDisposer) {\r\n registerDisposer(releaser);\r\n }\r\n }\r\n\r\n return releasers;\r\n }\r\n\r\n // registerDisposers\r\n protected registerFinalizers(...actions: (() => void)[]) {\r\n this.finalizers.push(...actions);\r\n }\r\n\r\n // registerDisposer\r\n protected registerFinalizer(action: () => void) {\r\n this.registerFinalizers(action);\r\n return action;\r\n }\r\n\r\n protected registerDisposable(disposable: IDisposable) {\r\n return this.registerFinalizer(disposable.dispose.bind(disposable));\r\n }\r\n\r\n public dispose() {\r\n if (this === undefined) {\r\n console.error('undefined \"this\"');\r\n }\r\n if (!this.isDisposed) {\r\n for (const d of this.finalizers) {\r\n try {\r\n d && d();\r\n } catch (err) {\r\n throw err; // for debug\r\n }\r\n }\r\n this.finalizers.length = 0;\r\n // while (this.finalizers.length) {\r\n // const d = this.finalizers.pop();\r\n // d && d();\r\n // }\r\n this.isDisposed = true;\r\n }\r\n }\r\n}\r\n\r\nexport class DisposableModel extends DisposableComponent {\r\n @observable.ref\r\n public isBusy: boolean = true; // isLoading\r\n\r\n protected async withBusyAsync<T>(asyncAction: () => Promise<T>) {\r\n transaction(() => {\r\n this.isBusy = true;\r\n });\r\n try {\r\n return await asyncAction();\r\n } finally {\r\n transaction(() => {\r\n this.isBusy = false;\r\n });\r\n }\r\n }\r\n\r\n protected withBusy<T>(action: () => T) {\r\n transaction(() => {\r\n this.isBusy = true;\r\n });\r\n try {\r\n return action();\r\n } finally {\r\n transaction(() => {\r\n this.isBusy = false;\r\n });\r\n }\r\n }\r\n\r\n // createViewModel = <T = any>(model: T, options?: IViewModelOptions<T>): T & IRootViewModel<T> => {\r\n // const vm = createViewModel(model, options);\r\n // this.registerFinalizer(vm.$().dispose);\r\n // return vm;\r\n // };\r\n}\r\n"],"names":["DisposableComponent","target","listener","releaser","deepObserve","view","opts","autorun","object","registerDisposer","observe","handlers","change","task","objects","fireImmediately","d","releasers","expression","effect","reaction","expressions","actions","action","disposable","err","DisposableModel","asyncAction","transaction","__decorateClass","observable"],"mappings":";;;;;;;AA2BO,MAAMA,EAA2C;AAAA;AAAA,EAEjC;AAAA,EAET;AAAA,EAEH;AAAA,EAEP,cAAc;AACV,SAAK,aAAa,IAClB,KAAK,aAAa,CAAA,GAClB,KAAK,+BAAe,IAAA;AAAA,EACxB;AAAA,EAEU,YACNC,GAEAC,GACS;AACT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IACL;AAAA,EACJ;AAAA,EAEU,SAAYL,GAAiB;AACnC,IAAAK,EAAY,MAAM;AACd,WAAK,SAAS;AAAA,IAClB,CAAC;AACD,QAAI;AACA,aAAOL,EAAA;AAAA,IACX,UAAA;AACI,MAAAK,EAAY,MAAM;AACd,aAAK,SAAS;AAAA,MAClB,CAAC;AAAA,IACL;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAOJ;AAjCWC,EAAA;AAAA,EADNC,EAAW;AAAA,GADHJ,EAEF,WAAA,QAAA;"}
|
|
1
|
+
{"version":3,"file":"scope.es.js","sources":["../../src/componentModel/scope.ts"],"sourcesContent":["// import { createViewModel } from \"@/componentModel\";\r\nimport {\r\n reaction,\r\n observe,\r\n Lambda,\r\n IReactionPublic,\r\n IReactionOptions,\r\n IReactionDisposer,\r\n IObjectDidChange,\r\n // IArrayChange,\r\n IArraySplice,\r\n IMapDidChange,\r\n autorun,\r\n IAutorunOptions\r\n} from \"mobx\";\r\nimport { deepObserve, IDisposer } from \"mobx-utils\";\r\nimport { observable, transaction } from \"mobx\";\r\n\r\nexport type IObjectChange<T> = IObjectDidChange & {\r\n name: keyof T;\r\n object: T;\r\n};\r\n\r\nexport interface IDisposable {\r\n dispose: () => void;\r\n}\r\n\r\nexport class DisposableComponent implements IDisposable {\r\n // finalizers\r\n protected readonly finalizers: IDisposer[];\r\n\r\n protected isDisposed: boolean;\r\n\r\n public handlers: Set<Promise<any>>;\r\n\r\n constructor() {\r\n this.isDisposed = false;\r\n this.finalizers = [];\r\n this.handlers = new Set<Promise<any>>();\r\n }\r\n\r\n protected deepObserve<T = any>(\r\n target: T,\r\n // | IArrayChange\r\n listener: (change: IObjectDidChange | IArraySplice | IMapDidChange, path: string, root: T) => void\r\n ): IDisposer {\r\n const releaser = deepObserve(target, listener);\r\n this.registerFinalizers(releaser);\r\n return releaser;\r\n }\r\n\r\n protected autorun(view: (r: IReactionPublic) => any, opts?: IAutorunOptions): IReactionDisposer {\r\n const releaser = autorun(view, opts);\r\n this.registerFinalizers(releaser);\r\n return releaser;\r\n }\r\n\r\n protected observe<T = Object>(object: T, listener: (change: IObjectChange<T>) => void, registerDisposer = true): Lambda {\r\n const releaser = observe(object, listener);\r\n if (registerDisposer) {\r\n this.registerFinalizers(releaser);\r\n }\r\n return releaser;\r\n }\r\n\r\n public async allHandlersAsync(): Promise<void> {\r\n await Promise.all(this.handlers);\r\n }\r\n\r\n protected validateState() {\r\n if (this.isDisposed) {\r\n throw new Error(\"Cannot access a disposed object\");\r\n }\r\n }\r\n \r\n protected observeAsync<T = Object>(\r\n object: T,\r\n listener: (change: IObjectChange<T>) => Promise<any>,\r\n registerDisposer = true,\r\n handlers = this.handlers\r\n ): Lambda {\r\n this.validateState(); \r\n const releaser = observe(object, (change) => {\r\n let task: Promise<any> = null;\r\n task = (async () => {\r\n await listener(change as IObjectChange<T>);\r\n handlers.delete(task);\r\n })();\r\n handlers.add(task);\r\n });\r\n if (registerDisposer) {\r\n this.registerFinalizers(releaser);\r\n }\r\n return releaser;\r\n }\r\n\r\n protected multiObserve(\r\n objects: Object[],\r\n listener: (change: IObjectDidChange) => void,\r\n fireImmediately?: boolean,\r\n registerDisposer = (d: () => void) => {\r\n this.registerFinalizer(d);\r\n }\r\n ): Lambda[] {\r\n const releasers: Lambda[] = [];\r\n for (const object of objects) {\r\n const releaser = observe(object, listener, fireImmediately);\r\n releasers.push(releaser);\r\n if (registerDisposer) {\r\n registerDisposer(releaser);\r\n }\r\n }\r\n return releasers;\r\n }\r\n\r\n protected reaction<T>(\r\n expression: (r: IReactionPublic) => T,\r\n effect: (arg: T, prev: T, r: IReactionPublic) => void,\r\n opts?: IReactionOptions<T, boolean>\r\n ): IReactionDisposer {\r\n const releaser = reaction(expression, effect, opts);\r\n this.registerFinalizers(releaser);\r\n return releaser;\r\n }\r\n\r\n protected multiReaction<T>(\r\n expressions: ((r: IReactionPublic) => T)[],\r\n effect: (arg: T, prev: T, r: IReactionPublic) => void,\r\n opts: IReactionOptions<T, boolean> = undefined,\r\n registerDisposer = (d: () => void) => {\r\n this.registerFinalizer(d);\r\n }\r\n ): IReactionDisposer[] {\r\n const releasers: IReactionDisposer[] = [];\r\n if (!opts) {\r\n opts = undefined;\r\n }\r\n for (const expression of expressions) {\r\n const releaser = reaction(expression, effect, opts);\r\n releasers.push(releaser);\r\n if (registerDisposer) {\r\n registerDisposer(releaser);\r\n }\r\n }\r\n\r\n return releasers;\r\n }\r\n\r\n // registerDisposers\r\n protected registerFinalizers(...actions: (() => void)[]) {\r\n this.finalizers.push(...actions);\r\n }\r\n\r\n // registerDisposer\r\n protected registerFinalizer(action: () => void) {\r\n this.registerFinalizers(action);\r\n return action;\r\n }\r\n\r\n protected registerDisposable(disposable: IDisposable) {\r\n return this.registerFinalizer(disposable.dispose.bind(disposable));\r\n }\r\n\r\n public dispose() {\r\n if (this === undefined) {\r\n console.error('undefined \"this\"');\r\n }\r\n if (!this.isDisposed) {\r\n for (const d of this.finalizers) {\r\n try {\r\n d && d();\r\n } catch (err) {\r\n throw err; // for debug\r\n }\r\n }\r\n this.finalizers.length = 0;\r\n // while (this.finalizers.length) {\r\n // const d = this.finalizers.pop();\r\n // d && d();\r\n // }\r\n this.isDisposed = true;\r\n }\r\n }\r\n}\r\n\r\n// export class Model extends DisposableComponent {\r\n \r\n// public isBusy: boolean = true; // isLoading\r\n\r\n// protected async withBusyAsync<T>(asyncAction: () => Promise<T>) {\r\n// transaction(() => {\r\n// this.isBusy = true;\r\n// });\r\n// try {\r\n// return await asyncAction();\r\n// } finally {\r\n// transaction(() => {\r\n// this.isBusy = false;\r\n// });\r\n// }\r\n// }\r\n\r\n// protected withBusy<T>(action: () => T) {\r\n// transaction(() => {\r\n// this.isBusy = true;\r\n// });\r\n// try {\r\n// return action();\r\n// } finally {\r\n// transaction(() => {\r\n// this.isBusy = false;\r\n// });\r\n// }\r\n// }\r\n// }\r\n"],"names":["DisposableComponent","target","listener","releaser","deepObserve","view","opts","autorun","object","registerDisposer","observe","handlers","change","task","objects","fireImmediately","d","releasers","expression","effect","reaction","expressions","actions","action","disposable","err"],"mappings":";;AA2BO,MAAMA,EAA2C;AAAA;AAAA,EAEjC;AAAA,EAET;AAAA,EAEH;AAAA,EAEP,cAAc;AACV,SAAK,aAAa,IAClB,KAAK,aAAa,CAAA,GAClB,KAAK,+BAAe,IAAA;AAAA,EACxB;AAAA,EAEU,YACNC,GAEAC,GACS;AACT,UAAMC,IAAWC,EAAYH,GAAQC,CAAQ;AAC7C,gBAAK,mBAAmBC,CAAQ,GACzBA;AAAA,EACX;AAAA,EAEU,QAAQE,GAAmCC,GAA2C;AAC5F,UAAMH,IAAWI,EAAQF,GAAMC,CAAI;AACnC,gBAAK,mBAAmBH,CAAQ,GACzBA;AAAA,EACX;AAAA,EAEU,QAAoBK,GAAWN,GAA8CO,IAAmB,IAAc;AACpH,UAAMN,IAAWO,EAAQF,GAAQN,CAAQ;AACzC,WAAIO,KACA,KAAK,mBAAmBN,CAAQ,GAE7BA;AAAA,EACX;AAAA,EAEA,MAAa,mBAAkC;AAC3C,UAAM,QAAQ,IAAI,KAAK,QAAQ;AAAA,EACnC;AAAA,EAEU,gBAAgB;AACtB,QAAI,KAAK;AACL,YAAM,IAAI,MAAM,iCAAiC;AAAA,EAEzD;AAAA,EAEU,aACNK,GACAN,GACAO,IAAmB,IACnBE,IAAW,KAAK,UACV;AACN,SAAK,cAAA;AACL,UAAMR,IAAWO,EAAQF,GAAQ,CAACI,MAAW;AACzC,UAAIC,IAAqB;AACzB,MAAAA,KAAQ,YAAY;AAChB,cAAMX,EAASU,CAA0B,GACzCD,EAAS,OAAOE,CAAI;AAAA,MACxB,GAAA,GACAF,EAAS,IAAIE,CAAI;AAAA,IACrB,CAAC;AACD,WAAIJ,KACA,KAAK,mBAAmBN,CAAQ,GAE7BA;AAAA,EACX;AAAA,EAEU,aACNW,GACAZ,GACAa,GACAN,IAAmB,CAACO,MAAkB;AAClC,SAAK,kBAAkBA,CAAC;AAAA,EAC5B,GAC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