phecda-core 3.0.0-beta.15 → 3.0.0-beta.17
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 +19 -17
- package/dist/index.js +83 -61
- package/dist/index.mjs +79 -59
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -11,11 +11,11 @@ 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
13
|
declare function getPhecdaFromTarget(target: any): any;
|
|
14
|
-
declare function setStateKey(proto: Phecda, key
|
|
15
|
-
declare function setExposeKey(proto: Phecda, key
|
|
16
|
-
declare function setIgnoreKey(proto: Phecda, key
|
|
17
|
-
declare function setHandler(proto: Phecda, key: PropertyKey, handler: Handler): void;
|
|
18
|
-
declare function setState(proto: Phecda, key: PropertyKey, state: Record<string, any>): void;
|
|
14
|
+
declare function setStateKey(proto: Phecda, key?: PropertyKey): void;
|
|
15
|
+
declare function setExposeKey(proto: Phecda, key?: PropertyKey): void;
|
|
16
|
+
declare function setIgnoreKey(proto: Phecda, key?: PropertyKey): void;
|
|
17
|
+
declare function setHandler(proto: Phecda, key: PropertyKey | undefined, handler: Handler): void;
|
|
18
|
+
declare function setState(proto: Phecda, key: PropertyKey | undefined, state: Record<string, any>): void;
|
|
19
19
|
declare function getOwnStateKey(target: any): string[];
|
|
20
20
|
declare function getStateKey(target: any): PropertyKey[];
|
|
21
21
|
declare function getOwnExposeKey(target: any): string[];
|
|
@@ -23,11 +23,11 @@ declare function getExposeKey(target: any): PropertyKey[];
|
|
|
23
23
|
declare function getOwnIgnoreKey(target: any): string[];
|
|
24
24
|
declare function getOwnHandler(target: any, key: PropertyKey): Handler[];
|
|
25
25
|
declare function getHandler(target: any, key: PropertyKey): any[];
|
|
26
|
-
declare function getState(target: any, key
|
|
27
|
-
declare function getOwnState(target: any, key
|
|
26
|
+
declare function getState(target: any, key?: PropertyKey): any;
|
|
27
|
+
declare function getOwnState(target: any, key?: PropertyKey): Record<string, any>;
|
|
28
28
|
declare function invokeHandler(event: string, module: Phecda): Promise<any[]>;
|
|
29
|
-
declare function set(proto:
|
|
30
|
-
declare function get(proto:
|
|
29
|
+
declare function set(proto: any, key: string, value: any): void;
|
|
30
|
+
declare function get(proto: any, key: string): any;
|
|
31
31
|
|
|
32
32
|
interface NameSpace {
|
|
33
33
|
[name: string]: Phecda;
|
|
@@ -66,7 +66,7 @@ declare function To(...callbacks: ((arg: any, instance: any, key: string) => any
|
|
|
66
66
|
declare function Rule(cb: ((arg: any) => boolean | Promise<boolean>), info: string | (() => string)): (proto: any, key: PropertyKey) => void;
|
|
67
67
|
declare function Err(cb: (e: Error | any, instance: any, key: string) => void, isCatch?: boolean): (proto: any, key: PropertyKey) => void;
|
|
68
68
|
interface StorageParam {
|
|
69
|
-
key
|
|
69
|
+
key: PropertyKey;
|
|
70
70
|
instance: any;
|
|
71
71
|
tag: string;
|
|
72
72
|
toJSON: (str: string) => any;
|
|
@@ -84,9 +84,9 @@ declare function Watcher(eventName: keyof Events, options?: {
|
|
|
84
84
|
once?: boolean;
|
|
85
85
|
}): (proto: any, key: string) => void;
|
|
86
86
|
declare function Effect(cb: (value: any, instance: any, key: string) => void): (proto: any, key: string) => void;
|
|
87
|
-
declare function Storage({ key: storeKey,
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
declare function Storage({ key: storeKey, json, stringify }?: {
|
|
88
|
+
json?: (str: string) => any;
|
|
89
|
+
stringify?: (arg: any) => string;
|
|
90
90
|
key?: string;
|
|
91
91
|
}): (proto: any, key?: PropertyKey) => void;
|
|
92
92
|
|
|
@@ -103,15 +103,17 @@ declare function snapShot<T extends Construct>(data: InstanceType<T>): {
|
|
|
103
103
|
clear(): void;
|
|
104
104
|
apply(): void;
|
|
105
105
|
};
|
|
106
|
-
declare function addDecoToClass<M extends Construct | AbConstruct>(c: M, key: keyof InstanceType<M> | PropertyKey, handler: PropertyDecorator | ClassDecorator): void;
|
|
106
|
+
declare function addDecoToClass<M extends Construct | AbConstruct>(c: M, key: keyof InstanceType<M> | PropertyKey | undefined, handler: PropertyDecorator | ClassDecorator): void;
|
|
107
107
|
declare function Pipeline(...decos: ((...args: any) => void)[]): (...args: any) => void;
|
|
108
108
|
declare function isAsyncFunc(fn: Function): boolean;
|
|
109
|
+
declare function setPropertyState(target: any, k: undefined | PropertyKey, setter: (state: Record<string, any>) => void): void;
|
|
110
|
+
declare function getShareState<State>(target: any, getter: (state: Record<string, any>) => State): State;
|
|
109
111
|
|
|
110
112
|
declare const DataMap: InjectData;
|
|
111
113
|
declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
|
|
112
114
|
declare function Inject<K extends keyof InjectData>(key: K): InjectData[K];
|
|
113
115
|
declare const activeInstance: Record<string, any>;
|
|
114
|
-
declare function
|
|
115
|
-
declare function
|
|
116
|
+
declare function setInject(key: string, value: any): Record<string, any>;
|
|
117
|
+
declare function getInject(key: string): any;
|
|
116
118
|
|
|
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,
|
|
119
|
+
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, getInject, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnState, getOwnStateKey, getPhecdaFromTarget, getShareState, getState, getStateKey, getTag, init, invokeHandler, isAsyncFunc, isPhecda, plainToClass, set, setExposeKey, setHandler, setIgnoreKey, setInject, setPropertyState, setState, setStateKey, snapShot, transformInstance, transformInstanceAsync, transformProperty, transformPropertyAsync };
|
package/dist/index.js
CHANGED
|
@@ -52,18 +52,18 @@ __export(src_exports, {
|
|
|
52
52
|
getBind: () => getBind,
|
|
53
53
|
getExposeKey: () => getExposeKey,
|
|
54
54
|
getHandler: () => getHandler,
|
|
55
|
-
|
|
55
|
+
getInject: () => getInject,
|
|
56
56
|
getOwnExposeKey: () => getOwnExposeKey,
|
|
57
57
|
getOwnHandler: () => getOwnHandler,
|
|
58
58
|
getOwnIgnoreKey: () => getOwnIgnoreKey,
|
|
59
59
|
getOwnState: () => getOwnState,
|
|
60
60
|
getOwnStateKey: () => getOwnStateKey,
|
|
61
61
|
getPhecdaFromTarget: () => getPhecdaFromTarget,
|
|
62
|
+
getShareState: () => getShareState,
|
|
62
63
|
getState: () => getState,
|
|
63
64
|
getStateKey: () => getStateKey,
|
|
64
65
|
getTag: () => getTag,
|
|
65
66
|
init: () => init,
|
|
66
|
-
injectKey: () => injectKey,
|
|
67
67
|
invokeHandler: () => invokeHandler,
|
|
68
68
|
isAsyncFunc: () => isAsyncFunc,
|
|
69
69
|
isPhecda: () => isPhecda,
|
|
@@ -72,6 +72,8 @@ __export(src_exports, {
|
|
|
72
72
|
setExposeKey: () => setExposeKey,
|
|
73
73
|
setHandler: () => setHandler,
|
|
74
74
|
setIgnoreKey: () => setIgnoreKey,
|
|
75
|
+
setInject: () => setInject,
|
|
76
|
+
setPropertyState: () => setPropertyState,
|
|
75
77
|
setState: () => setState,
|
|
76
78
|
setStateKey: () => setStateKey,
|
|
77
79
|
snapShot: () => snapShot,
|
|
@@ -115,22 +117,38 @@ function getPhecdaFromTarget(target) {
|
|
|
115
117
|
}
|
|
116
118
|
__name(getPhecdaFromTarget, "getPhecdaFromTarget");
|
|
117
119
|
function setStateKey(proto, key) {
|
|
120
|
+
if (!key) {
|
|
121
|
+
key = SHARE_KEY;
|
|
122
|
+
proto = proto.prototype;
|
|
123
|
+
}
|
|
118
124
|
init(proto);
|
|
119
125
|
proto[PHECDA_KEY].__STATE_KEY.add(key);
|
|
120
126
|
setExposeKey(proto, key);
|
|
121
127
|
}
|
|
122
128
|
__name(setStateKey, "setStateKey");
|
|
123
129
|
function setExposeKey(proto, key) {
|
|
130
|
+
if (!key) {
|
|
131
|
+
key = SHARE_KEY;
|
|
132
|
+
proto = proto.prototype;
|
|
133
|
+
}
|
|
124
134
|
init(proto);
|
|
125
135
|
proto[PHECDA_KEY].__EXPOSE_KEY.add(key);
|
|
126
136
|
}
|
|
127
137
|
__name(setExposeKey, "setExposeKey");
|
|
128
138
|
function setIgnoreKey(proto, key) {
|
|
139
|
+
if (!key) {
|
|
140
|
+
key = SHARE_KEY;
|
|
141
|
+
proto = proto.prototype;
|
|
142
|
+
}
|
|
129
143
|
init(proto);
|
|
130
144
|
proto[PHECDA_KEY].__IGNORE_KEY.add(key);
|
|
131
145
|
}
|
|
132
146
|
__name(setIgnoreKey, "setIgnoreKey");
|
|
133
147
|
function setHandler(proto, key, handler) {
|
|
148
|
+
if (!key) {
|
|
149
|
+
key = SHARE_KEY;
|
|
150
|
+
proto = proto.prototype;
|
|
151
|
+
}
|
|
134
152
|
init(proto);
|
|
135
153
|
if (!proto[PHECDA_KEY].__STATE_HANDLER__.has(key))
|
|
136
154
|
proto[PHECDA_KEY].__STATE_HANDLER__.set(key, [
|
|
@@ -141,6 +159,10 @@ function setHandler(proto, key, handler) {
|
|
|
141
159
|
}
|
|
142
160
|
__name(setHandler, "setHandler");
|
|
143
161
|
function setState(proto, key, state) {
|
|
162
|
+
if (!key) {
|
|
163
|
+
key = SHARE_KEY;
|
|
164
|
+
proto = proto.prototype;
|
|
165
|
+
}
|
|
144
166
|
init(proto);
|
|
145
167
|
const namespace = proto[PHECDA_KEY].__STATE_NAMESPACE__;
|
|
146
168
|
namespace.set(key, state);
|
|
@@ -217,7 +239,7 @@ function getHandler(target, key) {
|
|
|
217
239
|
];
|
|
218
240
|
}
|
|
219
241
|
__name(getHandler, "getHandler");
|
|
220
|
-
function getState(target, key) {
|
|
242
|
+
function getState(target, key = SHARE_KEY) {
|
|
221
243
|
let proto = getPhecdaFromTarget(target);
|
|
222
244
|
let ret = {};
|
|
223
245
|
while (proto?.[PHECDA_KEY]) {
|
|
@@ -236,7 +258,7 @@ function getState(target, key) {
|
|
|
236
258
|
return ret;
|
|
237
259
|
}
|
|
238
260
|
__name(getState, "getState");
|
|
239
|
-
function getOwnState(target, key) {
|
|
261
|
+
function getOwnState(target, key = SHARE_KEY) {
|
|
240
262
|
const proto = getPhecdaFromTarget(target);
|
|
241
263
|
return proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key) || {};
|
|
242
264
|
}
|
|
@@ -251,13 +273,11 @@ function invokeHandler(event, module2) {
|
|
|
251
273
|
__name(invokeHandler, "invokeHandler");
|
|
252
274
|
function set(proto, key, value) {
|
|
253
275
|
init(proto);
|
|
254
|
-
|
|
255
|
-
[`__${key.toUpperCase()}__`]: value
|
|
256
|
-
});
|
|
276
|
+
proto[`__${key.toUpperCase()}__`] = value;
|
|
257
277
|
}
|
|
258
278
|
__name(set, "set");
|
|
259
279
|
function get(proto, key) {
|
|
260
|
-
return
|
|
280
|
+
return proto[`__${key.toUpperCase()}__`];
|
|
261
281
|
}
|
|
262
282
|
__name(get, "get");
|
|
263
283
|
|
|
@@ -289,11 +309,19 @@ function Bind(value) {
|
|
|
289
309
|
};
|
|
290
310
|
}
|
|
291
311
|
__name(Bind, "Bind");
|
|
292
|
-
function Ignore(proto, key
|
|
312
|
+
function Ignore(proto, key) {
|
|
313
|
+
if (!key) {
|
|
314
|
+
proto = proto.prototype;
|
|
315
|
+
key = SHARE_KEY;
|
|
316
|
+
}
|
|
293
317
|
setIgnoreKey(proto, key);
|
|
294
318
|
}
|
|
295
319
|
__name(Ignore, "Ignore");
|
|
296
|
-
function Clear(proto, key
|
|
320
|
+
function Clear(proto, key) {
|
|
321
|
+
if (!key) {
|
|
322
|
+
proto = proto.prototype;
|
|
323
|
+
key = SHARE_KEY;
|
|
324
|
+
}
|
|
297
325
|
init(proto);
|
|
298
326
|
proto[PHECDA_KEY].__CLEAR_KEY.add(key);
|
|
299
327
|
}
|
|
@@ -434,7 +462,7 @@ function snapShot(data) {
|
|
|
434
462
|
}
|
|
435
463
|
__name(snapShot, "snapShot");
|
|
436
464
|
function addDecoToClass(c, key, handler) {
|
|
437
|
-
handler(key
|
|
465
|
+
handler(key ? c.prototype : c, key);
|
|
438
466
|
}
|
|
439
467
|
__name(addDecoToClass, "addDecoToClass");
|
|
440
468
|
function Pipeline(...decos) {
|
|
@@ -448,6 +476,18 @@ function isAsyncFunc(fn) {
|
|
|
448
476
|
return fn[Symbol.toStringTag] === "AsyncFunction";
|
|
449
477
|
}
|
|
450
478
|
__name(isAsyncFunc, "isAsyncFunc");
|
|
479
|
+
function setPropertyState(target, k, setter) {
|
|
480
|
+
setStateKey(target, k);
|
|
481
|
+
const state = getOwnState(target, k) || {};
|
|
482
|
+
setter(state);
|
|
483
|
+
setState(target, k, state);
|
|
484
|
+
}
|
|
485
|
+
__name(setPropertyState, "setPropertyState");
|
|
486
|
+
function getShareState(target, getter) {
|
|
487
|
+
const state = getOwnState(target, SHARE_KEY) || {};
|
|
488
|
+
return getter(state);
|
|
489
|
+
}
|
|
490
|
+
__name(getShareState, "getShareState");
|
|
451
491
|
|
|
452
492
|
// src/di.ts
|
|
453
493
|
var DataMap = {};
|
|
@@ -460,15 +500,15 @@ function Inject(key) {
|
|
|
460
500
|
}
|
|
461
501
|
__name(Inject, "Inject");
|
|
462
502
|
var activeInstance = {};
|
|
463
|
-
function
|
|
503
|
+
function setInject(key, value) {
|
|
464
504
|
activeInstance[key] = value;
|
|
465
505
|
return activeInstance;
|
|
466
506
|
}
|
|
467
|
-
__name(
|
|
468
|
-
function
|
|
507
|
+
__name(setInject, "setInject");
|
|
508
|
+
function getInject(key) {
|
|
469
509
|
return activeInstance[key];
|
|
470
510
|
}
|
|
471
|
-
__name(
|
|
511
|
+
__name(getInject, "getInject");
|
|
472
512
|
|
|
473
513
|
// src/decorators/function.ts
|
|
474
514
|
function Isolate(model) {
|
|
@@ -490,9 +530,8 @@ function Unique(desc) {
|
|
|
490
530
|
__name(Unique, "Unique");
|
|
491
531
|
function Assign(cb) {
|
|
492
532
|
return (model) => {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
setHandler(model.prototype, SHARE_KEY, {
|
|
533
|
+
setStateKey(model);
|
|
534
|
+
setHandler(model, void 0, {
|
|
496
535
|
init: async (instance) => {
|
|
497
536
|
const value = await cb(instance);
|
|
498
537
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
@@ -505,9 +544,8 @@ function Assign(cb) {
|
|
|
505
544
|
}
|
|
506
545
|
__name(Assign, "Assign");
|
|
507
546
|
function Global(model) {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
setHandler(model.prototype, SHARE_KEY, {
|
|
547
|
+
setStateKey(model);
|
|
548
|
+
setHandler(model, void 0, {
|
|
511
549
|
init: async (instance) => {
|
|
512
550
|
const tag = instance[PHECDA_KEY].__TAG__;
|
|
513
551
|
if (!tag)
|
|
@@ -600,7 +638,7 @@ function Watcher(eventName, options) {
|
|
|
600
638
|
setStateKey(proto, key);
|
|
601
639
|
setHandler(proto, key, {
|
|
602
640
|
init(instance) {
|
|
603
|
-
return cb =
|
|
641
|
+
return cb = getInject("watcher")?.({
|
|
604
642
|
eventName,
|
|
605
643
|
instance,
|
|
606
644
|
key,
|
|
@@ -635,44 +673,26 @@ function Effect(cb) {
|
|
|
635
673
|
};
|
|
636
674
|
}
|
|
637
675
|
__name(Effect, "Effect");
|
|
638
|
-
function Storage({ key: storeKey,
|
|
639
|
-
if (!
|
|
640
|
-
|
|
641
|
-
if (!
|
|
642
|
-
|
|
676
|
+
function Storage({ key: storeKey, json, stringify } = {}) {
|
|
677
|
+
if (!json)
|
|
678
|
+
json = /* @__PURE__ */ __name((v) => JSON.parse(v), "json");
|
|
679
|
+
if (!stringify)
|
|
680
|
+
stringify = /* @__PURE__ */ __name((v) => JSON.stringify(v), "stringify");
|
|
643
681
|
return (proto, key) => {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
}
|
|
659
|
-
});
|
|
660
|
-
} else {
|
|
661
|
-
init(proto.prototype);
|
|
662
|
-
tag = storeKey || getTag(proto);
|
|
663
|
-
setStateKey(proto.prototype, SHARE_KEY);
|
|
664
|
-
setHandler(proto.prototype, SHARE_KEY, {
|
|
665
|
-
init: (instance) => {
|
|
666
|
-
return getKey("storage")?.({
|
|
667
|
-
instance,
|
|
668
|
-
key,
|
|
669
|
-
tag,
|
|
670
|
-
toJSON,
|
|
671
|
-
toString
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
});
|
|
675
|
-
}
|
|
682
|
+
const tag = storeKey || getTag(proto);
|
|
683
|
+
init(proto);
|
|
684
|
+
setStateKey(proto, key);
|
|
685
|
+
setHandler(proto, key, {
|
|
686
|
+
init: (instance) => {
|
|
687
|
+
return getInject("storage")?.({
|
|
688
|
+
instance,
|
|
689
|
+
key,
|
|
690
|
+
tag,
|
|
691
|
+
toJSON: json,
|
|
692
|
+
toString: stringify
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
});
|
|
676
696
|
};
|
|
677
697
|
}
|
|
678
698
|
__name(Storage, "Storage");
|
|
@@ -709,18 +729,18 @@ __name(Storage, "Storage");
|
|
|
709
729
|
getBind,
|
|
710
730
|
getExposeKey,
|
|
711
731
|
getHandler,
|
|
712
|
-
|
|
732
|
+
getInject,
|
|
713
733
|
getOwnExposeKey,
|
|
714
734
|
getOwnHandler,
|
|
715
735
|
getOwnIgnoreKey,
|
|
716
736
|
getOwnState,
|
|
717
737
|
getOwnStateKey,
|
|
718
738
|
getPhecdaFromTarget,
|
|
739
|
+
getShareState,
|
|
719
740
|
getState,
|
|
720
741
|
getStateKey,
|
|
721
742
|
getTag,
|
|
722
743
|
init,
|
|
723
|
-
injectKey,
|
|
724
744
|
invokeHandler,
|
|
725
745
|
isAsyncFunc,
|
|
726
746
|
isPhecda,
|
|
@@ -729,6 +749,8 @@ __name(Storage, "Storage");
|
|
|
729
749
|
setExposeKey,
|
|
730
750
|
setHandler,
|
|
731
751
|
setIgnoreKey,
|
|
752
|
+
setInject,
|
|
753
|
+
setPropertyState,
|
|
732
754
|
setState,
|
|
733
755
|
setStateKey,
|
|
734
756
|
snapShot,
|
package/dist/index.mjs
CHANGED
|
@@ -34,22 +34,38 @@ function getPhecdaFromTarget(target) {
|
|
|
34
34
|
}
|
|
35
35
|
__name(getPhecdaFromTarget, "getPhecdaFromTarget");
|
|
36
36
|
function setStateKey(proto, key) {
|
|
37
|
+
if (!key) {
|
|
38
|
+
key = SHARE_KEY;
|
|
39
|
+
proto = proto.prototype;
|
|
40
|
+
}
|
|
37
41
|
init(proto);
|
|
38
42
|
proto[PHECDA_KEY].__STATE_KEY.add(key);
|
|
39
43
|
setExposeKey(proto, key);
|
|
40
44
|
}
|
|
41
45
|
__name(setStateKey, "setStateKey");
|
|
42
46
|
function setExposeKey(proto, key) {
|
|
47
|
+
if (!key) {
|
|
48
|
+
key = SHARE_KEY;
|
|
49
|
+
proto = proto.prototype;
|
|
50
|
+
}
|
|
43
51
|
init(proto);
|
|
44
52
|
proto[PHECDA_KEY].__EXPOSE_KEY.add(key);
|
|
45
53
|
}
|
|
46
54
|
__name(setExposeKey, "setExposeKey");
|
|
47
55
|
function setIgnoreKey(proto, key) {
|
|
56
|
+
if (!key) {
|
|
57
|
+
key = SHARE_KEY;
|
|
58
|
+
proto = proto.prototype;
|
|
59
|
+
}
|
|
48
60
|
init(proto);
|
|
49
61
|
proto[PHECDA_KEY].__IGNORE_KEY.add(key);
|
|
50
62
|
}
|
|
51
63
|
__name(setIgnoreKey, "setIgnoreKey");
|
|
52
64
|
function setHandler(proto, key, handler) {
|
|
65
|
+
if (!key) {
|
|
66
|
+
key = SHARE_KEY;
|
|
67
|
+
proto = proto.prototype;
|
|
68
|
+
}
|
|
53
69
|
init(proto);
|
|
54
70
|
if (!proto[PHECDA_KEY].__STATE_HANDLER__.has(key))
|
|
55
71
|
proto[PHECDA_KEY].__STATE_HANDLER__.set(key, [
|
|
@@ -60,6 +76,10 @@ function setHandler(proto, key, handler) {
|
|
|
60
76
|
}
|
|
61
77
|
__name(setHandler, "setHandler");
|
|
62
78
|
function setState(proto, key, state) {
|
|
79
|
+
if (!key) {
|
|
80
|
+
key = SHARE_KEY;
|
|
81
|
+
proto = proto.prototype;
|
|
82
|
+
}
|
|
63
83
|
init(proto);
|
|
64
84
|
const namespace = proto[PHECDA_KEY].__STATE_NAMESPACE__;
|
|
65
85
|
namespace.set(key, state);
|
|
@@ -136,7 +156,7 @@ function getHandler(target, key) {
|
|
|
136
156
|
];
|
|
137
157
|
}
|
|
138
158
|
__name(getHandler, "getHandler");
|
|
139
|
-
function getState(target, key) {
|
|
159
|
+
function getState(target, key = SHARE_KEY) {
|
|
140
160
|
let proto = getPhecdaFromTarget(target);
|
|
141
161
|
let ret = {};
|
|
142
162
|
while (proto?.[PHECDA_KEY]) {
|
|
@@ -155,7 +175,7 @@ function getState(target, key) {
|
|
|
155
175
|
return ret;
|
|
156
176
|
}
|
|
157
177
|
__name(getState, "getState");
|
|
158
|
-
function getOwnState(target, key) {
|
|
178
|
+
function getOwnState(target, key = SHARE_KEY) {
|
|
159
179
|
const proto = getPhecdaFromTarget(target);
|
|
160
180
|
return proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key) || {};
|
|
161
181
|
}
|
|
@@ -170,13 +190,11 @@ function invokeHandler(event, module) {
|
|
|
170
190
|
__name(invokeHandler, "invokeHandler");
|
|
171
191
|
function set(proto, key, value) {
|
|
172
192
|
init(proto);
|
|
173
|
-
|
|
174
|
-
[`__${key.toUpperCase()}__`]: value
|
|
175
|
-
});
|
|
193
|
+
proto[`__${key.toUpperCase()}__`] = value;
|
|
176
194
|
}
|
|
177
195
|
__name(set, "set");
|
|
178
196
|
function get(proto, key) {
|
|
179
|
-
return
|
|
197
|
+
return proto[`__${key.toUpperCase()}__`];
|
|
180
198
|
}
|
|
181
199
|
__name(get, "get");
|
|
182
200
|
|
|
@@ -208,11 +226,19 @@ function Bind(value) {
|
|
|
208
226
|
};
|
|
209
227
|
}
|
|
210
228
|
__name(Bind, "Bind");
|
|
211
|
-
function Ignore(proto, key
|
|
229
|
+
function Ignore(proto, key) {
|
|
230
|
+
if (!key) {
|
|
231
|
+
proto = proto.prototype;
|
|
232
|
+
key = SHARE_KEY;
|
|
233
|
+
}
|
|
212
234
|
setIgnoreKey(proto, key);
|
|
213
235
|
}
|
|
214
236
|
__name(Ignore, "Ignore");
|
|
215
|
-
function Clear(proto, key
|
|
237
|
+
function Clear(proto, key) {
|
|
238
|
+
if (!key) {
|
|
239
|
+
proto = proto.prototype;
|
|
240
|
+
key = SHARE_KEY;
|
|
241
|
+
}
|
|
216
242
|
init(proto);
|
|
217
243
|
proto[PHECDA_KEY].__CLEAR_KEY.add(key);
|
|
218
244
|
}
|
|
@@ -353,7 +379,7 @@ function snapShot(data) {
|
|
|
353
379
|
}
|
|
354
380
|
__name(snapShot, "snapShot");
|
|
355
381
|
function addDecoToClass(c, key, handler) {
|
|
356
|
-
handler(key
|
|
382
|
+
handler(key ? c.prototype : c, key);
|
|
357
383
|
}
|
|
358
384
|
__name(addDecoToClass, "addDecoToClass");
|
|
359
385
|
function Pipeline(...decos) {
|
|
@@ -367,6 +393,18 @@ function isAsyncFunc(fn) {
|
|
|
367
393
|
return fn[Symbol.toStringTag] === "AsyncFunction";
|
|
368
394
|
}
|
|
369
395
|
__name(isAsyncFunc, "isAsyncFunc");
|
|
396
|
+
function setPropertyState(target, k, setter) {
|
|
397
|
+
setStateKey(target, k);
|
|
398
|
+
const state = getOwnState(target, k) || {};
|
|
399
|
+
setter(state);
|
|
400
|
+
setState(target, k, state);
|
|
401
|
+
}
|
|
402
|
+
__name(setPropertyState, "setPropertyState");
|
|
403
|
+
function getShareState(target, getter) {
|
|
404
|
+
const state = getOwnState(target, SHARE_KEY) || {};
|
|
405
|
+
return getter(state);
|
|
406
|
+
}
|
|
407
|
+
__name(getShareState, "getShareState");
|
|
370
408
|
|
|
371
409
|
// src/di.ts
|
|
372
410
|
var DataMap = {};
|
|
@@ -379,15 +417,15 @@ function Inject(key) {
|
|
|
379
417
|
}
|
|
380
418
|
__name(Inject, "Inject");
|
|
381
419
|
var activeInstance = {};
|
|
382
|
-
function
|
|
420
|
+
function setInject(key, value) {
|
|
383
421
|
activeInstance[key] = value;
|
|
384
422
|
return activeInstance;
|
|
385
423
|
}
|
|
386
|
-
__name(
|
|
387
|
-
function
|
|
424
|
+
__name(setInject, "setInject");
|
|
425
|
+
function getInject(key) {
|
|
388
426
|
return activeInstance[key];
|
|
389
427
|
}
|
|
390
|
-
__name(
|
|
428
|
+
__name(getInject, "getInject");
|
|
391
429
|
|
|
392
430
|
// src/decorators/function.ts
|
|
393
431
|
function Isolate(model) {
|
|
@@ -409,9 +447,8 @@ function Unique(desc) {
|
|
|
409
447
|
__name(Unique, "Unique");
|
|
410
448
|
function Assign(cb) {
|
|
411
449
|
return (model) => {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
setHandler(model.prototype, SHARE_KEY, {
|
|
450
|
+
setStateKey(model);
|
|
451
|
+
setHandler(model, void 0, {
|
|
415
452
|
init: async (instance) => {
|
|
416
453
|
const value = await cb(instance);
|
|
417
454
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
@@ -424,9 +461,8 @@ function Assign(cb) {
|
|
|
424
461
|
}
|
|
425
462
|
__name(Assign, "Assign");
|
|
426
463
|
function Global(model) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
setHandler(model.prototype, SHARE_KEY, {
|
|
464
|
+
setStateKey(model);
|
|
465
|
+
setHandler(model, void 0, {
|
|
430
466
|
init: async (instance) => {
|
|
431
467
|
const tag = instance[PHECDA_KEY].__TAG__;
|
|
432
468
|
if (!tag)
|
|
@@ -519,7 +555,7 @@ function Watcher(eventName, options) {
|
|
|
519
555
|
setStateKey(proto, key);
|
|
520
556
|
setHandler(proto, key, {
|
|
521
557
|
init(instance) {
|
|
522
|
-
return cb =
|
|
558
|
+
return cb = getInject("watcher")?.({
|
|
523
559
|
eventName,
|
|
524
560
|
instance,
|
|
525
561
|
key,
|
|
@@ -554,44 +590,26 @@ function Effect(cb) {
|
|
|
554
590
|
};
|
|
555
591
|
}
|
|
556
592
|
__name(Effect, "Effect");
|
|
557
|
-
function Storage({ key: storeKey,
|
|
558
|
-
if (!
|
|
559
|
-
|
|
560
|
-
if (!
|
|
561
|
-
|
|
593
|
+
function Storage({ key: storeKey, json, stringify } = {}) {
|
|
594
|
+
if (!json)
|
|
595
|
+
json = /* @__PURE__ */ __name((v) => JSON.parse(v), "json");
|
|
596
|
+
if (!stringify)
|
|
597
|
+
stringify = /* @__PURE__ */ __name((v) => JSON.stringify(v), "stringify");
|
|
562
598
|
return (proto, key) => {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
}
|
|
578
|
-
});
|
|
579
|
-
} else {
|
|
580
|
-
init(proto.prototype);
|
|
581
|
-
tag = storeKey || getTag(proto);
|
|
582
|
-
setStateKey(proto.prototype, SHARE_KEY);
|
|
583
|
-
setHandler(proto.prototype, SHARE_KEY, {
|
|
584
|
-
init: (instance) => {
|
|
585
|
-
return getKey("storage")?.({
|
|
586
|
-
instance,
|
|
587
|
-
key,
|
|
588
|
-
tag,
|
|
589
|
-
toJSON,
|
|
590
|
-
toString
|
|
591
|
-
});
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
}
|
|
599
|
+
const tag = storeKey || getTag(proto);
|
|
600
|
+
init(proto);
|
|
601
|
+
setStateKey(proto, key);
|
|
602
|
+
setHandler(proto, key, {
|
|
603
|
+
init: (instance) => {
|
|
604
|
+
return getInject("storage")?.({
|
|
605
|
+
instance,
|
|
606
|
+
key,
|
|
607
|
+
tag,
|
|
608
|
+
toJSON: json,
|
|
609
|
+
toString: stringify
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
});
|
|
595
613
|
};
|
|
596
614
|
}
|
|
597
615
|
__name(Storage, "Storage");
|
|
@@ -627,18 +645,18 @@ export {
|
|
|
627
645
|
getBind,
|
|
628
646
|
getExposeKey,
|
|
629
647
|
getHandler,
|
|
630
|
-
|
|
648
|
+
getInject,
|
|
631
649
|
getOwnExposeKey,
|
|
632
650
|
getOwnHandler,
|
|
633
651
|
getOwnIgnoreKey,
|
|
634
652
|
getOwnState,
|
|
635
653
|
getOwnStateKey,
|
|
636
654
|
getPhecdaFromTarget,
|
|
655
|
+
getShareState,
|
|
637
656
|
getState,
|
|
638
657
|
getStateKey,
|
|
639
658
|
getTag,
|
|
640
659
|
init,
|
|
641
|
-
injectKey,
|
|
642
660
|
invokeHandler,
|
|
643
661
|
isAsyncFunc,
|
|
644
662
|
isPhecda,
|
|
@@ -647,6 +665,8 @@ export {
|
|
|
647
665
|
setExposeKey,
|
|
648
666
|
setHandler,
|
|
649
667
|
setIgnoreKey,
|
|
668
|
+
setInject,
|
|
669
|
+
setPropertyState,
|
|
650
670
|
setState,
|
|
651
671
|
setStateKey,
|
|
652
672
|
snapShot,
|