phecda-core 3.0.0-beta.14 → 3.0.0-beta.15
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 +11 -10
- package/dist/index.js +68 -56
- package/dist/index.mjs +64 -53
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
declare function Init(proto: any, key: PropertyKey): void;
|
|
2
2
|
declare function Unmount(proto: any, key: PropertyKey): void;
|
|
3
3
|
declare function Bind(value: any): (proto: any, k: PropertyKey) => void;
|
|
4
|
-
declare function Ignore(proto: any, key
|
|
5
|
-
declare function Clear(proto: any, key
|
|
4
|
+
declare function Ignore(proto: any, key?: PropertyKey): void;
|
|
5
|
+
declare function Clear(proto: any, key?: PropertyKey): void;
|
|
6
6
|
declare function Expose(proto: any, key: PropertyKey): void;
|
|
7
7
|
declare function Empty(model: any): void;
|
|
8
8
|
|
|
@@ -10,13 +10,14 @@ declare const SHARE_KEY: unique symbol;
|
|
|
10
10
|
declare const PHECDA_KEY: unique symbol;
|
|
11
11
|
declare function isPhecda(model: any): model is Construct;
|
|
12
12
|
declare function init(proto: Phecda): void;
|
|
13
|
-
declare function
|
|
13
|
+
declare function getPhecdaFromTarget(target: any): any;
|
|
14
|
+
declare function setStateKey(proto: Phecda, key: PropertyKey): void;
|
|
14
15
|
declare function setExposeKey(proto: Phecda, key: PropertyKey): void;
|
|
15
16
|
declare function setIgnoreKey(proto: Phecda, key: PropertyKey): void;
|
|
16
17
|
declare function setHandler(proto: Phecda, key: PropertyKey, handler: Handler): void;
|
|
17
18
|
declare function setState(proto: Phecda, key: PropertyKey, state: Record<string, any>): void;
|
|
18
|
-
declare function
|
|
19
|
-
declare function
|
|
19
|
+
declare function getOwnStateKey(target: any): string[];
|
|
20
|
+
declare function getStateKey(target: any): PropertyKey[];
|
|
20
21
|
declare function getOwnExposeKey(target: any): string[];
|
|
21
22
|
declare function getExposeKey(target: any): PropertyKey[];
|
|
22
23
|
declare function getOwnIgnoreKey(target: any): string[];
|
|
@@ -42,12 +43,12 @@ interface Handler {
|
|
|
42
43
|
interface Phecda {
|
|
43
44
|
prototype: any;
|
|
44
45
|
[PHECDA_KEY]: {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
__EXPOSE_KEY: Set<PropertyKey>;
|
|
47
|
+
__IGNORE_KEY: Set<PropertyKey>;
|
|
48
|
+
__CLEAR_KEY: Set<PropertyKey>;
|
|
49
|
+
__STATE_KEY: Set<PropertyKey>;
|
|
48
50
|
__STATE_HANDLER__: Map<PropertyKey, Handler[]>;
|
|
49
51
|
__STATE_NAMESPACE__: Map<PropertyKey, Object>;
|
|
50
|
-
[key: string]: any;
|
|
51
52
|
};
|
|
52
53
|
}
|
|
53
54
|
type ClassValue<I> = {
|
|
@@ -113,4 +114,4 @@ declare const activeInstance: Record<string, any>;
|
|
|
113
114
|
declare function injectKey(key: string, value: any): Record<string, any>;
|
|
114
115
|
declare function getKey(key: string): any;
|
|
115
116
|
|
|
116
|
-
export { AbConstruct, Assign, Bind, ClassValue, Clear, Construct, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, Isolate, NameSpace, PHECDA_KEY, Phecda, Pipeline, Provide, Rule, SHARE_KEY, Storage, StorageParam, Tag, To, Unique, Unmount, Watcher, WatcherParam, activeInstance, addDecoToClass, classToPlain, get, getBind, getExposeKey, getHandler, getKey, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnState,
|
|
117
|
+
export { AbConstruct, Assign, Bind, ClassValue, Clear, Construct, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, Isolate, NameSpace, PHECDA_KEY, Phecda, Pipeline, Provide, Rule, SHARE_KEY, Storage, StorageParam, Tag, To, Unique, Unmount, Watcher, WatcherParam, activeInstance, addDecoToClass, classToPlain, get, getBind, getExposeKey, getHandler, getKey, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnState, getOwnStateKey, getPhecdaFromTarget, getState, getStateKey, getTag, init, injectKey, invokeHandler, isAsyncFunc, isPhecda, plainToClass, set, setExposeKey, setHandler, setIgnoreKey, setState, setStateKey, snapShot, transformInstance, transformInstanceAsync, transformProperty, transformPropertyAsync };
|
package/dist/index.js
CHANGED
|
@@ -57,9 +57,10 @@ __export(src_exports, {
|
|
|
57
57
|
getOwnHandler: () => getOwnHandler,
|
|
58
58
|
getOwnIgnoreKey: () => getOwnIgnoreKey,
|
|
59
59
|
getOwnState: () => getOwnState,
|
|
60
|
-
|
|
60
|
+
getOwnStateKey: () => getOwnStateKey,
|
|
61
|
+
getPhecdaFromTarget: () => getPhecdaFromTarget,
|
|
61
62
|
getState: () => getState,
|
|
62
|
-
|
|
63
|
+
getStateKey: () => getStateKey,
|
|
63
64
|
getTag: () => getTag,
|
|
64
65
|
init: () => init,
|
|
65
66
|
injectKey: () => injectKey,
|
|
@@ -72,7 +73,7 @@ __export(src_exports, {
|
|
|
72
73
|
setHandler: () => setHandler,
|
|
73
74
|
setIgnoreKey: () => setIgnoreKey,
|
|
74
75
|
setState: () => setState,
|
|
75
|
-
|
|
76
|
+
setStateKey: () => setStateKey,
|
|
76
77
|
snapShot: () => snapShot,
|
|
77
78
|
transformInstance: () => transformInstance,
|
|
78
79
|
transformInstanceAsync: () => transformInstanceAsync,
|
|
@@ -95,9 +96,10 @@ function init(proto) {
|
|
|
95
96
|
return;
|
|
96
97
|
if (!proto.hasOwnProperty(PHECDA_KEY)) {
|
|
97
98
|
proto[PHECDA_KEY] = {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
__EXPOSE_KEY: /* @__PURE__ */ new Set(),
|
|
100
|
+
__IGNORE_KEY: /* @__PURE__ */ new Set(),
|
|
101
|
+
__CLEAR_KEY: /* @__PURE__ */ new Set(),
|
|
102
|
+
__STATE_KEY: /* @__PURE__ */ new Set(),
|
|
101
103
|
__STATE_HANDLER__: /* @__PURE__ */ new Map(),
|
|
102
104
|
__STATE_NAMESPACE__: /* @__PURE__ */ new Map()
|
|
103
105
|
};
|
|
@@ -112,20 +114,20 @@ function getPhecdaFromTarget(target) {
|
|
|
112
114
|
return Object.getPrototypeOf(target);
|
|
113
115
|
}
|
|
114
116
|
__name(getPhecdaFromTarget, "getPhecdaFromTarget");
|
|
115
|
-
function
|
|
117
|
+
function setStateKey(proto, key) {
|
|
116
118
|
init(proto);
|
|
117
|
-
proto[PHECDA_KEY].
|
|
119
|
+
proto[PHECDA_KEY].__STATE_KEY.add(key);
|
|
118
120
|
setExposeKey(proto, key);
|
|
119
121
|
}
|
|
120
|
-
__name(
|
|
122
|
+
__name(setStateKey, "setStateKey");
|
|
121
123
|
function setExposeKey(proto, key) {
|
|
122
124
|
init(proto);
|
|
123
|
-
proto[PHECDA_KEY].
|
|
125
|
+
proto[PHECDA_KEY].__EXPOSE_KEY.add(key);
|
|
124
126
|
}
|
|
125
127
|
__name(setExposeKey, "setExposeKey");
|
|
126
128
|
function setIgnoreKey(proto, key) {
|
|
127
129
|
init(proto);
|
|
128
|
-
proto[PHECDA_KEY].
|
|
130
|
+
proto[PHECDA_KEY].__IGNORE_KEY.add(key);
|
|
129
131
|
}
|
|
130
132
|
__name(setIgnoreKey, "setIgnoreKey");
|
|
131
133
|
function setHandler(proto, key, handler) {
|
|
@@ -144,39 +146,42 @@ function setState(proto, key, state) {
|
|
|
144
146
|
namespace.set(key, state);
|
|
145
147
|
}
|
|
146
148
|
__name(setState, "setState");
|
|
147
|
-
function
|
|
149
|
+
function getOwnStateKey(target) {
|
|
148
150
|
const proto = getPhecdaFromTarget(target);
|
|
149
151
|
return [
|
|
150
|
-
...proto[PHECDA_KEY].
|
|
152
|
+
...proto[PHECDA_KEY].__STATE_KEY
|
|
151
153
|
];
|
|
152
154
|
}
|
|
153
|
-
__name(
|
|
154
|
-
function
|
|
155
|
+
__name(getOwnStateKey, "getOwnStateKey");
|
|
156
|
+
function getStateKey(target) {
|
|
155
157
|
let proto = getPhecdaFromTarget(target);
|
|
156
158
|
const set2 = /* @__PURE__ */ new Set();
|
|
157
159
|
while (proto?.[PHECDA_KEY]) {
|
|
158
|
-
proto
|
|
160
|
+
if (proto.hasOwnProperty(PHECDA_KEY))
|
|
161
|
+
proto[PHECDA_KEY].__STATE_KEY.forEach((item) => set2.add(item));
|
|
159
162
|
proto = Object.getPrototypeOf(proto);
|
|
160
163
|
}
|
|
161
164
|
return [
|
|
162
165
|
...set2
|
|
163
166
|
];
|
|
164
167
|
}
|
|
165
|
-
__name(
|
|
168
|
+
__name(getStateKey, "getStateKey");
|
|
166
169
|
function getOwnExposeKey(target) {
|
|
167
170
|
const proto = getPhecdaFromTarget(target);
|
|
168
171
|
return [
|
|
169
|
-
...proto[PHECDA_KEY].
|
|
170
|
-
].filter((item) => !proto[PHECDA_KEY].
|
|
172
|
+
...proto[PHECDA_KEY].__EXPOSE_KEY
|
|
173
|
+
].filter((item) => !proto[PHECDA_KEY].__IGNORE_KEY.has(item));
|
|
171
174
|
}
|
|
172
175
|
__name(getOwnExposeKey, "getOwnExposeKey");
|
|
173
176
|
function getExposeKey(target) {
|
|
174
177
|
let proto = getPhecdaFromTarget(target);
|
|
175
178
|
const set2 = /* @__PURE__ */ new Set();
|
|
179
|
+
const origin = proto;
|
|
176
180
|
while (proto?.[PHECDA_KEY]) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
181
|
+
if (proto.hasOwnProperty(PHECDA_KEY))
|
|
182
|
+
[
|
|
183
|
+
...proto[PHECDA_KEY].__EXPOSE_KEY
|
|
184
|
+
].forEach((item) => !origin[PHECDA_KEY].__IGNORE_KEY.has(item) && set2.add(item));
|
|
180
185
|
proto = Object.getPrototypeOf(proto);
|
|
181
186
|
}
|
|
182
187
|
return [
|
|
@@ -187,7 +192,7 @@ __name(getExposeKey, "getExposeKey");
|
|
|
187
192
|
function getOwnIgnoreKey(target) {
|
|
188
193
|
const proto = getPhecdaFromTarget(target);
|
|
189
194
|
return [
|
|
190
|
-
...proto[PHECDA_KEY]?.
|
|
195
|
+
...proto[PHECDA_KEY]?.__IGNORE_KEY
|
|
191
196
|
];
|
|
192
197
|
}
|
|
193
198
|
__name(getOwnIgnoreKey, "getOwnIgnoreKey");
|
|
@@ -200,7 +205,11 @@ function getHandler(target, key) {
|
|
|
200
205
|
let proto = getPhecdaFromTarget(target);
|
|
201
206
|
const set2 = /* @__PURE__ */ new Set();
|
|
202
207
|
while (proto?.[PHECDA_KEY]) {
|
|
203
|
-
proto
|
|
208
|
+
if (proto.hasOwnProperty(PHECDA_KEY)) {
|
|
209
|
+
proto[PHECDA_KEY].__STATE_HANDLER__.get(key)?.forEach((item) => set2.add(item));
|
|
210
|
+
if (proto[PHECDA_KEY].__CLEAR_KEY.has(key))
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
204
213
|
proto = Object.getPrototypeOf(proto);
|
|
205
214
|
}
|
|
206
215
|
return [
|
|
@@ -212,12 +221,16 @@ function getState(target, key) {
|
|
|
212
221
|
let proto = getPhecdaFromTarget(target);
|
|
213
222
|
let ret = {};
|
|
214
223
|
while (proto?.[PHECDA_KEY]) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
224
|
+
if (proto.hasOwnProperty(PHECDA_KEY)) {
|
|
225
|
+
const state = proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key);
|
|
226
|
+
if (state)
|
|
227
|
+
ret = {
|
|
228
|
+
...state,
|
|
229
|
+
...ret
|
|
230
|
+
};
|
|
231
|
+
if (proto[PHECDA_KEY].__CLEAR_KEY.has(key))
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
221
234
|
proto = Object.getPrototypeOf(proto);
|
|
222
235
|
}
|
|
223
236
|
return ret;
|
|
@@ -238,17 +251,19 @@ function invokeHandler(event, module2) {
|
|
|
238
251
|
__name(invokeHandler, "invokeHandler");
|
|
239
252
|
function set(proto, key, value) {
|
|
240
253
|
init(proto);
|
|
241
|
-
proto
|
|
254
|
+
setState(proto, SHARE_KEY, {
|
|
255
|
+
[`__${key.toUpperCase()}__`]: value
|
|
256
|
+
});
|
|
242
257
|
}
|
|
243
258
|
__name(set, "set");
|
|
244
259
|
function get(proto, key) {
|
|
245
|
-
return proto[
|
|
260
|
+
return getState(proto, SHARE_KEY)[`__${key.toUpperCase()}__`];
|
|
246
261
|
}
|
|
247
262
|
__name(get, "get");
|
|
248
263
|
|
|
249
264
|
// src/decorators/core.ts
|
|
250
265
|
function Init(proto, key) {
|
|
251
|
-
|
|
266
|
+
setStateKey(proto, key);
|
|
252
267
|
setHandler(proto, key, {
|
|
253
268
|
async init(instance) {
|
|
254
269
|
return instance[key]();
|
|
@@ -257,7 +272,7 @@ function Init(proto, key) {
|
|
|
257
272
|
}
|
|
258
273
|
__name(Init, "Init");
|
|
259
274
|
function Unmount(proto, key) {
|
|
260
|
-
|
|
275
|
+
setStateKey(proto, key);
|
|
261
276
|
setHandler(proto, key, {
|
|
262
277
|
async unmount(instance) {
|
|
263
278
|
return instance[key]();
|
|
@@ -267,24 +282,20 @@ function Unmount(proto, key) {
|
|
|
267
282
|
__name(Unmount, "Unmount");
|
|
268
283
|
function Bind(value) {
|
|
269
284
|
return (proto, k) => {
|
|
270
|
-
|
|
285
|
+
setStateKey(proto, k);
|
|
271
286
|
setState(proto, k, {
|
|
272
287
|
value
|
|
273
288
|
});
|
|
274
289
|
};
|
|
275
290
|
}
|
|
276
291
|
__name(Bind, "Bind");
|
|
277
|
-
function Ignore(proto, key) {
|
|
292
|
+
function Ignore(proto, key = SHARE_KEY) {
|
|
278
293
|
setIgnoreKey(proto, key);
|
|
279
294
|
}
|
|
280
295
|
__name(Ignore, "Ignore");
|
|
281
|
-
function Clear(proto, key) {
|
|
296
|
+
function Clear(proto, key = SHARE_KEY) {
|
|
282
297
|
init(proto);
|
|
283
|
-
proto[PHECDA_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);
|
|
298
|
+
proto[PHECDA_KEY].__CLEAR_KEY.add(key);
|
|
288
299
|
}
|
|
289
300
|
__name(Clear, "Clear");
|
|
290
301
|
function Expose(proto, key) {
|
|
@@ -300,12 +311,12 @@ __name(Empty, "Empty");
|
|
|
300
311
|
function getTag(moduleOrInstance) {
|
|
301
312
|
if (typeof moduleOrInstance === "object")
|
|
302
313
|
moduleOrInstance = moduleOrInstance.constructor;
|
|
303
|
-
return moduleOrInstance.prototype
|
|
314
|
+
return get(moduleOrInstance.prototype, "tag") || moduleOrInstance.name;
|
|
304
315
|
}
|
|
305
316
|
__name(getTag, "getTag");
|
|
306
317
|
function getBind(model) {
|
|
307
318
|
const instance = new model();
|
|
308
|
-
const keys =
|
|
319
|
+
const keys = getStateKey(instance);
|
|
309
320
|
const ret = {};
|
|
310
321
|
for (const item of keys) {
|
|
311
322
|
const state = getState(instance, item);
|
|
@@ -480,7 +491,7 @@ __name(Unique, "Unique");
|
|
|
480
491
|
function Assign(cb) {
|
|
481
492
|
return (model) => {
|
|
482
493
|
init(model.prototype);
|
|
483
|
-
|
|
494
|
+
setStateKey(model.prototype, SHARE_KEY);
|
|
484
495
|
setHandler(model.prototype, SHARE_KEY, {
|
|
485
496
|
init: async (instance) => {
|
|
486
497
|
const value = await cb(instance);
|
|
@@ -495,7 +506,7 @@ function Assign(cb) {
|
|
|
495
506
|
__name(Assign, "Assign");
|
|
496
507
|
function Global(model) {
|
|
497
508
|
init(model.prototype);
|
|
498
|
-
|
|
509
|
+
setStateKey(model.prototype, SHARE_KEY);
|
|
499
510
|
setHandler(model.prototype, SHARE_KEY, {
|
|
500
511
|
init: async (instance) => {
|
|
501
512
|
const tag = instance[PHECDA_KEY].__TAG__;
|
|
@@ -510,7 +521,7 @@ function Global(model) {
|
|
|
510
521
|
__name(Global, "Global");
|
|
511
522
|
function To(...callbacks) {
|
|
512
523
|
return (proto, key) => {
|
|
513
|
-
|
|
524
|
+
setStateKey(proto, key);
|
|
514
525
|
setHandler(proto, key, {
|
|
515
526
|
async pipe(instance, addError) {
|
|
516
527
|
for (const cb of callbacks) {
|
|
@@ -530,7 +541,7 @@ function To(...callbacks) {
|
|
|
530
541
|
__name(To, "To");
|
|
531
542
|
function Rule(cb, info) {
|
|
532
543
|
return (proto, key) => {
|
|
533
|
-
|
|
544
|
+
setStateKey(proto, key);
|
|
534
545
|
setHandler(proto, key, {
|
|
535
546
|
async pipe(instance, addError) {
|
|
536
547
|
let ret;
|
|
@@ -551,7 +562,7 @@ function Rule(cb, info) {
|
|
|
551
562
|
__name(Rule, "Rule");
|
|
552
563
|
function Err(cb, isCatch = false) {
|
|
553
564
|
return (proto, key) => {
|
|
554
|
-
|
|
565
|
+
setStateKey(proto, key);
|
|
555
566
|
setHandler(proto, key, {
|
|
556
567
|
init: (instance) => {
|
|
557
568
|
if (typeof instance[key] === "function") {
|
|
@@ -586,7 +597,7 @@ __name(Err, "Err");
|
|
|
586
597
|
function Watcher(eventName, options) {
|
|
587
598
|
let cb;
|
|
588
599
|
return (proto, key) => {
|
|
589
|
-
|
|
600
|
+
setStateKey(proto, key);
|
|
590
601
|
setHandler(proto, key, {
|
|
591
602
|
init(instance) {
|
|
592
603
|
return cb = getKey("watcher")?.({
|
|
@@ -605,7 +616,7 @@ function Watcher(eventName, options) {
|
|
|
605
616
|
__name(Watcher, "Watcher");
|
|
606
617
|
function Effect(cb) {
|
|
607
618
|
return (proto, key) => {
|
|
608
|
-
|
|
619
|
+
setStateKey(proto, key);
|
|
609
620
|
setHandler(proto, key, {
|
|
610
621
|
init(instance) {
|
|
611
622
|
instance[`$_${key}`] = instance[key];
|
|
@@ -634,7 +645,7 @@ function Storage({ key: storeKey, toJSON, toString } = {}) {
|
|
|
634
645
|
if (key) {
|
|
635
646
|
init(proto);
|
|
636
647
|
tag = storeKey || `${getTag(proto)}_${key}`;
|
|
637
|
-
|
|
648
|
+
setStateKey(proto, key);
|
|
638
649
|
setHandler(proto, key, {
|
|
639
650
|
init: (instance) => {
|
|
640
651
|
return getKey("storage")?.({
|
|
@@ -649,7 +660,7 @@ function Storage({ key: storeKey, toJSON, toString } = {}) {
|
|
|
649
660
|
} else {
|
|
650
661
|
init(proto.prototype);
|
|
651
662
|
tag = storeKey || getTag(proto);
|
|
652
|
-
|
|
663
|
+
setStateKey(proto.prototype, SHARE_KEY);
|
|
653
664
|
setHandler(proto.prototype, SHARE_KEY, {
|
|
654
665
|
init: (instance) => {
|
|
655
666
|
return getKey("storage")?.({
|
|
@@ -703,9 +714,10 @@ __name(Storage, "Storage");
|
|
|
703
714
|
getOwnHandler,
|
|
704
715
|
getOwnIgnoreKey,
|
|
705
716
|
getOwnState,
|
|
706
|
-
|
|
717
|
+
getOwnStateKey,
|
|
718
|
+
getPhecdaFromTarget,
|
|
707
719
|
getState,
|
|
708
|
-
|
|
720
|
+
getStateKey,
|
|
709
721
|
getTag,
|
|
710
722
|
init,
|
|
711
723
|
injectKey,
|
|
@@ -718,7 +730,7 @@ __name(Storage, "Storage");
|
|
|
718
730
|
setHandler,
|
|
719
731
|
setIgnoreKey,
|
|
720
732
|
setState,
|
|
721
|
-
|
|
733
|
+
setStateKey,
|
|
722
734
|
snapShot,
|
|
723
735
|
transformInstance,
|
|
724
736
|
transformInstanceAsync,
|
package/dist/index.mjs
CHANGED
|
@@ -15,9 +15,10 @@ function init(proto) {
|
|
|
15
15
|
return;
|
|
16
16
|
if (!proto.hasOwnProperty(PHECDA_KEY)) {
|
|
17
17
|
proto[PHECDA_KEY] = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
__EXPOSE_KEY: /* @__PURE__ */ new Set(),
|
|
19
|
+
__IGNORE_KEY: /* @__PURE__ */ new Set(),
|
|
20
|
+
__CLEAR_KEY: /* @__PURE__ */ new Set(),
|
|
21
|
+
__STATE_KEY: /* @__PURE__ */ new Set(),
|
|
21
22
|
__STATE_HANDLER__: /* @__PURE__ */ new Map(),
|
|
22
23
|
__STATE_NAMESPACE__: /* @__PURE__ */ new Map()
|
|
23
24
|
};
|
|
@@ -32,20 +33,20 @@ function getPhecdaFromTarget(target) {
|
|
|
32
33
|
return Object.getPrototypeOf(target);
|
|
33
34
|
}
|
|
34
35
|
__name(getPhecdaFromTarget, "getPhecdaFromTarget");
|
|
35
|
-
function
|
|
36
|
+
function setStateKey(proto, key) {
|
|
36
37
|
init(proto);
|
|
37
|
-
proto[PHECDA_KEY].
|
|
38
|
+
proto[PHECDA_KEY].__STATE_KEY.add(key);
|
|
38
39
|
setExposeKey(proto, key);
|
|
39
40
|
}
|
|
40
|
-
__name(
|
|
41
|
+
__name(setStateKey, "setStateKey");
|
|
41
42
|
function setExposeKey(proto, key) {
|
|
42
43
|
init(proto);
|
|
43
|
-
proto[PHECDA_KEY].
|
|
44
|
+
proto[PHECDA_KEY].__EXPOSE_KEY.add(key);
|
|
44
45
|
}
|
|
45
46
|
__name(setExposeKey, "setExposeKey");
|
|
46
47
|
function setIgnoreKey(proto, key) {
|
|
47
48
|
init(proto);
|
|
48
|
-
proto[PHECDA_KEY].
|
|
49
|
+
proto[PHECDA_KEY].__IGNORE_KEY.add(key);
|
|
49
50
|
}
|
|
50
51
|
__name(setIgnoreKey, "setIgnoreKey");
|
|
51
52
|
function setHandler(proto, key, handler) {
|
|
@@ -64,39 +65,42 @@ function setState(proto, key, state) {
|
|
|
64
65
|
namespace.set(key, state);
|
|
65
66
|
}
|
|
66
67
|
__name(setState, "setState");
|
|
67
|
-
function
|
|
68
|
+
function getOwnStateKey(target) {
|
|
68
69
|
const proto = getPhecdaFromTarget(target);
|
|
69
70
|
return [
|
|
70
|
-
...proto[PHECDA_KEY].
|
|
71
|
+
...proto[PHECDA_KEY].__STATE_KEY
|
|
71
72
|
];
|
|
72
73
|
}
|
|
73
|
-
__name(
|
|
74
|
-
function
|
|
74
|
+
__name(getOwnStateKey, "getOwnStateKey");
|
|
75
|
+
function getStateKey(target) {
|
|
75
76
|
let proto = getPhecdaFromTarget(target);
|
|
76
77
|
const set2 = /* @__PURE__ */ new Set();
|
|
77
78
|
while (proto?.[PHECDA_KEY]) {
|
|
78
|
-
proto
|
|
79
|
+
if (proto.hasOwnProperty(PHECDA_KEY))
|
|
80
|
+
proto[PHECDA_KEY].__STATE_KEY.forEach((item) => set2.add(item));
|
|
79
81
|
proto = Object.getPrototypeOf(proto);
|
|
80
82
|
}
|
|
81
83
|
return [
|
|
82
84
|
...set2
|
|
83
85
|
];
|
|
84
86
|
}
|
|
85
|
-
__name(
|
|
87
|
+
__name(getStateKey, "getStateKey");
|
|
86
88
|
function getOwnExposeKey(target) {
|
|
87
89
|
const proto = getPhecdaFromTarget(target);
|
|
88
90
|
return [
|
|
89
|
-
...proto[PHECDA_KEY].
|
|
90
|
-
].filter((item) => !proto[PHECDA_KEY].
|
|
91
|
+
...proto[PHECDA_KEY].__EXPOSE_KEY
|
|
92
|
+
].filter((item) => !proto[PHECDA_KEY].__IGNORE_KEY.has(item));
|
|
91
93
|
}
|
|
92
94
|
__name(getOwnExposeKey, "getOwnExposeKey");
|
|
93
95
|
function getExposeKey(target) {
|
|
94
96
|
let proto = getPhecdaFromTarget(target);
|
|
95
97
|
const set2 = /* @__PURE__ */ new Set();
|
|
98
|
+
const origin = proto;
|
|
96
99
|
while (proto?.[PHECDA_KEY]) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
if (proto.hasOwnProperty(PHECDA_KEY))
|
|
101
|
+
[
|
|
102
|
+
...proto[PHECDA_KEY].__EXPOSE_KEY
|
|
103
|
+
].forEach((item) => !origin[PHECDA_KEY].__IGNORE_KEY.has(item) && set2.add(item));
|
|
100
104
|
proto = Object.getPrototypeOf(proto);
|
|
101
105
|
}
|
|
102
106
|
return [
|
|
@@ -107,7 +111,7 @@ __name(getExposeKey, "getExposeKey");
|
|
|
107
111
|
function getOwnIgnoreKey(target) {
|
|
108
112
|
const proto = getPhecdaFromTarget(target);
|
|
109
113
|
return [
|
|
110
|
-
...proto[PHECDA_KEY]?.
|
|
114
|
+
...proto[PHECDA_KEY]?.__IGNORE_KEY
|
|
111
115
|
];
|
|
112
116
|
}
|
|
113
117
|
__name(getOwnIgnoreKey, "getOwnIgnoreKey");
|
|
@@ -120,7 +124,11 @@ function getHandler(target, key) {
|
|
|
120
124
|
let proto = getPhecdaFromTarget(target);
|
|
121
125
|
const set2 = /* @__PURE__ */ new Set();
|
|
122
126
|
while (proto?.[PHECDA_KEY]) {
|
|
123
|
-
proto
|
|
127
|
+
if (proto.hasOwnProperty(PHECDA_KEY)) {
|
|
128
|
+
proto[PHECDA_KEY].__STATE_HANDLER__.get(key)?.forEach((item) => set2.add(item));
|
|
129
|
+
if (proto[PHECDA_KEY].__CLEAR_KEY.has(key))
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
124
132
|
proto = Object.getPrototypeOf(proto);
|
|
125
133
|
}
|
|
126
134
|
return [
|
|
@@ -132,12 +140,16 @@ function getState(target, key) {
|
|
|
132
140
|
let proto = getPhecdaFromTarget(target);
|
|
133
141
|
let ret = {};
|
|
134
142
|
while (proto?.[PHECDA_KEY]) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
if (proto.hasOwnProperty(PHECDA_KEY)) {
|
|
144
|
+
const state = proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key);
|
|
145
|
+
if (state)
|
|
146
|
+
ret = {
|
|
147
|
+
...state,
|
|
148
|
+
...ret
|
|
149
|
+
};
|
|
150
|
+
if (proto[PHECDA_KEY].__CLEAR_KEY.has(key))
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
141
153
|
proto = Object.getPrototypeOf(proto);
|
|
142
154
|
}
|
|
143
155
|
return ret;
|
|
@@ -158,17 +170,19 @@ function invokeHandler(event, module) {
|
|
|
158
170
|
__name(invokeHandler, "invokeHandler");
|
|
159
171
|
function set(proto, key, value) {
|
|
160
172
|
init(proto);
|
|
161
|
-
proto
|
|
173
|
+
setState(proto, SHARE_KEY, {
|
|
174
|
+
[`__${key.toUpperCase()}__`]: value
|
|
175
|
+
});
|
|
162
176
|
}
|
|
163
177
|
__name(set, "set");
|
|
164
178
|
function get(proto, key) {
|
|
165
|
-
return proto[
|
|
179
|
+
return getState(proto, SHARE_KEY)[`__${key.toUpperCase()}__`];
|
|
166
180
|
}
|
|
167
181
|
__name(get, "get");
|
|
168
182
|
|
|
169
183
|
// src/decorators/core.ts
|
|
170
184
|
function Init(proto, key) {
|
|
171
|
-
|
|
185
|
+
setStateKey(proto, key);
|
|
172
186
|
setHandler(proto, key, {
|
|
173
187
|
async init(instance) {
|
|
174
188
|
return instance[key]();
|
|
@@ -177,7 +191,7 @@ function Init(proto, key) {
|
|
|
177
191
|
}
|
|
178
192
|
__name(Init, "Init");
|
|
179
193
|
function Unmount(proto, key) {
|
|
180
|
-
|
|
194
|
+
setStateKey(proto, key);
|
|
181
195
|
setHandler(proto, key, {
|
|
182
196
|
async unmount(instance) {
|
|
183
197
|
return instance[key]();
|
|
@@ -187,24 +201,20 @@ function Unmount(proto, key) {
|
|
|
187
201
|
__name(Unmount, "Unmount");
|
|
188
202
|
function Bind(value) {
|
|
189
203
|
return (proto, k) => {
|
|
190
|
-
|
|
204
|
+
setStateKey(proto, k);
|
|
191
205
|
setState(proto, k, {
|
|
192
206
|
value
|
|
193
207
|
});
|
|
194
208
|
};
|
|
195
209
|
}
|
|
196
210
|
__name(Bind, "Bind");
|
|
197
|
-
function Ignore(proto, key) {
|
|
211
|
+
function Ignore(proto, key = SHARE_KEY) {
|
|
198
212
|
setIgnoreKey(proto, key);
|
|
199
213
|
}
|
|
200
214
|
__name(Ignore, "Ignore");
|
|
201
|
-
function Clear(proto, key) {
|
|
215
|
+
function Clear(proto, key = SHARE_KEY) {
|
|
202
216
|
init(proto);
|
|
203
|
-
proto[PHECDA_KEY].
|
|
204
|
-
proto[PHECDA_KEY].__IGNORE_VAR__.delete(key);
|
|
205
|
-
proto[PHECDA_KEY].__STATE_VAR__.delete(key);
|
|
206
|
-
proto[PHECDA_KEY].__STATE_HANDLER__.delete(key);
|
|
207
|
-
proto[PHECDA_KEY].__STATE_NAMESPACE__.delete(key);
|
|
217
|
+
proto[PHECDA_KEY].__CLEAR_KEY.add(key);
|
|
208
218
|
}
|
|
209
219
|
__name(Clear, "Clear");
|
|
210
220
|
function Expose(proto, key) {
|
|
@@ -220,12 +230,12 @@ __name(Empty, "Empty");
|
|
|
220
230
|
function getTag(moduleOrInstance) {
|
|
221
231
|
if (typeof moduleOrInstance === "object")
|
|
222
232
|
moduleOrInstance = moduleOrInstance.constructor;
|
|
223
|
-
return moduleOrInstance.prototype
|
|
233
|
+
return get(moduleOrInstance.prototype, "tag") || moduleOrInstance.name;
|
|
224
234
|
}
|
|
225
235
|
__name(getTag, "getTag");
|
|
226
236
|
function getBind(model) {
|
|
227
237
|
const instance = new model();
|
|
228
|
-
const keys =
|
|
238
|
+
const keys = getStateKey(instance);
|
|
229
239
|
const ret = {};
|
|
230
240
|
for (const item of keys) {
|
|
231
241
|
const state = getState(instance, item);
|
|
@@ -400,7 +410,7 @@ __name(Unique, "Unique");
|
|
|
400
410
|
function Assign(cb) {
|
|
401
411
|
return (model) => {
|
|
402
412
|
init(model.prototype);
|
|
403
|
-
|
|
413
|
+
setStateKey(model.prototype, SHARE_KEY);
|
|
404
414
|
setHandler(model.prototype, SHARE_KEY, {
|
|
405
415
|
init: async (instance) => {
|
|
406
416
|
const value = await cb(instance);
|
|
@@ -415,7 +425,7 @@ function Assign(cb) {
|
|
|
415
425
|
__name(Assign, "Assign");
|
|
416
426
|
function Global(model) {
|
|
417
427
|
init(model.prototype);
|
|
418
|
-
|
|
428
|
+
setStateKey(model.prototype, SHARE_KEY);
|
|
419
429
|
setHandler(model.prototype, SHARE_KEY, {
|
|
420
430
|
init: async (instance) => {
|
|
421
431
|
const tag = instance[PHECDA_KEY].__TAG__;
|
|
@@ -430,7 +440,7 @@ function Global(model) {
|
|
|
430
440
|
__name(Global, "Global");
|
|
431
441
|
function To(...callbacks) {
|
|
432
442
|
return (proto, key) => {
|
|
433
|
-
|
|
443
|
+
setStateKey(proto, key);
|
|
434
444
|
setHandler(proto, key, {
|
|
435
445
|
async pipe(instance, addError) {
|
|
436
446
|
for (const cb of callbacks) {
|
|
@@ -450,7 +460,7 @@ function To(...callbacks) {
|
|
|
450
460
|
__name(To, "To");
|
|
451
461
|
function Rule(cb, info) {
|
|
452
462
|
return (proto, key) => {
|
|
453
|
-
|
|
463
|
+
setStateKey(proto, key);
|
|
454
464
|
setHandler(proto, key, {
|
|
455
465
|
async pipe(instance, addError) {
|
|
456
466
|
let ret;
|
|
@@ -471,7 +481,7 @@ function Rule(cb, info) {
|
|
|
471
481
|
__name(Rule, "Rule");
|
|
472
482
|
function Err(cb, isCatch = false) {
|
|
473
483
|
return (proto, key) => {
|
|
474
|
-
|
|
484
|
+
setStateKey(proto, key);
|
|
475
485
|
setHandler(proto, key, {
|
|
476
486
|
init: (instance) => {
|
|
477
487
|
if (typeof instance[key] === "function") {
|
|
@@ -506,7 +516,7 @@ __name(Err, "Err");
|
|
|
506
516
|
function Watcher(eventName, options) {
|
|
507
517
|
let cb;
|
|
508
518
|
return (proto, key) => {
|
|
509
|
-
|
|
519
|
+
setStateKey(proto, key);
|
|
510
520
|
setHandler(proto, key, {
|
|
511
521
|
init(instance) {
|
|
512
522
|
return cb = getKey("watcher")?.({
|
|
@@ -525,7 +535,7 @@ function Watcher(eventName, options) {
|
|
|
525
535
|
__name(Watcher, "Watcher");
|
|
526
536
|
function Effect(cb) {
|
|
527
537
|
return (proto, key) => {
|
|
528
|
-
|
|
538
|
+
setStateKey(proto, key);
|
|
529
539
|
setHandler(proto, key, {
|
|
530
540
|
init(instance) {
|
|
531
541
|
instance[`$_${key}`] = instance[key];
|
|
@@ -554,7 +564,7 @@ function Storage({ key: storeKey, toJSON, toString } = {}) {
|
|
|
554
564
|
if (key) {
|
|
555
565
|
init(proto);
|
|
556
566
|
tag = storeKey || `${getTag(proto)}_${key}`;
|
|
557
|
-
|
|
567
|
+
setStateKey(proto, key);
|
|
558
568
|
setHandler(proto, key, {
|
|
559
569
|
init: (instance) => {
|
|
560
570
|
return getKey("storage")?.({
|
|
@@ -569,7 +579,7 @@ function Storage({ key: storeKey, toJSON, toString } = {}) {
|
|
|
569
579
|
} else {
|
|
570
580
|
init(proto.prototype);
|
|
571
581
|
tag = storeKey || getTag(proto);
|
|
572
|
-
|
|
582
|
+
setStateKey(proto.prototype, SHARE_KEY);
|
|
573
583
|
setHandler(proto.prototype, SHARE_KEY, {
|
|
574
584
|
init: (instance) => {
|
|
575
585
|
return getKey("storage")?.({
|
|
@@ -622,9 +632,10 @@ export {
|
|
|
622
632
|
getOwnHandler,
|
|
623
633
|
getOwnIgnoreKey,
|
|
624
634
|
getOwnState,
|
|
625
|
-
|
|
635
|
+
getOwnStateKey,
|
|
636
|
+
getPhecdaFromTarget,
|
|
626
637
|
getState,
|
|
627
|
-
|
|
638
|
+
getStateKey,
|
|
628
639
|
getTag,
|
|
629
640
|
init,
|
|
630
641
|
injectKey,
|
|
@@ -637,7 +648,7 @@ export {
|
|
|
637
648
|
setHandler,
|
|
638
649
|
setIgnoreKey,
|
|
639
650
|
setState,
|
|
640
|
-
|
|
651
|
+
setStateKey,
|
|
641
652
|
snapShot,
|
|
642
653
|
transformInstance,
|
|
643
654
|
transformInstanceAsync,
|