phecda-core 3.0.0-alpha.9 → 3.0.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +73 -45
- package/dist/index.js +371 -245
- package/dist/index.mjs +355 -236
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -34,9 +34,10 @@ __export(src_exports, {
|
|
|
34
34
|
Init: () => Init,
|
|
35
35
|
Inject: () => Inject,
|
|
36
36
|
Isolate: () => Isolate,
|
|
37
|
-
|
|
37
|
+
PHECDA_KEY: () => PHECDA_KEY,
|
|
38
38
|
Pipeline: () => Pipeline,
|
|
39
39
|
Provide: () => Provide,
|
|
40
|
+
Rule: () => Rule,
|
|
40
41
|
SHARE_KEY: () => SHARE_KEY,
|
|
41
42
|
Storage: () => Storage,
|
|
42
43
|
Tag: () => Tag,
|
|
@@ -46,47 +47,54 @@ __export(src_exports, {
|
|
|
46
47
|
Watcher: () => Watcher,
|
|
47
48
|
activeInstance: () => activeInstance,
|
|
48
49
|
addDecoToClass: () => addDecoToClass,
|
|
49
|
-
|
|
50
|
+
classToPlain: () => classToPlain,
|
|
51
|
+
get: () => get,
|
|
50
52
|
getBind: () => getBind,
|
|
51
53
|
getExposeKey: () => getExposeKey,
|
|
52
54
|
getHandler: () => getHandler,
|
|
53
|
-
|
|
55
|
+
getKey: () => getKey,
|
|
54
56
|
getOwnExposeKey: () => getOwnExposeKey,
|
|
55
57
|
getOwnHandler: () => getOwnHandler,
|
|
56
58
|
getOwnIgnoreKey: () => getOwnIgnoreKey,
|
|
57
|
-
getOwnModuleState: () => getOwnModuleState,
|
|
58
59
|
getOwnState: () => getOwnState,
|
|
59
|
-
|
|
60
|
+
getOwnStateVars: () => getOwnStateVars,
|
|
60
61
|
getState: () => getState,
|
|
62
|
+
getStateVars: () => getStateVars,
|
|
61
63
|
getTag: () => getTag,
|
|
62
64
|
init: () => init,
|
|
63
|
-
|
|
65
|
+
injectKey: () => injectKey,
|
|
64
66
|
invokeHandler: () => invokeHandler,
|
|
67
|
+
isAsyncFunc: () => isAsyncFunc,
|
|
65
68
|
isPhecda: () => isPhecda,
|
|
66
69
|
plainToClass: () => plainToClass,
|
|
67
|
-
|
|
70
|
+
set: () => set,
|
|
68
71
|
setExposeKey: () => setExposeKey,
|
|
72
|
+
setHandler: () => setHandler,
|
|
69
73
|
setIgnoreKey: () => setIgnoreKey,
|
|
70
74
|
setState: () => setState,
|
|
71
|
-
|
|
75
|
+
setStateVar: () => setStateVar,
|
|
72
76
|
snapShot: () => snapShot,
|
|
73
|
-
|
|
77
|
+
transformInstance: () => transformInstance,
|
|
78
|
+
transformInstanceAsync: () => transformInstanceAsync,
|
|
79
|
+
transformProperty: () => transformProperty,
|
|
80
|
+
transformPropertyAsync: () => transformPropertyAsync
|
|
74
81
|
});
|
|
75
82
|
module.exports = __toCommonJS(src_exports);
|
|
76
83
|
|
|
77
84
|
// src/core.ts
|
|
85
|
+
var SHARE_KEY = Symbol("phecda");
|
|
86
|
+
var PHECDA_KEY = Symbol("phecda");
|
|
78
87
|
function isPhecda(module2) {
|
|
79
88
|
if (typeof module2 === "function")
|
|
80
|
-
return !!module2.prototype
|
|
89
|
+
return !!module2.prototype[PHECDA_KEY];
|
|
81
90
|
return false;
|
|
82
91
|
}
|
|
83
92
|
__name(isPhecda, "isPhecda");
|
|
84
|
-
var SHARE_KEY = Symbol("phecda-core");
|
|
85
93
|
function init(proto) {
|
|
86
94
|
if (!proto)
|
|
87
95
|
return;
|
|
88
|
-
if (!proto.hasOwnProperty(
|
|
89
|
-
proto
|
|
96
|
+
if (!proto.hasOwnProperty(PHECDA_KEY)) {
|
|
97
|
+
proto[PHECDA_KEY] = {
|
|
90
98
|
__EXPOSE_VAR__: /* @__PURE__ */ new Set(),
|
|
91
99
|
__IGNORE_VAR__: /* @__PURE__ */ new Set(),
|
|
92
100
|
__STATE_VAR__: /* @__PURE__ */ new Set(),
|
|
@@ -96,114 +104,115 @@ function init(proto) {
|
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
106
|
__name(init, "init");
|
|
99
|
-
function
|
|
107
|
+
function getPhecdaFromTarget(target) {
|
|
108
|
+
if (typeof target === "function")
|
|
109
|
+
return target.prototype;
|
|
110
|
+
if (target.hasOwnProperty(PHECDA_KEY))
|
|
111
|
+
return target;
|
|
112
|
+
return Object.getPrototypeOf(target);
|
|
113
|
+
}
|
|
114
|
+
__name(getPhecdaFromTarget, "getPhecdaFromTarget");
|
|
115
|
+
function setStateVar(proto, key) {
|
|
100
116
|
init(proto);
|
|
101
|
-
proto.
|
|
117
|
+
proto[PHECDA_KEY].__STATE_VAR__.add(key);
|
|
102
118
|
setExposeKey(proto, key);
|
|
103
119
|
}
|
|
104
|
-
__name(
|
|
120
|
+
__name(setStateVar, "setStateVar");
|
|
105
121
|
function setExposeKey(proto, key) {
|
|
106
122
|
init(proto);
|
|
107
|
-
proto.
|
|
123
|
+
proto[PHECDA_KEY].__EXPOSE_VAR__.add(key);
|
|
108
124
|
}
|
|
109
125
|
__name(setExposeKey, "setExposeKey");
|
|
110
126
|
function setIgnoreKey(proto, key) {
|
|
111
127
|
init(proto);
|
|
112
|
-
proto.
|
|
128
|
+
proto[PHECDA_KEY].__IGNORE_VAR__.add(key);
|
|
113
129
|
}
|
|
114
130
|
__name(setIgnoreKey, "setIgnoreKey");
|
|
115
|
-
function
|
|
116
|
-
|
|
131
|
+
function setHandler(proto, key, handler) {
|
|
132
|
+
init(proto);
|
|
133
|
+
if (!proto[PHECDA_KEY].__STATE_HANDLER__.has(key))
|
|
134
|
+
proto[PHECDA_KEY].__STATE_HANDLER__.set(key, [
|
|
135
|
+
handler
|
|
136
|
+
]);
|
|
137
|
+
else
|
|
138
|
+
proto[PHECDA_KEY].__STATE_HANDLER__.get(key).push(handler);
|
|
139
|
+
}
|
|
140
|
+
__name(setHandler, "setHandler");
|
|
141
|
+
function setState(proto, key, state) {
|
|
142
|
+
init(proto);
|
|
143
|
+
const namespace = proto[PHECDA_KEY].__STATE_NAMESPACE__;
|
|
144
|
+
namespace.set(key, state);
|
|
145
|
+
}
|
|
146
|
+
__name(setState, "setState");
|
|
147
|
+
function getOwnStateVars(target) {
|
|
148
|
+
const proto = getPhecdaFromTarget(target);
|
|
117
149
|
return [
|
|
118
|
-
...
|
|
150
|
+
...proto[PHECDA_KEY].__STATE_VAR__
|
|
119
151
|
];
|
|
120
152
|
}
|
|
121
|
-
__name(
|
|
122
|
-
function
|
|
123
|
-
let proto =
|
|
124
|
-
const
|
|
125
|
-
while (proto?.
|
|
126
|
-
proto.
|
|
153
|
+
__name(getOwnStateVars, "getOwnStateVars");
|
|
154
|
+
function getStateVars(target) {
|
|
155
|
+
let proto = getPhecdaFromTarget(target);
|
|
156
|
+
const set2 = /* @__PURE__ */ new Set();
|
|
157
|
+
while (proto?.[PHECDA_KEY]) {
|
|
158
|
+
proto[PHECDA_KEY].__STATE_VAR__.forEach((item) => set2.add(item));
|
|
127
159
|
proto = Object.getPrototypeOf(proto);
|
|
128
160
|
}
|
|
129
161
|
return [
|
|
130
|
-
...
|
|
162
|
+
...set2
|
|
131
163
|
];
|
|
132
164
|
}
|
|
133
|
-
__name(
|
|
134
|
-
function getOwnExposeKey(
|
|
135
|
-
|
|
165
|
+
__name(getStateVars, "getStateVars");
|
|
166
|
+
function getOwnExposeKey(target) {
|
|
167
|
+
const proto = getPhecdaFromTarget(target);
|
|
136
168
|
return [
|
|
137
|
-
...
|
|
138
|
-
].filter((item) => !
|
|
169
|
+
...proto[PHECDA_KEY].__EXPOSE_VAR__
|
|
170
|
+
].filter((item) => !proto[PHECDA_KEY].__IGNORE_VAR__.has(item));
|
|
139
171
|
}
|
|
140
172
|
__name(getOwnExposeKey, "getOwnExposeKey");
|
|
141
|
-
function getExposeKey(
|
|
142
|
-
let proto =
|
|
143
|
-
const
|
|
144
|
-
while (proto?.
|
|
173
|
+
function getExposeKey(target) {
|
|
174
|
+
let proto = getPhecdaFromTarget(target);
|
|
175
|
+
const set2 = /* @__PURE__ */ new Set();
|
|
176
|
+
while (proto?.[PHECDA_KEY]) {
|
|
145
177
|
[
|
|
146
|
-
...proto.
|
|
147
|
-
].forEach((item) => !proto.
|
|
178
|
+
...proto[PHECDA_KEY].__EXPOSE_VAR__
|
|
179
|
+
].forEach((item) => !proto[PHECDA_KEY].__IGNORE_VAR__.has(item) && set2.add(item));
|
|
148
180
|
proto = Object.getPrototypeOf(proto);
|
|
149
181
|
}
|
|
150
182
|
return [
|
|
151
|
-
...
|
|
183
|
+
...set2
|
|
152
184
|
];
|
|
153
185
|
}
|
|
154
186
|
__name(getExposeKey, "getExposeKey");
|
|
155
|
-
function getOwnIgnoreKey(
|
|
156
|
-
|
|
157
|
-
return [];
|
|
187
|
+
function getOwnIgnoreKey(target) {
|
|
188
|
+
const proto = getPhecdaFromTarget(target);
|
|
158
189
|
return [
|
|
159
|
-
...
|
|
190
|
+
...proto[PHECDA_KEY]?.__IGNORE_VAR__
|
|
160
191
|
];
|
|
161
192
|
}
|
|
162
193
|
__name(getOwnIgnoreKey, "getOwnIgnoreKey");
|
|
163
|
-
function
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
proto._namespace.__STATE_HANDLER__.set(key, [
|
|
167
|
-
handler
|
|
168
|
-
]);
|
|
169
|
-
else
|
|
170
|
-
proto._namespace.__STATE_HANDLER__.get(key).push(handler);
|
|
171
|
-
}
|
|
172
|
-
__name(regisHandler, "regisHandler");
|
|
173
|
-
function getOwnHandler(instance, key) {
|
|
174
|
-
if (!instance?._namespace)
|
|
175
|
-
return [];
|
|
176
|
-
return instance._namespace.__STATE_HANDLER__.get(key) || [];
|
|
194
|
+
function getOwnHandler(target, key) {
|
|
195
|
+
const proto = getPhecdaFromTarget(target);
|
|
196
|
+
return proto[PHECDA_KEY]?.__STATE_HANDLER__.get(key) || [];
|
|
177
197
|
}
|
|
178
198
|
__name(getOwnHandler, "getOwnHandler");
|
|
179
|
-
function getHandler(
|
|
180
|
-
let proto =
|
|
181
|
-
const
|
|
182
|
-
while (proto?.
|
|
183
|
-
proto.
|
|
199
|
+
function getHandler(target, key) {
|
|
200
|
+
let proto = getPhecdaFromTarget(target);
|
|
201
|
+
const set2 = /* @__PURE__ */ new Set();
|
|
202
|
+
while (proto?.[PHECDA_KEY]) {
|
|
203
|
+
proto[PHECDA_KEY].__STATE_HANDLER__.get(key)?.forEach((item) => set2.add(item));
|
|
184
204
|
proto = Object.getPrototypeOf(proto);
|
|
185
205
|
}
|
|
186
206
|
return [
|
|
187
|
-
...
|
|
207
|
+
...set2
|
|
188
208
|
];
|
|
189
209
|
}
|
|
190
210
|
__name(getHandler, "getHandler");
|
|
191
|
-
function
|
|
192
|
-
|
|
193
|
-
const namespace = proto._namespace.__STATE_NAMESPACE__;
|
|
194
|
-
namespace.set(key, state);
|
|
195
|
-
}
|
|
196
|
-
__name(setState, "setState");
|
|
197
|
-
function getOwnState(instance, key) {
|
|
198
|
-
instance = Object.getPrototypeOf(instance);
|
|
199
|
-
return instance._namespace.__STATE_NAMESPACE__.get(key) || {};
|
|
200
|
-
}
|
|
201
|
-
__name(getOwnState, "getOwnState");
|
|
202
|
-
function getState(instance, key) {
|
|
203
|
-
let proto = Object.getPrototypeOf(instance);
|
|
211
|
+
function getState(target, key) {
|
|
212
|
+
let proto = getPhecdaFromTarget(target);
|
|
204
213
|
let ret = {};
|
|
205
|
-
while (proto?.
|
|
206
|
-
const state = proto.
|
|
214
|
+
while (proto?.[PHECDA_KEY]) {
|
|
215
|
+
const state = proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key);
|
|
207
216
|
if (state)
|
|
208
217
|
ret = {
|
|
209
218
|
...state,
|
|
@@ -214,25 +223,89 @@ function getState(instance, key) {
|
|
|
214
223
|
return ret;
|
|
215
224
|
}
|
|
216
225
|
__name(getState, "getState");
|
|
226
|
+
function getOwnState(target, key) {
|
|
227
|
+
const proto = getPhecdaFromTarget(target);
|
|
228
|
+
return proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key) || {};
|
|
229
|
+
}
|
|
230
|
+
__name(getOwnState, "getOwnState");
|
|
217
231
|
function invokeHandler(event, instance) {
|
|
218
232
|
const stateVars = getExposeKey(instance);
|
|
219
233
|
const initHandlers = stateVars.map((item) => {
|
|
220
|
-
return getHandler(instance, item).filter((h) => h[event]).map((h) => h[event](instance));
|
|
234
|
+
return getHandler(instance, item).filter((h) => !!h[event]).map((h) => h[event](instance));
|
|
221
235
|
}).flat();
|
|
222
236
|
return Promise.all(initHandlers);
|
|
223
237
|
}
|
|
224
238
|
__name(invokeHandler, "invokeHandler");
|
|
239
|
+
function set(proto, key, value) {
|
|
240
|
+
init(proto);
|
|
241
|
+
proto[PHECDA_KEY][`__${key.toUpperCase()}__`] = value;
|
|
242
|
+
}
|
|
243
|
+
__name(set, "set");
|
|
244
|
+
function get(proto, key) {
|
|
245
|
+
return proto[PHECDA_KEY]?.[`__${key.toUpperCase()}__`];
|
|
246
|
+
}
|
|
247
|
+
__name(get, "get");
|
|
248
|
+
|
|
249
|
+
// src/decorators/core.ts
|
|
250
|
+
function Init(proto, key) {
|
|
251
|
+
setStateVar(proto, key);
|
|
252
|
+
setHandler(proto, key, {
|
|
253
|
+
async init(instance) {
|
|
254
|
+
return instance[key]();
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
__name(Init, "Init");
|
|
259
|
+
function Unmount(proto, key) {
|
|
260
|
+
setStateVar(proto, key);
|
|
261
|
+
setHandler(proto, key, {
|
|
262
|
+
async unmount(instance) {
|
|
263
|
+
return instance[key]();
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
__name(Unmount, "Unmount");
|
|
268
|
+
function Bind(value) {
|
|
269
|
+
return (proto, k) => {
|
|
270
|
+
setStateVar(proto, k);
|
|
271
|
+
setState(proto, k, {
|
|
272
|
+
value
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
__name(Bind, "Bind");
|
|
277
|
+
function Ignore(proto, key) {
|
|
278
|
+
setIgnoreKey(proto, key);
|
|
279
|
+
}
|
|
280
|
+
__name(Ignore, "Ignore");
|
|
281
|
+
function Clear(proto, key) {
|
|
282
|
+
init(proto);
|
|
283
|
+
proto[PHECDA_KEY].__EXPOSE_VAR__.delete(key);
|
|
284
|
+
proto[PHECDA_KEY].__IGNORE_VAR__.delete(key);
|
|
285
|
+
proto[PHECDA_KEY].__STATE_VAR__.delete(key);
|
|
286
|
+
proto[PHECDA_KEY].__STATE_HANDLER__.delete(key);
|
|
287
|
+
proto[PHECDA_KEY].__STATE_NAMESPACE__.delete(key);
|
|
288
|
+
}
|
|
289
|
+
__name(Clear, "Clear");
|
|
290
|
+
function Expose(proto, key) {
|
|
291
|
+
setExposeKey(proto, key);
|
|
292
|
+
}
|
|
293
|
+
__name(Expose, "Expose");
|
|
294
|
+
function Empty(module2) {
|
|
295
|
+
init(module2.prototype);
|
|
296
|
+
}
|
|
297
|
+
__name(Empty, "Empty");
|
|
225
298
|
|
|
226
299
|
// src/helper.ts
|
|
227
300
|
function getTag(moduleOrInstance) {
|
|
228
301
|
if (typeof moduleOrInstance === "object")
|
|
229
302
|
moduleOrInstance = moduleOrInstance.constructor;
|
|
230
|
-
return moduleOrInstance.prototype?.__TAG__ || moduleOrInstance.name;
|
|
303
|
+
return moduleOrInstance.prototype[PHECDA_KEY]?.__TAG__ || moduleOrInstance.name;
|
|
231
304
|
}
|
|
232
305
|
__name(getTag, "getTag");
|
|
233
306
|
function getBind(module2) {
|
|
234
307
|
const instance = new module2();
|
|
235
|
-
const keys =
|
|
308
|
+
const keys = getStateVars(instance);
|
|
236
309
|
const ret = {};
|
|
237
310
|
for (const item of keys) {
|
|
238
311
|
const state = getState(instance, item);
|
|
@@ -250,35 +323,88 @@ function plainToClass(module2, input) {
|
|
|
250
323
|
return instance;
|
|
251
324
|
}
|
|
252
325
|
__name(plainToClass, "plainToClass");
|
|
253
|
-
|
|
326
|
+
function transformInstance(instance, force = false) {
|
|
254
327
|
const err = [];
|
|
255
|
-
const
|
|
256
|
-
|
|
328
|
+
const keys = getExposeKey(instance);
|
|
329
|
+
const addError = err.push.bind(err);
|
|
330
|
+
for (const item of keys) {
|
|
257
331
|
const handlers = getHandler(instance, item);
|
|
258
332
|
if (handlers) {
|
|
259
333
|
for (const handler of handlers) {
|
|
260
334
|
const pipe = handler.pipe;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return err;
|
|
267
|
-
}
|
|
335
|
+
if (!pipe)
|
|
336
|
+
continue;
|
|
337
|
+
pipe(instance, addError);
|
|
338
|
+
if (err.length && !force)
|
|
339
|
+
return err;
|
|
268
340
|
}
|
|
269
341
|
}
|
|
270
342
|
}
|
|
271
343
|
return err;
|
|
272
344
|
}
|
|
273
|
-
__name(
|
|
274
|
-
function
|
|
345
|
+
__name(transformInstance, "transformInstance");
|
|
346
|
+
async function transformInstanceAsync(instance, force = false) {
|
|
347
|
+
const err = [];
|
|
348
|
+
const keys = getExposeKey(instance);
|
|
349
|
+
const addError = err.push.bind(err);
|
|
350
|
+
for (const item of keys) {
|
|
351
|
+
const handlers = getHandler(instance, item);
|
|
352
|
+
if (handlers) {
|
|
353
|
+
for (const handler of handlers) {
|
|
354
|
+
const pipe = handler.pipe;
|
|
355
|
+
if (!pipe)
|
|
356
|
+
continue;
|
|
357
|
+
await pipe(instance, addError);
|
|
358
|
+
if (err.length && !force)
|
|
359
|
+
return err;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return err;
|
|
364
|
+
}
|
|
365
|
+
__name(transformInstanceAsync, "transformInstanceAsync");
|
|
366
|
+
function transformProperty(instance, property, force = false) {
|
|
367
|
+
const err = [];
|
|
368
|
+
const handlers = getHandler(instance, property);
|
|
369
|
+
const addError = err.push.bind(err);
|
|
370
|
+
if (handlers) {
|
|
371
|
+
for (const handler of handlers) {
|
|
372
|
+
const pipe = handler.pipe;
|
|
373
|
+
if (!pipe)
|
|
374
|
+
continue;
|
|
375
|
+
pipe(instance, addError);
|
|
376
|
+
if (err.length && !force)
|
|
377
|
+
return err;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return err;
|
|
381
|
+
}
|
|
382
|
+
__name(transformProperty, "transformProperty");
|
|
383
|
+
async function transformPropertyAsync(instance, property, force = false) {
|
|
384
|
+
const err = [];
|
|
385
|
+
const handlers = getHandler(instance, property);
|
|
386
|
+
const addError = err.push.bind(err);
|
|
387
|
+
if (handlers) {
|
|
388
|
+
for (const handler of handlers) {
|
|
389
|
+
const pipe = handler.pipe;
|
|
390
|
+
if (!pipe)
|
|
391
|
+
continue;
|
|
392
|
+
await pipe(instance, addError);
|
|
393
|
+
if (err.length && !force)
|
|
394
|
+
return err;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return err;
|
|
398
|
+
}
|
|
399
|
+
__name(transformPropertyAsync, "transformPropertyAsync");
|
|
400
|
+
function classToPlain(instance) {
|
|
275
401
|
const data = {};
|
|
276
402
|
const exposeVars = getExposeKey(instance);
|
|
277
403
|
for (const item of exposeVars)
|
|
278
404
|
data[item] = instance[item];
|
|
279
|
-
return data;
|
|
405
|
+
return JSON.parse(JSON.stringify(data));
|
|
280
406
|
}
|
|
281
|
-
__name(
|
|
407
|
+
__name(classToPlain, "classToPlain");
|
|
282
408
|
function snapShot(data) {
|
|
283
409
|
const snap = {};
|
|
284
410
|
for (const i in data)
|
|
@@ -296,8 +422,8 @@ function snapShot(data) {
|
|
|
296
422
|
};
|
|
297
423
|
}
|
|
298
424
|
__name(snapShot, "snapShot");
|
|
299
|
-
function addDecoToClass(c, key, handler
|
|
300
|
-
handler(
|
|
425
|
+
function addDecoToClass(c, key, handler) {
|
|
426
|
+
handler(key === SHARE_KEY ? c : c.prototype, key);
|
|
301
427
|
}
|
|
302
428
|
__name(addDecoToClass, "addDecoToClass");
|
|
303
429
|
function Pipeline(...decos) {
|
|
@@ -307,92 +433,55 @@ function Pipeline(...decos) {
|
|
|
307
433
|
};
|
|
308
434
|
}
|
|
309
435
|
__name(Pipeline, "Pipeline");
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
function Init(proto, key) {
|
|
313
|
-
setVar(proto, key);
|
|
314
|
-
regisHandler(proto, key, {
|
|
315
|
-
async init(instance) {
|
|
316
|
-
return instance[key]();
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
__name(Init, "Init");
|
|
321
|
-
function Unmount(proto, key) {
|
|
322
|
-
setVar(proto, key);
|
|
323
|
-
regisHandler(proto, key, {
|
|
324
|
-
async unmount(instance) {
|
|
325
|
-
return instance[key]();
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
__name(Unmount, "Unmount");
|
|
330
|
-
function Bind(value) {
|
|
331
|
-
return (proto, k) => {
|
|
332
|
-
setVar(proto, k);
|
|
333
|
-
setState(proto, k, {
|
|
334
|
-
value
|
|
335
|
-
});
|
|
336
|
-
};
|
|
436
|
+
function isAsyncFunc(fn) {
|
|
437
|
+
return fn[Symbol.toStringTag] === "AsyncFunction";
|
|
337
438
|
}
|
|
338
|
-
__name(
|
|
339
|
-
|
|
340
|
-
|
|
439
|
+
__name(isAsyncFunc, "isAsyncFunc");
|
|
440
|
+
|
|
441
|
+
// src/di.ts
|
|
442
|
+
var DataMap = {};
|
|
443
|
+
function Provide(key, value) {
|
|
444
|
+
DataMap[key] = value;
|
|
341
445
|
}
|
|
342
|
-
__name(
|
|
343
|
-
function
|
|
344
|
-
|
|
345
|
-
proto._namespace.__EXPOSE_VAR__.delete(key);
|
|
346
|
-
proto._namespace.__IGNORE_VAR__.delete(key);
|
|
347
|
-
proto._namespace.__STATE_VAR__.delete(key);
|
|
348
|
-
proto._namespace.__STATE_HANDLER__.delete(key);
|
|
349
|
-
proto._namespace.__STATE_NAMESPACE__.delete(key);
|
|
446
|
+
__name(Provide, "Provide");
|
|
447
|
+
function Inject(key) {
|
|
448
|
+
return DataMap[key];
|
|
350
449
|
}
|
|
351
|
-
__name(
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
error: cb
|
|
357
|
-
});
|
|
358
|
-
};
|
|
450
|
+
__name(Inject, "Inject");
|
|
451
|
+
var activeInstance = {};
|
|
452
|
+
function injectKey(key, value) {
|
|
453
|
+
activeInstance[key] = value;
|
|
454
|
+
return activeInstance;
|
|
359
455
|
}
|
|
360
|
-
__name(
|
|
361
|
-
function
|
|
362
|
-
|
|
456
|
+
__name(injectKey, "injectKey");
|
|
457
|
+
function getKey(key) {
|
|
458
|
+
return activeInstance[key];
|
|
363
459
|
}
|
|
364
|
-
__name(
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
for (const cb of callbacks)
|
|
371
|
-
instance[key] = await cb(instance[key], instance, key);
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
};
|
|
460
|
+
__name(getKey, "getKey");
|
|
461
|
+
|
|
462
|
+
// src/decorators/function.ts
|
|
463
|
+
function Isolate(module2) {
|
|
464
|
+
set(module2.prototype, "isolate", true);
|
|
465
|
+
module2.prototype[PHECDA_KEY].__ISOLATE__ = true;
|
|
375
466
|
}
|
|
376
|
-
__name(
|
|
467
|
+
__name(Isolate, "Isolate");
|
|
377
468
|
function Tag(tag) {
|
|
378
469
|
return (module2) => {
|
|
379
|
-
|
|
380
|
-
module2.prototype.__TAG__ = tag;
|
|
470
|
+
set(module2.prototype, "tag", tag);
|
|
381
471
|
};
|
|
382
472
|
}
|
|
383
473
|
__name(Tag, "Tag");
|
|
384
474
|
function Unique(desc) {
|
|
385
475
|
return (module2) => {
|
|
386
|
-
|
|
387
|
-
module2.prototype.__TAG__ = Symbol(desc || module2.name);
|
|
476
|
+
set(module2.prototype, "tag", Symbol(desc || module2.name));
|
|
388
477
|
};
|
|
389
478
|
}
|
|
390
479
|
__name(Unique, "Unique");
|
|
391
480
|
function Assign(cb) {
|
|
392
481
|
return (module2) => {
|
|
393
482
|
init(module2.prototype);
|
|
394
|
-
|
|
395
|
-
|
|
483
|
+
setStateVar(module2.prototype, SHARE_KEY);
|
|
484
|
+
setHandler(module2.prototype, SHARE_KEY, {
|
|
396
485
|
init: async (instance) => {
|
|
397
486
|
const value = await cb(instance);
|
|
398
487
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
@@ -406,10 +495,10 @@ function Assign(cb) {
|
|
|
406
495
|
__name(Assign, "Assign");
|
|
407
496
|
function Global(module2) {
|
|
408
497
|
init(module2.prototype);
|
|
409
|
-
|
|
410
|
-
|
|
498
|
+
setStateVar(module2.prototype, SHARE_KEY);
|
|
499
|
+
setHandler(module2.prototype, SHARE_KEY, {
|
|
411
500
|
init: async (instance) => {
|
|
412
|
-
const tag = instance.__TAG__;
|
|
501
|
+
const tag = instance[PHECDA_KEY].__TAG__;
|
|
413
502
|
if (!tag)
|
|
414
503
|
return;
|
|
415
504
|
if (!globalThis.__PHECDA__)
|
|
@@ -419,59 +508,88 @@ function Global(module2) {
|
|
|
419
508
|
});
|
|
420
509
|
}
|
|
421
510
|
__name(Global, "Global");
|
|
422
|
-
function
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
__name(Inject, "Inject");
|
|
440
|
-
function Nested(module2) {
|
|
441
|
-
return To(async (property) => {
|
|
442
|
-
const instance = plainToClass(module2, property);
|
|
443
|
-
const err = await transformClass(instance);
|
|
444
|
-
if (err.length > 0)
|
|
445
|
-
throw new Error(err[0]);
|
|
446
|
-
return instance;
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
__name(Nested, "Nested");
|
|
450
|
-
function Isolate() {
|
|
451
|
-
return (target) => {
|
|
452
|
-
target.prototype.__ISOLATE__ = true;
|
|
511
|
+
function To(...callbacks) {
|
|
512
|
+
return (proto, key) => {
|
|
513
|
+
setStateVar(proto, key);
|
|
514
|
+
setHandler(proto, key, {
|
|
515
|
+
async pipe(instance, addError) {
|
|
516
|
+
for (const cb of callbacks) {
|
|
517
|
+
try {
|
|
518
|
+
if (isAsyncFunc(cb))
|
|
519
|
+
instance[key] = await cb(instance[key], instance, key);
|
|
520
|
+
else
|
|
521
|
+
instance[key] = cb(instance[key], instance, key);
|
|
522
|
+
} catch (e) {
|
|
523
|
+
addError(e.message);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
});
|
|
453
528
|
};
|
|
454
529
|
}
|
|
455
|
-
__name(
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
530
|
+
__name(To, "To");
|
|
531
|
+
function Rule(cb, info) {
|
|
532
|
+
return (proto, key) => {
|
|
533
|
+
setStateVar(proto, key);
|
|
534
|
+
setHandler(proto, key, {
|
|
535
|
+
async pipe(instance, addError) {
|
|
536
|
+
let ret;
|
|
537
|
+
if (isAsyncFunc(cb))
|
|
538
|
+
ret = await cb(instance[key]);
|
|
539
|
+
else
|
|
540
|
+
ret = cb(instance[key]);
|
|
541
|
+
if (!ret) {
|
|
542
|
+
if (typeof info === "string")
|
|
543
|
+
addError(info);
|
|
544
|
+
else
|
|
545
|
+
addError(info());
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
};
|
|
462
550
|
}
|
|
463
|
-
__name(
|
|
464
|
-
function
|
|
465
|
-
return
|
|
551
|
+
__name(Rule, "Rule");
|
|
552
|
+
function Err(cb, isCatch = false) {
|
|
553
|
+
return (proto, key) => {
|
|
554
|
+
setStateVar(proto, key);
|
|
555
|
+
setHandler(proto, key, {
|
|
556
|
+
init: (instance) => {
|
|
557
|
+
if (typeof instance[key] === "function") {
|
|
558
|
+
const oldFn = instance[key].bind(instance);
|
|
559
|
+
if (isAsyncFunc(oldFn)) {
|
|
560
|
+
instance[key] = async (...args) => {
|
|
561
|
+
try {
|
|
562
|
+
await oldFn(...args);
|
|
563
|
+
} catch (e) {
|
|
564
|
+
cb(e, instance, key);
|
|
565
|
+
if (!isCatch)
|
|
566
|
+
throw e;
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
} else {
|
|
570
|
+
instance[key] = (...args) => {
|
|
571
|
+
try {
|
|
572
|
+
oldFn(...args);
|
|
573
|
+
} catch (e) {
|
|
574
|
+
cb(e, instance, key);
|
|
575
|
+
if (!isCatch)
|
|
576
|
+
throw e;
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
};
|
|
466
584
|
}
|
|
467
|
-
__name(
|
|
585
|
+
__name(Err, "Err");
|
|
468
586
|
function Watcher(eventName, options) {
|
|
469
587
|
let cb;
|
|
470
588
|
return (proto, key) => {
|
|
471
|
-
|
|
472
|
-
|
|
589
|
+
setStateVar(proto, key);
|
|
590
|
+
setHandler(proto, key, {
|
|
473
591
|
init(instance) {
|
|
474
|
-
return cb =
|
|
592
|
+
return cb = getKey("watcher")?.({
|
|
475
593
|
eventName,
|
|
476
594
|
instance,
|
|
477
595
|
key,
|
|
@@ -485,10 +603,10 @@ function Watcher(eventName, options) {
|
|
|
485
603
|
};
|
|
486
604
|
}
|
|
487
605
|
__name(Watcher, "Watcher");
|
|
488
|
-
function Effect(
|
|
606
|
+
function Effect(cb) {
|
|
489
607
|
return (proto, key) => {
|
|
490
|
-
|
|
491
|
-
|
|
608
|
+
setStateVar(proto, key);
|
|
609
|
+
setHandler(proto, key, {
|
|
492
610
|
init(instance) {
|
|
493
611
|
instance[`$_${key}`] = instance[key];
|
|
494
612
|
Object.defineProperty(instance, key, {
|
|
@@ -497,12 +615,7 @@ function Effect(eventName, options) {
|
|
|
497
615
|
},
|
|
498
616
|
set(v) {
|
|
499
617
|
instance[`$_${key}`] = v;
|
|
500
|
-
|
|
501
|
-
instance,
|
|
502
|
-
key,
|
|
503
|
-
value: v,
|
|
504
|
-
options
|
|
505
|
-
});
|
|
618
|
+
cb(v, instance, key);
|
|
506
619
|
return true;
|
|
507
620
|
}
|
|
508
621
|
});
|
|
@@ -511,34 +624,40 @@ function Effect(eventName, options) {
|
|
|
511
624
|
};
|
|
512
625
|
}
|
|
513
626
|
__name(Effect, "Effect");
|
|
514
|
-
function Storage(storeKey) {
|
|
627
|
+
function Storage({ key: storeKey, toJSON, toString } = {}) {
|
|
628
|
+
if (!toJSON)
|
|
629
|
+
toJSON = /* @__PURE__ */ __name((v) => JSON.parse(v), "toJSON");
|
|
630
|
+
if (!toString)
|
|
631
|
+
toString = /* @__PURE__ */ __name((v) => JSON.stringify(v), "toString");
|
|
515
632
|
return (proto, key) => {
|
|
516
633
|
let tag;
|
|
517
634
|
if (key) {
|
|
518
635
|
init(proto);
|
|
519
|
-
tag = storeKey || proto
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
regisHandler(proto, uniTag, {
|
|
636
|
+
tag = storeKey || `${getTag(proto)}_${key}`;
|
|
637
|
+
setStateVar(proto, key);
|
|
638
|
+
setHandler(proto, key, {
|
|
523
639
|
init: (instance) => {
|
|
524
|
-
return
|
|
640
|
+
return getKey("storage")?.({
|
|
525
641
|
instance,
|
|
526
642
|
key,
|
|
527
|
-
tag
|
|
643
|
+
tag,
|
|
644
|
+
toJSON,
|
|
645
|
+
toString
|
|
528
646
|
});
|
|
529
647
|
}
|
|
530
648
|
});
|
|
531
649
|
} else {
|
|
532
650
|
init(proto.prototype);
|
|
533
|
-
tag = storeKey ||
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
regisHandler(proto.prototype, uniTag, {
|
|
651
|
+
tag = storeKey || getTag(proto);
|
|
652
|
+
setStateVar(proto.prototype, SHARE_KEY);
|
|
653
|
+
setHandler(proto.prototype, SHARE_KEY, {
|
|
537
654
|
init: (instance) => {
|
|
538
|
-
return
|
|
655
|
+
return getKey("storage")?.({
|
|
539
656
|
instance,
|
|
540
|
-
key
|
|
541
|
-
tag
|
|
657
|
+
key,
|
|
658
|
+
tag,
|
|
659
|
+
toJSON,
|
|
660
|
+
toString
|
|
542
661
|
});
|
|
543
662
|
}
|
|
544
663
|
});
|
|
@@ -561,9 +680,10 @@ __name(Storage, "Storage");
|
|
|
561
680
|
Init,
|
|
562
681
|
Inject,
|
|
563
682
|
Isolate,
|
|
564
|
-
|
|
683
|
+
PHECDA_KEY,
|
|
565
684
|
Pipeline,
|
|
566
685
|
Provide,
|
|
686
|
+
Rule,
|
|
567
687
|
SHARE_KEY,
|
|
568
688
|
Storage,
|
|
569
689
|
Tag,
|
|
@@ -573,29 +693,35 @@ __name(Storage, "Storage");
|
|
|
573
693
|
Watcher,
|
|
574
694
|
activeInstance,
|
|
575
695
|
addDecoToClass,
|
|
576
|
-
|
|
696
|
+
classToPlain,
|
|
697
|
+
get,
|
|
577
698
|
getBind,
|
|
578
699
|
getExposeKey,
|
|
579
700
|
getHandler,
|
|
580
|
-
|
|
701
|
+
getKey,
|
|
581
702
|
getOwnExposeKey,
|
|
582
703
|
getOwnHandler,
|
|
583
704
|
getOwnIgnoreKey,
|
|
584
|
-
getOwnModuleState,
|
|
585
705
|
getOwnState,
|
|
586
|
-
|
|
706
|
+
getOwnStateVars,
|
|
587
707
|
getState,
|
|
708
|
+
getStateVars,
|
|
588
709
|
getTag,
|
|
589
710
|
init,
|
|
590
|
-
|
|
711
|
+
injectKey,
|
|
591
712
|
invokeHandler,
|
|
713
|
+
isAsyncFunc,
|
|
592
714
|
isPhecda,
|
|
593
715
|
plainToClass,
|
|
594
|
-
|
|
716
|
+
set,
|
|
595
717
|
setExposeKey,
|
|
718
|
+
setHandler,
|
|
596
719
|
setIgnoreKey,
|
|
597
720
|
setState,
|
|
598
|
-
|
|
721
|
+
setStateVar,
|
|
599
722
|
snapShot,
|
|
600
|
-
|
|
723
|
+
transformInstance,
|
|
724
|
+
transformInstanceAsync,
|
|
725
|
+
transformProperty,
|
|
726
|
+
transformPropertyAsync
|
|
601
727
|
});
|