phecda-core 3.0.0-beta.15 → 3.0.0-beta.16
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 +9 -9
- package/dist/index.js +33 -51
- package/dist/index.mjs +31 -49
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -26,8 +26,8 @@ declare function getHandler(target: any, key: PropertyKey): any[];
|
|
|
26
26
|
declare function getState(target: any, key: PropertyKey): any;
|
|
27
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
|
|
|
@@ -111,7 +111,7 @@ declare const DataMap: InjectData;
|
|
|
111
111
|
declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
|
|
112
112
|
declare function Inject<K extends keyof InjectData>(key: K): InjectData[K];
|
|
113
113
|
declare const activeInstance: Record<string, any>;
|
|
114
|
-
declare function
|
|
115
|
-
declare function
|
|
114
|
+
declare function setInject(key: string, value: any): Record<string, any>;
|
|
115
|
+
declare function getInject(key: string): any;
|
|
116
116
|
|
|
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,
|
|
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, getInject, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnState, getOwnStateKey, getPhecdaFromTarget, getState, getStateKey, getTag, init, invokeHandler, isAsyncFunc, isPhecda, plainToClass, set, setExposeKey, setHandler, setIgnoreKey, setInject, setState, setStateKey, snapShot, transformInstance, transformInstanceAsync, transformProperty, transformPropertyAsync };
|
package/dist/index.js
CHANGED
|
@@ -52,7 +52,7 @@ __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,
|
|
@@ -63,7 +63,6 @@ __export(src_exports, {
|
|
|
63
63
|
getStateKey: () => getStateKey,
|
|
64
64
|
getTag: () => getTag,
|
|
65
65
|
init: () => init,
|
|
66
|
-
injectKey: () => injectKey,
|
|
67
66
|
invokeHandler: () => invokeHandler,
|
|
68
67
|
isAsyncFunc: () => isAsyncFunc,
|
|
69
68
|
isPhecda: () => isPhecda,
|
|
@@ -72,6 +71,7 @@ __export(src_exports, {
|
|
|
72
71
|
setExposeKey: () => setExposeKey,
|
|
73
72
|
setHandler: () => setHandler,
|
|
74
73
|
setIgnoreKey: () => setIgnoreKey,
|
|
74
|
+
setInject: () => setInject,
|
|
75
75
|
setState: () => setState,
|
|
76
76
|
setStateKey: () => setStateKey,
|
|
77
77
|
snapShot: () => snapShot,
|
|
@@ -251,13 +251,11 @@ function invokeHandler(event, module2) {
|
|
|
251
251
|
__name(invokeHandler, "invokeHandler");
|
|
252
252
|
function set(proto, key, value) {
|
|
253
253
|
init(proto);
|
|
254
|
-
|
|
255
|
-
[`__${key.toUpperCase()}__`]: value
|
|
256
|
-
});
|
|
254
|
+
proto[`__${key.toUpperCase()}__`] = value;
|
|
257
255
|
}
|
|
258
256
|
__name(set, "set");
|
|
259
257
|
function get(proto, key) {
|
|
260
|
-
return
|
|
258
|
+
return proto[`__${key.toUpperCase()}__`];
|
|
261
259
|
}
|
|
262
260
|
__name(get, "get");
|
|
263
261
|
|
|
@@ -460,15 +458,15 @@ function Inject(key) {
|
|
|
460
458
|
}
|
|
461
459
|
__name(Inject, "Inject");
|
|
462
460
|
var activeInstance = {};
|
|
463
|
-
function
|
|
461
|
+
function setInject(key, value) {
|
|
464
462
|
activeInstance[key] = value;
|
|
465
463
|
return activeInstance;
|
|
466
464
|
}
|
|
467
|
-
__name(
|
|
468
|
-
function
|
|
465
|
+
__name(setInject, "setInject");
|
|
466
|
+
function getInject(key) {
|
|
469
467
|
return activeInstance[key];
|
|
470
468
|
}
|
|
471
|
-
__name(
|
|
469
|
+
__name(getInject, "getInject");
|
|
472
470
|
|
|
473
471
|
// src/decorators/function.ts
|
|
474
472
|
function Isolate(model) {
|
|
@@ -600,7 +598,7 @@ function Watcher(eventName, options) {
|
|
|
600
598
|
setStateKey(proto, key);
|
|
601
599
|
setHandler(proto, key, {
|
|
602
600
|
init(instance) {
|
|
603
|
-
return cb =
|
|
601
|
+
return cb = getInject("watcher")?.({
|
|
604
602
|
eventName,
|
|
605
603
|
instance,
|
|
606
604
|
key,
|
|
@@ -635,44 +633,28 @@ function Effect(cb) {
|
|
|
635
633
|
};
|
|
636
634
|
}
|
|
637
635
|
__name(Effect, "Effect");
|
|
638
|
-
function Storage({ key: storeKey,
|
|
639
|
-
if (!
|
|
640
|
-
|
|
641
|
-
if (!
|
|
642
|
-
|
|
643
|
-
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
|
-
}
|
|
636
|
+
function Storage({ key: storeKey, json, stringify } = {}) {
|
|
637
|
+
if (!json)
|
|
638
|
+
json = /* @__PURE__ */ __name((v) => JSON.parse(v), "json");
|
|
639
|
+
if (!stringify)
|
|
640
|
+
stringify = /* @__PURE__ */ __name((v) => JSON.stringify(v), "stringify");
|
|
641
|
+
return (proto, key = SHARE_KEY) => {
|
|
642
|
+
if (typeof proto === "function")
|
|
643
|
+
proto = proto.prototype;
|
|
644
|
+
const tag = storeKey || getTag(proto);
|
|
645
|
+
init(proto);
|
|
646
|
+
setStateKey(proto, key);
|
|
647
|
+
setHandler(proto, key, {
|
|
648
|
+
init: (instance) => {
|
|
649
|
+
return getInject("storage")?.({
|
|
650
|
+
instance,
|
|
651
|
+
key,
|
|
652
|
+
tag,
|
|
653
|
+
toJSON: json,
|
|
654
|
+
toString: stringify
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
});
|
|
676
658
|
};
|
|
677
659
|
}
|
|
678
660
|
__name(Storage, "Storage");
|
|
@@ -709,7 +691,7 @@ __name(Storage, "Storage");
|
|
|
709
691
|
getBind,
|
|
710
692
|
getExposeKey,
|
|
711
693
|
getHandler,
|
|
712
|
-
|
|
694
|
+
getInject,
|
|
713
695
|
getOwnExposeKey,
|
|
714
696
|
getOwnHandler,
|
|
715
697
|
getOwnIgnoreKey,
|
|
@@ -720,7 +702,6 @@ __name(Storage, "Storage");
|
|
|
720
702
|
getStateKey,
|
|
721
703
|
getTag,
|
|
722
704
|
init,
|
|
723
|
-
injectKey,
|
|
724
705
|
invokeHandler,
|
|
725
706
|
isAsyncFunc,
|
|
726
707
|
isPhecda,
|
|
@@ -729,6 +710,7 @@ __name(Storage, "Storage");
|
|
|
729
710
|
setExposeKey,
|
|
730
711
|
setHandler,
|
|
731
712
|
setIgnoreKey,
|
|
713
|
+
setInject,
|
|
732
714
|
setState,
|
|
733
715
|
setStateKey,
|
|
734
716
|
snapShot,
|
package/dist/index.mjs
CHANGED
|
@@ -170,13 +170,11 @@ function invokeHandler(event, module) {
|
|
|
170
170
|
__name(invokeHandler, "invokeHandler");
|
|
171
171
|
function set(proto, key, value) {
|
|
172
172
|
init(proto);
|
|
173
|
-
|
|
174
|
-
[`__${key.toUpperCase()}__`]: value
|
|
175
|
-
});
|
|
173
|
+
proto[`__${key.toUpperCase()}__`] = value;
|
|
176
174
|
}
|
|
177
175
|
__name(set, "set");
|
|
178
176
|
function get(proto, key) {
|
|
179
|
-
return
|
|
177
|
+
return proto[`__${key.toUpperCase()}__`];
|
|
180
178
|
}
|
|
181
179
|
__name(get, "get");
|
|
182
180
|
|
|
@@ -379,15 +377,15 @@ function Inject(key) {
|
|
|
379
377
|
}
|
|
380
378
|
__name(Inject, "Inject");
|
|
381
379
|
var activeInstance = {};
|
|
382
|
-
function
|
|
380
|
+
function setInject(key, value) {
|
|
383
381
|
activeInstance[key] = value;
|
|
384
382
|
return activeInstance;
|
|
385
383
|
}
|
|
386
|
-
__name(
|
|
387
|
-
function
|
|
384
|
+
__name(setInject, "setInject");
|
|
385
|
+
function getInject(key) {
|
|
388
386
|
return activeInstance[key];
|
|
389
387
|
}
|
|
390
|
-
__name(
|
|
388
|
+
__name(getInject, "getInject");
|
|
391
389
|
|
|
392
390
|
// src/decorators/function.ts
|
|
393
391
|
function Isolate(model) {
|
|
@@ -519,7 +517,7 @@ function Watcher(eventName, options) {
|
|
|
519
517
|
setStateKey(proto, key);
|
|
520
518
|
setHandler(proto, key, {
|
|
521
519
|
init(instance) {
|
|
522
|
-
return cb =
|
|
520
|
+
return cb = getInject("watcher")?.({
|
|
523
521
|
eventName,
|
|
524
522
|
instance,
|
|
525
523
|
key,
|
|
@@ -554,44 +552,28 @@ function Effect(cb) {
|
|
|
554
552
|
};
|
|
555
553
|
}
|
|
556
554
|
__name(Effect, "Effect");
|
|
557
|
-
function Storage({ key: storeKey,
|
|
558
|
-
if (!
|
|
559
|
-
|
|
560
|
-
if (!
|
|
561
|
-
|
|
562
|
-
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
|
-
}
|
|
555
|
+
function Storage({ key: storeKey, json, stringify } = {}) {
|
|
556
|
+
if (!json)
|
|
557
|
+
json = /* @__PURE__ */ __name((v) => JSON.parse(v), "json");
|
|
558
|
+
if (!stringify)
|
|
559
|
+
stringify = /* @__PURE__ */ __name((v) => JSON.stringify(v), "stringify");
|
|
560
|
+
return (proto, key = SHARE_KEY) => {
|
|
561
|
+
if (typeof proto === "function")
|
|
562
|
+
proto = proto.prototype;
|
|
563
|
+
const tag = storeKey || getTag(proto);
|
|
564
|
+
init(proto);
|
|
565
|
+
setStateKey(proto, key);
|
|
566
|
+
setHandler(proto, key, {
|
|
567
|
+
init: (instance) => {
|
|
568
|
+
return getInject("storage")?.({
|
|
569
|
+
instance,
|
|
570
|
+
key,
|
|
571
|
+
tag,
|
|
572
|
+
toJSON: json,
|
|
573
|
+
toString: stringify
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
});
|
|
595
577
|
};
|
|
596
578
|
}
|
|
597
579
|
__name(Storage, "Storage");
|
|
@@ -627,7 +609,7 @@ export {
|
|
|
627
609
|
getBind,
|
|
628
610
|
getExposeKey,
|
|
629
611
|
getHandler,
|
|
630
|
-
|
|
612
|
+
getInject,
|
|
631
613
|
getOwnExposeKey,
|
|
632
614
|
getOwnHandler,
|
|
633
615
|
getOwnIgnoreKey,
|
|
@@ -638,7 +620,6 @@ export {
|
|
|
638
620
|
getStateKey,
|
|
639
621
|
getTag,
|
|
640
622
|
init,
|
|
641
|
-
injectKey,
|
|
642
623
|
invokeHandler,
|
|
643
624
|
isAsyncFunc,
|
|
644
625
|
isPhecda,
|
|
@@ -647,6 +628,7 @@ export {
|
|
|
647
628
|
setExposeKey,
|
|
648
629
|
setHandler,
|
|
649
630
|
setIgnoreKey,
|
|
631
|
+
setInject,
|
|
650
632
|
setState,
|
|
651
633
|
setStateKey,
|
|
652
634
|
snapShot,
|