phecda-core 3.0.0-alpha.10 → 3.0.0-alpha.12
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/dist/index.d.ts +55 -52
- package/dist/index.js +260 -204
- package/dist/index.mjs +251 -197
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,18 +2,19 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/core.ts
|
|
5
|
+
var SHARE_KEY = Symbol("phecda");
|
|
6
|
+
var PHECDA_KEY = Symbol("phecda");
|
|
5
7
|
function isPhecda(module) {
|
|
6
8
|
if (typeof module === "function")
|
|
7
|
-
return !!module.prototype?.
|
|
9
|
+
return !!module.prototype?.[PHECDA_KEY];
|
|
8
10
|
return false;
|
|
9
11
|
}
|
|
10
12
|
__name(isPhecda, "isPhecda");
|
|
11
|
-
var SHARE_KEY = Symbol("phecda-core");
|
|
12
13
|
function init(proto) {
|
|
13
14
|
if (!proto)
|
|
14
15
|
return;
|
|
15
|
-
if (!proto.hasOwnProperty(
|
|
16
|
-
proto
|
|
16
|
+
if (!proto.hasOwnProperty(PHECDA_KEY)) {
|
|
17
|
+
proto[PHECDA_KEY] = {
|
|
17
18
|
__EXPOSE_VAR__: /* @__PURE__ */ new Set(),
|
|
18
19
|
__IGNORE_VAR__: /* @__PURE__ */ new Set(),
|
|
19
20
|
__STATE_VAR__: /* @__PURE__ */ new Set(),
|
|
@@ -23,55 +24,79 @@ function init(proto) {
|
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
__name(init, "init");
|
|
26
|
-
function
|
|
27
|
+
function getPhecdaFromTarget(target) {
|
|
28
|
+
if (typeof target === "function")
|
|
29
|
+
return target.prototype;
|
|
30
|
+
if (target.hasOwnProperty(PHECDA_KEY))
|
|
31
|
+
return target;
|
|
32
|
+
return Object.getPrototypeOf(target);
|
|
33
|
+
}
|
|
34
|
+
__name(getPhecdaFromTarget, "getPhecdaFromTarget");
|
|
35
|
+
function setStateVar(proto, key) {
|
|
27
36
|
init(proto);
|
|
28
|
-
proto.
|
|
37
|
+
proto[PHECDA_KEY].__STATE_VAR__.add(key);
|
|
29
38
|
setExposeKey(proto, key);
|
|
30
39
|
}
|
|
31
|
-
__name(
|
|
40
|
+
__name(setStateVar, "setStateVar");
|
|
32
41
|
function setExposeKey(proto, key) {
|
|
33
42
|
init(proto);
|
|
34
|
-
proto.
|
|
43
|
+
proto[PHECDA_KEY].__EXPOSE_VAR__.add(key);
|
|
35
44
|
}
|
|
36
45
|
__name(setExposeKey, "setExposeKey");
|
|
37
46
|
function setIgnoreKey(proto, key) {
|
|
38
47
|
init(proto);
|
|
39
|
-
proto.
|
|
48
|
+
proto[PHECDA_KEY].__IGNORE_VAR__.add(key);
|
|
40
49
|
}
|
|
41
50
|
__name(setIgnoreKey, "setIgnoreKey");
|
|
42
|
-
function
|
|
43
|
-
|
|
51
|
+
function setHandler(proto, key, handler) {
|
|
52
|
+
init(proto);
|
|
53
|
+
if (!proto[PHECDA_KEY].__STATE_HANDLER__.has(key))
|
|
54
|
+
proto[PHECDA_KEY].__STATE_HANDLER__.set(key, [
|
|
55
|
+
handler
|
|
56
|
+
]);
|
|
57
|
+
else
|
|
58
|
+
proto[PHECDA_KEY].__STATE_HANDLER__.get(key).push(handler);
|
|
59
|
+
}
|
|
60
|
+
__name(setHandler, "setHandler");
|
|
61
|
+
function setState(proto, key, state) {
|
|
62
|
+
init(proto);
|
|
63
|
+
const namespace = proto[PHECDA_KEY].__STATE_NAMESPACE__;
|
|
64
|
+
namespace.set(key, state);
|
|
65
|
+
}
|
|
66
|
+
__name(setState, "setState");
|
|
67
|
+
function getOwnStateVars(target) {
|
|
68
|
+
const proto = getPhecdaFromTarget(target);
|
|
44
69
|
return [
|
|
45
|
-
...
|
|
70
|
+
...proto[PHECDA_KEY].__STATE_VAR__
|
|
46
71
|
];
|
|
47
72
|
}
|
|
48
|
-
__name(
|
|
49
|
-
function
|
|
50
|
-
let proto =
|
|
73
|
+
__name(getOwnStateVars, "getOwnStateVars");
|
|
74
|
+
function getStateVars(target) {
|
|
75
|
+
let proto = getPhecdaFromTarget(target);
|
|
51
76
|
const set = /* @__PURE__ */ new Set();
|
|
52
|
-
while (proto?.
|
|
53
|
-
proto.
|
|
77
|
+
while (proto?.[PHECDA_KEY]) {
|
|
78
|
+
proto[PHECDA_KEY].__STATE_VAR__.forEach((item) => set.add(item));
|
|
54
79
|
proto = Object.getPrototypeOf(proto);
|
|
55
80
|
}
|
|
56
81
|
return [
|
|
57
82
|
...set
|
|
58
83
|
];
|
|
59
84
|
}
|
|
60
|
-
__name(
|
|
61
|
-
function getOwnExposeKey(
|
|
62
|
-
|
|
85
|
+
__name(getStateVars, "getStateVars");
|
|
86
|
+
function getOwnExposeKey(target) {
|
|
87
|
+
const proto = getPhecdaFromTarget(target);
|
|
63
88
|
return [
|
|
64
|
-
...
|
|
65
|
-
].filter((item) => !
|
|
89
|
+
...proto[PHECDA_KEY].__EXPOSE_VAR__
|
|
90
|
+
].filter((item) => !proto[PHECDA_KEY].__IGNORE_VAR__.has(item));
|
|
66
91
|
}
|
|
67
92
|
__name(getOwnExposeKey, "getOwnExposeKey");
|
|
68
|
-
function getExposeKey(
|
|
69
|
-
let proto =
|
|
93
|
+
function getExposeKey(target) {
|
|
94
|
+
let proto = getPhecdaFromTarget(target);
|
|
70
95
|
const set = /* @__PURE__ */ new Set();
|
|
71
|
-
while (proto?.
|
|
96
|
+
while (proto?.[PHECDA_KEY]) {
|
|
72
97
|
[
|
|
73
|
-
...proto.
|
|
74
|
-
].forEach((item) => !proto.
|
|
98
|
+
...proto[PHECDA_KEY].__EXPOSE_VAR__
|
|
99
|
+
].forEach((item) => !proto[PHECDA_KEY].__IGNORE_VAR__.has(item) && set.add(item));
|
|
75
100
|
proto = Object.getPrototypeOf(proto);
|
|
76
101
|
}
|
|
77
102
|
return [
|
|
@@ -79,35 +104,27 @@ function getExposeKey(instance) {
|
|
|
79
104
|
];
|
|
80
105
|
}
|
|
81
106
|
__name(getExposeKey, "getExposeKey");
|
|
82
|
-
function getOwnIgnoreKey(
|
|
83
|
-
|
|
107
|
+
function getOwnIgnoreKey(target) {
|
|
108
|
+
const proto = getPhecdaFromTarget(target);
|
|
109
|
+
if (!proto?.[PHECDA_KEY])
|
|
84
110
|
return [];
|
|
85
111
|
return [
|
|
86
|
-
...
|
|
112
|
+
...proto[PHECDA_KEY].__IGNORE_VAR__
|
|
87
113
|
];
|
|
88
114
|
}
|
|
89
115
|
__name(getOwnIgnoreKey, "getOwnIgnoreKey");
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
if (!proto
|
|
93
|
-
proto._namespace.__STATE_HANDLER__.set(key, [
|
|
94
|
-
handler
|
|
95
|
-
]);
|
|
96
|
-
else
|
|
97
|
-
proto._namespace.__STATE_HANDLER__.get(key).push(handler);
|
|
98
|
-
}
|
|
99
|
-
__name(regisHandler, "regisHandler");
|
|
100
|
-
function getOwnHandler(instance, key) {
|
|
101
|
-
if (!instance?._namespace)
|
|
116
|
+
function getOwnHandler(target, key) {
|
|
117
|
+
const proto = getPhecdaFromTarget(target);
|
|
118
|
+
if (!proto?.[PHECDA_KEY])
|
|
102
119
|
return [];
|
|
103
|
-
return
|
|
120
|
+
return proto[PHECDA_KEY].__STATE_HANDLER__.get(key) || [];
|
|
104
121
|
}
|
|
105
122
|
__name(getOwnHandler, "getOwnHandler");
|
|
106
|
-
function getHandler(
|
|
107
|
-
let proto =
|
|
123
|
+
function getHandler(target, key) {
|
|
124
|
+
let proto = getPhecdaFromTarget(target);
|
|
108
125
|
const set = /* @__PURE__ */ new Set();
|
|
109
|
-
while (proto?.
|
|
110
|
-
proto.
|
|
126
|
+
while (proto?.[PHECDA_KEY]) {
|
|
127
|
+
proto[PHECDA_KEY].__STATE_HANDLER__.get(key)?.forEach((item) => set.add(item));
|
|
111
128
|
proto = Object.getPrototypeOf(proto);
|
|
112
129
|
}
|
|
113
130
|
return [
|
|
@@ -115,22 +132,11 @@ function getHandler(instance, key) {
|
|
|
115
132
|
];
|
|
116
133
|
}
|
|
117
134
|
__name(getHandler, "getHandler");
|
|
118
|
-
function
|
|
119
|
-
|
|
120
|
-
const namespace = proto._namespace.__STATE_NAMESPACE__;
|
|
121
|
-
namespace.set(key, state);
|
|
122
|
-
}
|
|
123
|
-
__name(setState, "setState");
|
|
124
|
-
function getOwnState(instance, key) {
|
|
125
|
-
instance = Object.getPrototypeOf(instance);
|
|
126
|
-
return instance._namespace.__STATE_NAMESPACE__.get(key) || {};
|
|
127
|
-
}
|
|
128
|
-
__name(getOwnState, "getOwnState");
|
|
129
|
-
function getState(instance, key) {
|
|
130
|
-
let proto = Object.getPrototypeOf(instance);
|
|
135
|
+
function getState(target, key) {
|
|
136
|
+
let proto = getPhecdaFromTarget(target);
|
|
131
137
|
let ret = {};
|
|
132
|
-
while (proto?.
|
|
133
|
-
const state = proto.
|
|
138
|
+
while (proto?.[PHECDA_KEY]) {
|
|
139
|
+
const state = proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key);
|
|
134
140
|
if (state)
|
|
135
141
|
ret = {
|
|
136
142
|
...state,
|
|
@@ -141,6 +147,11 @@ function getState(instance, key) {
|
|
|
141
147
|
return ret;
|
|
142
148
|
}
|
|
143
149
|
__name(getState, "getState");
|
|
150
|
+
function getOwnState(target, key) {
|
|
151
|
+
const proto = getPhecdaFromTarget(target);
|
|
152
|
+
return proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key) || {};
|
|
153
|
+
}
|
|
154
|
+
__name(getOwnState, "getOwnState");
|
|
144
155
|
function invokeHandler(event, instance) {
|
|
145
156
|
const stateVars = getExposeKey(instance);
|
|
146
157
|
const initHandlers = stateVars.map((item) => {
|
|
@@ -150,16 +161,66 @@ function invokeHandler(event, instance) {
|
|
|
150
161
|
}
|
|
151
162
|
__name(invokeHandler, "invokeHandler");
|
|
152
163
|
|
|
164
|
+
// src/decorators/core.ts
|
|
165
|
+
function Init(proto, key) {
|
|
166
|
+
setStateVar(proto, key);
|
|
167
|
+
setHandler(proto, key, {
|
|
168
|
+
async init(instance) {
|
|
169
|
+
return instance[key]();
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
__name(Init, "Init");
|
|
174
|
+
function Unmount(proto, key) {
|
|
175
|
+
setStateVar(proto, key);
|
|
176
|
+
setHandler(proto, key, {
|
|
177
|
+
async unmount(instance) {
|
|
178
|
+
return instance[key]();
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
__name(Unmount, "Unmount");
|
|
183
|
+
function Bind(value) {
|
|
184
|
+
return (proto, k) => {
|
|
185
|
+
setStateVar(proto, k);
|
|
186
|
+
setState(proto, k, {
|
|
187
|
+
value
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
__name(Bind, "Bind");
|
|
192
|
+
function Ignore(proto, key) {
|
|
193
|
+
setIgnoreKey(proto, key);
|
|
194
|
+
}
|
|
195
|
+
__name(Ignore, "Ignore");
|
|
196
|
+
function Clear(proto, key) {
|
|
197
|
+
init(proto);
|
|
198
|
+
proto[PHECDA_KEY].__EXPOSE_VAR__.delete(key);
|
|
199
|
+
proto[PHECDA_KEY].__IGNORE_VAR__.delete(key);
|
|
200
|
+
proto[PHECDA_KEY].__STATE_VAR__.delete(key);
|
|
201
|
+
proto[PHECDA_KEY].__STATE_HANDLER__.delete(key);
|
|
202
|
+
proto[PHECDA_KEY].__STATE_NAMESPACE__.delete(key);
|
|
203
|
+
}
|
|
204
|
+
__name(Clear, "Clear");
|
|
205
|
+
function Expose(proto, key) {
|
|
206
|
+
setExposeKey(proto, key);
|
|
207
|
+
}
|
|
208
|
+
__name(Expose, "Expose");
|
|
209
|
+
function Empty(module) {
|
|
210
|
+
init(module.prototype);
|
|
211
|
+
}
|
|
212
|
+
__name(Empty, "Empty");
|
|
213
|
+
|
|
153
214
|
// src/helper.ts
|
|
154
|
-
function
|
|
215
|
+
function getTag(moduleOrInstance) {
|
|
155
216
|
if (typeof moduleOrInstance === "object")
|
|
156
217
|
moduleOrInstance = moduleOrInstance.constructor;
|
|
157
218
|
return moduleOrInstance.prototype?.__TAG__ || moduleOrInstance.name;
|
|
158
219
|
}
|
|
159
|
-
__name(
|
|
220
|
+
__name(getTag, "getTag");
|
|
160
221
|
function getBind(module) {
|
|
161
222
|
const instance = new module();
|
|
162
|
-
const keys =
|
|
223
|
+
const keys = getStateVars(instance);
|
|
163
224
|
const ret = {};
|
|
164
225
|
for (const item of keys) {
|
|
165
226
|
const state = getState(instance, item);
|
|
@@ -179,12 +240,14 @@ function plainToClass(module, input) {
|
|
|
179
240
|
__name(plainToClass, "plainToClass");
|
|
180
241
|
async function transformClass(instance, force = false) {
|
|
181
242
|
const err = [];
|
|
182
|
-
const
|
|
183
|
-
for (const item of
|
|
243
|
+
const keys = getExposeKey(instance);
|
|
244
|
+
for (const item of keys) {
|
|
184
245
|
const handlers = getHandler(instance, item);
|
|
185
246
|
if (handlers) {
|
|
186
247
|
for (const handler of handlers) {
|
|
187
248
|
const pipe = handler.pipe;
|
|
249
|
+
if (!pipe)
|
|
250
|
+
continue;
|
|
188
251
|
try {
|
|
189
252
|
await pipe(instance);
|
|
190
253
|
} catch (e) {
|
|
@@ -198,14 +261,34 @@ async function transformClass(instance, force = false) {
|
|
|
198
261
|
return err;
|
|
199
262
|
}
|
|
200
263
|
__name(transformClass, "transformClass");
|
|
201
|
-
function
|
|
264
|
+
async function transformProperty(instance, property, force = false) {
|
|
265
|
+
const err = [];
|
|
266
|
+
const handlers = getHandler(instance, property);
|
|
267
|
+
if (handlers) {
|
|
268
|
+
for (const handler of handlers) {
|
|
269
|
+
const pipe = handler.pipe;
|
|
270
|
+
if (!pipe)
|
|
271
|
+
continue;
|
|
272
|
+
try {
|
|
273
|
+
await pipe(instance);
|
|
274
|
+
} catch (e) {
|
|
275
|
+
err.push(e.message);
|
|
276
|
+
if (!force)
|
|
277
|
+
return err;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return err;
|
|
282
|
+
}
|
|
283
|
+
__name(transformProperty, "transformProperty");
|
|
284
|
+
function classToPlain(instance) {
|
|
202
285
|
const data = {};
|
|
203
286
|
const exposeVars = getExposeKey(instance);
|
|
204
287
|
for (const item of exposeVars)
|
|
205
288
|
data[item] = instance[item];
|
|
206
|
-
return data;
|
|
289
|
+
return JSON.parse(JSON.stringify(data));
|
|
207
290
|
}
|
|
208
|
-
__name(
|
|
291
|
+
__name(classToPlain, "classToPlain");
|
|
209
292
|
function snapShot(data) {
|
|
210
293
|
const snap = {};
|
|
211
294
|
for (const i in data)
|
|
@@ -223,8 +306,8 @@ function snapShot(data) {
|
|
|
223
306
|
};
|
|
224
307
|
}
|
|
225
308
|
__name(snapShot, "snapShot");
|
|
226
|
-
function addDecoToClass(c, key, handler
|
|
227
|
-
handler(
|
|
309
|
+
function addDecoToClass(c, key, handler) {
|
|
310
|
+
handler(key === SHARE_KEY ? c : c.prototype, key);
|
|
228
311
|
}
|
|
229
312
|
__name(addDecoToClass, "addDecoToClass");
|
|
230
313
|
function Pipeline(...decos) {
|
|
@@ -234,73 +317,43 @@ function Pipeline(...decos) {
|
|
|
234
317
|
};
|
|
235
318
|
}
|
|
236
319
|
__name(Pipeline, "Pipeline");
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
function Init(proto, key) {
|
|
240
|
-
setVar(proto, key);
|
|
241
|
-
regisHandler(proto, key, {
|
|
242
|
-
async init(instance) {
|
|
243
|
-
return instance[key]();
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
__name(Init, "Init");
|
|
248
|
-
function Unmount(proto, key) {
|
|
249
|
-
setVar(proto, key);
|
|
250
|
-
regisHandler(proto, key, {
|
|
251
|
-
async unmount(instance) {
|
|
252
|
-
return instance[key]();
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
__name(Unmount, "Unmount");
|
|
257
|
-
function Bind(value) {
|
|
258
|
-
return (proto, k) => {
|
|
259
|
-
setVar(proto, k);
|
|
260
|
-
setState(proto, k, {
|
|
261
|
-
value
|
|
262
|
-
});
|
|
263
|
-
};
|
|
320
|
+
function isAsyncFunc(fn) {
|
|
321
|
+
return fn[Symbol.toStringTag] === "AsyncFunction";
|
|
264
322
|
}
|
|
265
|
-
__name(
|
|
266
|
-
|
|
267
|
-
|
|
323
|
+
__name(isAsyncFunc, "isAsyncFunc");
|
|
324
|
+
|
|
325
|
+
// src/di.ts
|
|
326
|
+
var DataMap = {};
|
|
327
|
+
function Provide(key, value) {
|
|
328
|
+
DataMap[key] = value;
|
|
268
329
|
}
|
|
269
|
-
__name(
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
330
|
+
__name(Provide, "Provide");
|
|
331
|
+
var EmptyProxy = new Proxy(Empty, {
|
|
332
|
+
apply() {
|
|
333
|
+
return EmptyProxy;
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
function Inject(key) {
|
|
337
|
+
return DataMap[key] || EmptyProxy;
|
|
277
338
|
}
|
|
278
|
-
__name(
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
error: cb
|
|
284
|
-
});
|
|
285
|
-
};
|
|
339
|
+
__name(Inject, "Inject");
|
|
340
|
+
var activeInstance = {};
|
|
341
|
+
function injectProperty(key, value) {
|
|
342
|
+
activeInstance[key] = value;
|
|
343
|
+
return activeInstance;
|
|
286
344
|
}
|
|
287
|
-
__name(
|
|
288
|
-
function
|
|
289
|
-
|
|
345
|
+
__name(injectProperty, "injectProperty");
|
|
346
|
+
function getProperty(key) {
|
|
347
|
+
return activeInstance[key];
|
|
290
348
|
}
|
|
291
|
-
__name(
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
for (const cb of callbacks)
|
|
298
|
-
instance[key] = await cb(instance[key], instance, key);
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
};
|
|
349
|
+
__name(getProperty, "getProperty");
|
|
350
|
+
|
|
351
|
+
// src/decorators/function.ts
|
|
352
|
+
function Isolate(target) {
|
|
353
|
+
init(target.prototype);
|
|
354
|
+
target.prototype.__ISOLATE__ = true;
|
|
302
355
|
}
|
|
303
|
-
__name(
|
|
356
|
+
__name(Isolate, "Isolate");
|
|
304
357
|
function Tag(tag) {
|
|
305
358
|
return (module) => {
|
|
306
359
|
init(module.prototype);
|
|
@@ -318,8 +371,8 @@ __name(Unique, "Unique");
|
|
|
318
371
|
function Assign(cb) {
|
|
319
372
|
return (module) => {
|
|
320
373
|
init(module.prototype);
|
|
321
|
-
|
|
322
|
-
|
|
374
|
+
setStateVar(module.prototype, SHARE_KEY);
|
|
375
|
+
setHandler(module.prototype, SHARE_KEY, {
|
|
323
376
|
init: async (instance) => {
|
|
324
377
|
const value = await cb(instance);
|
|
325
378
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
@@ -333,8 +386,8 @@ function Assign(cb) {
|
|
|
333
386
|
__name(Assign, "Assign");
|
|
334
387
|
function Global(module) {
|
|
335
388
|
init(module.prototype);
|
|
336
|
-
|
|
337
|
-
|
|
389
|
+
setStateVar(module.prototype, SHARE_KEY);
|
|
390
|
+
setHandler(module.prototype, SHARE_KEY, {
|
|
338
391
|
init: async (instance) => {
|
|
339
392
|
const tag = instance.__TAG__;
|
|
340
393
|
if (!tag)
|
|
@@ -346,58 +399,57 @@ function Global(module) {
|
|
|
346
399
|
});
|
|
347
400
|
}
|
|
348
401
|
__name(Global, "Global");
|
|
349
|
-
function
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
var EmptyProxy = new Proxy(Empty, {
|
|
359
|
-
apply() {
|
|
360
|
-
return EmptyProxy;
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
function Inject(key) {
|
|
364
|
-
return DataMap[key] || EmptyProxy;
|
|
365
|
-
}
|
|
366
|
-
__name(Inject, "Inject");
|
|
367
|
-
function Nested(module) {
|
|
368
|
-
return To(async (property) => {
|
|
369
|
-
const instance = plainToClass(module, property);
|
|
370
|
-
const err = await transformClass(instance);
|
|
371
|
-
if (err.length > 0)
|
|
372
|
-
throw new Error(err[0]);
|
|
373
|
-
return instance;
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
__name(Nested, "Nested");
|
|
377
|
-
function Isolate() {
|
|
378
|
-
return (target) => {
|
|
379
|
-
init(target.prototype);
|
|
380
|
-
target.prototype.__ISOLATE__ = true;
|
|
402
|
+
function To(...callbacks) {
|
|
403
|
+
return (proto, key) => {
|
|
404
|
+
setStateVar(proto, key);
|
|
405
|
+
setHandler(proto, key, {
|
|
406
|
+
async pipe(instance) {
|
|
407
|
+
for (const cb of callbacks)
|
|
408
|
+
instance[key] = await cb(instance[key], instance, key);
|
|
409
|
+
}
|
|
410
|
+
});
|
|
381
411
|
};
|
|
382
412
|
}
|
|
383
|
-
__name(
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
413
|
+
__name(To, "To");
|
|
414
|
+
function Err(cb, isCatch = false) {
|
|
415
|
+
return (proto, key) => {
|
|
416
|
+
setStateVar(proto, key);
|
|
417
|
+
setHandler(proto, key, {
|
|
418
|
+
init: (instance) => {
|
|
419
|
+
if (typeof instance[key] === "function") {
|
|
420
|
+
const oldFn = instance[key].bind(instance);
|
|
421
|
+
if (isAsyncFunc(oldFn)) {
|
|
422
|
+
instance[key] = async (...args) => {
|
|
423
|
+
try {
|
|
424
|
+
await oldFn(...args);
|
|
425
|
+
} catch (e) {
|
|
426
|
+
cb(e, instance, key);
|
|
427
|
+
if (!isCatch)
|
|
428
|
+
throw e;
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
} else {
|
|
432
|
+
instance[key] = (...args) => {
|
|
433
|
+
try {
|
|
434
|
+
oldFn(...args);
|
|
435
|
+
} catch (e) {
|
|
436
|
+
cb(e, instance, key);
|
|
437
|
+
if (!isCatch)
|
|
438
|
+
throw e;
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
};
|
|
394
446
|
}
|
|
395
|
-
__name(
|
|
447
|
+
__name(Err, "Err");
|
|
396
448
|
function Watcher(eventName, options) {
|
|
397
449
|
let cb;
|
|
398
450
|
return (proto, key) => {
|
|
399
|
-
|
|
400
|
-
|
|
451
|
+
setStateVar(proto, key);
|
|
452
|
+
setHandler(proto, key, {
|
|
401
453
|
init(instance) {
|
|
402
454
|
return cb = getProperty("watcher")?.({
|
|
403
455
|
eventName,
|
|
@@ -415,8 +467,8 @@ function Watcher(eventName, options) {
|
|
|
415
467
|
__name(Watcher, "Watcher");
|
|
416
468
|
function Effect(eventName, options) {
|
|
417
469
|
return (proto, key) => {
|
|
418
|
-
|
|
419
|
-
|
|
470
|
+
setStateVar(proto, key);
|
|
471
|
+
setHandler(proto, key, {
|
|
420
472
|
init(instance) {
|
|
421
473
|
instance[`$_${key}`] = instance[key];
|
|
422
474
|
Object.defineProperty(instance, key, {
|
|
@@ -449,8 +501,8 @@ function Storage({ key: storeKey, toJSON, toString } = {}) {
|
|
|
449
501
|
if (key) {
|
|
450
502
|
init(proto);
|
|
451
503
|
tag = storeKey || `${getTag(proto)}_${key}`;
|
|
452
|
-
|
|
453
|
-
|
|
504
|
+
setStateVar(proto, key);
|
|
505
|
+
setHandler(proto, key, {
|
|
454
506
|
init: (instance) => {
|
|
455
507
|
return getProperty("storage")?.({
|
|
456
508
|
instance,
|
|
@@ -464,8 +516,8 @@ function Storage({ key: storeKey, toJSON, toString } = {}) {
|
|
|
464
516
|
} else {
|
|
465
517
|
init(proto.prototype);
|
|
466
518
|
tag = storeKey || getTag(proto);
|
|
467
|
-
|
|
468
|
-
|
|
519
|
+
setStateVar(proto.prototype, SHARE_KEY);
|
|
520
|
+
setHandler(proto.prototype, SHARE_KEY, {
|
|
469
521
|
init: (instance) => {
|
|
470
522
|
return getProperty("storage")?.({
|
|
471
523
|
instance,
|
|
@@ -494,7 +546,7 @@ export {
|
|
|
494
546
|
Init,
|
|
495
547
|
Inject,
|
|
496
548
|
Isolate,
|
|
497
|
-
|
|
549
|
+
PHECDA_KEY,
|
|
498
550
|
Pipeline,
|
|
499
551
|
Provide,
|
|
500
552
|
SHARE_KEY,
|
|
@@ -506,29 +558,31 @@ export {
|
|
|
506
558
|
Watcher,
|
|
507
559
|
activeInstance,
|
|
508
560
|
addDecoToClass,
|
|
509
|
-
|
|
561
|
+
classToPlain,
|
|
510
562
|
getBind,
|
|
511
563
|
getExposeKey,
|
|
512
564
|
getHandler,
|
|
513
|
-
getModuleState,
|
|
514
565
|
getOwnExposeKey,
|
|
515
566
|
getOwnHandler,
|
|
516
567
|
getOwnIgnoreKey,
|
|
517
|
-
getOwnModuleState,
|
|
518
568
|
getOwnState,
|
|
569
|
+
getOwnStateVars,
|
|
519
570
|
getProperty,
|
|
520
571
|
getState,
|
|
521
|
-
|
|
572
|
+
getStateVars,
|
|
573
|
+
getTag,
|
|
522
574
|
init,
|
|
523
575
|
injectProperty,
|
|
524
576
|
invokeHandler,
|
|
577
|
+
isAsyncFunc,
|
|
525
578
|
isPhecda,
|
|
526
579
|
plainToClass,
|
|
527
|
-
regisHandler,
|
|
528
580
|
setExposeKey,
|
|
581
|
+
setHandler,
|
|
529
582
|
setIgnoreKey,
|
|
530
583
|
setState,
|
|
531
|
-
|
|
584
|
+
setStateVar,
|
|
532
585
|
snapShot,
|
|
533
|
-
transformClass
|
|
586
|
+
transformClass,
|
|
587
|
+
transformProperty
|
|
534
588
|
};
|