phecda-core 3.0.0-alpha.1 → 3.0.0-alpha.10
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 +37 -15
- package/dist/index.js +72 -49
- package/dist/index.mjs +68 -46
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ interface NameSpace {
|
|
|
4
4
|
interface InjectData {
|
|
5
5
|
[key: string]: any;
|
|
6
6
|
}
|
|
7
|
+
type Construct<T = any> = new (...args: any[]) => T;
|
|
8
|
+
type AbConstruct<T = any> = abstract new (...args: any[]) => T;
|
|
7
9
|
interface Handler {
|
|
8
10
|
[key: string]: any;
|
|
9
11
|
}
|
|
@@ -24,13 +26,15 @@ interface Events {
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
declare function Init(proto: any, key: PropertyKey): void;
|
|
29
|
+
declare function Unmount(proto: any, key: PropertyKey): void;
|
|
27
30
|
declare function Bind(value: any): (proto: any, k: PropertyKey) => void;
|
|
28
31
|
declare function Ignore(proto: any, key: PropertyKey): void;
|
|
29
32
|
declare function Clear(proto: any, key: PropertyKey): void;
|
|
30
33
|
declare function Err<Fn extends (...args: any) => any>(cb: Fn): (proto: any, key: PropertyKey) => void;
|
|
31
34
|
declare function Expose(proto: any, key: PropertyKey): void;
|
|
32
|
-
declare function To(
|
|
33
|
-
declare function Tag(tag:
|
|
35
|
+
declare function To(...callbacks: ((arg: any, instance: any, key: string) => any)[]): (proto: any, key: PropertyKey) => void;
|
|
36
|
+
declare function Tag(tag: PropertyKey): (module: any) => void;
|
|
37
|
+
declare function Unique(desc?: string): (module: any) => void;
|
|
34
38
|
declare function Assign(cb: (instance?: any) => any): (module: any) => void;
|
|
35
39
|
declare function Global(module: any): void;
|
|
36
40
|
declare function Empty(module: any): void;
|
|
@@ -38,22 +42,22 @@ declare const DataMap: InjectData;
|
|
|
38
42
|
declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
|
|
39
43
|
declare function Inject<K extends keyof InjectData>(key: K): InjectData[K];
|
|
40
44
|
declare function Nested<M extends new (...args: any) => any>(module: M): (proto: any, key: PropertyKey) => void;
|
|
45
|
+
declare function Isolate(): (target: any) => void;
|
|
41
46
|
|
|
42
|
-
declare function getTag<M extends
|
|
43
|
-
declare function
|
|
44
|
-
declare function
|
|
45
|
-
declare function
|
|
46
|
-
declare function transformClass<M extends new (...args: any) => any>(instance: InstanceType<M>, force?: boolean): Promise<string[]>;
|
|
47
|
+
declare function getTag<M extends Construct | AbConstruct>(moduleOrInstance: M | InstanceType<M>): PropertyKey;
|
|
48
|
+
declare function getBind<M extends Construct | AbConstruct>(module: M): any;
|
|
49
|
+
declare function plainToClass<M extends Construct, Data extends Record<PropertyKey, any>>(module: M, input: Data): InstanceType<M>;
|
|
50
|
+
declare function transformClass<M extends Construct>(instance: InstanceType<M>, force?: boolean): Promise<string[]>;
|
|
47
51
|
declare function classToValue<M>(instance: M): ClassValue<M>;
|
|
48
|
-
declare function snapShot<T extends
|
|
52
|
+
declare function snapShot<T extends Construct>(data: InstanceType<T>): {
|
|
49
53
|
data: InstanceType<T>;
|
|
50
54
|
clear(): void;
|
|
51
55
|
apply(): void;
|
|
52
56
|
};
|
|
53
|
-
declare function addDecoToClass<M extends
|
|
57
|
+
declare function addDecoToClass<M extends Construct | AbConstruct>(c: M, key: keyof InstanceType<M> | string, handler: ((target: any, key: PropertyKey) => void), type?: 'property' | 'class'): void;
|
|
54
58
|
declare function Pipeline(...decos: ((...args: any) => void)[]): (...args: any) => void;
|
|
55
59
|
|
|
56
|
-
declare function isPhecda(module: any):
|
|
60
|
+
declare function isPhecda(module: any): module is Construct;
|
|
57
61
|
declare const SHARE_KEY: unique symbol;
|
|
58
62
|
declare function init(proto: Phecda): void;
|
|
59
63
|
declare function setVar(proto: Phecda, key: PropertyKey): void;
|
|
@@ -70,16 +74,34 @@ declare function getHandler(instance: Phecda, key: PropertyKey): any[];
|
|
|
70
74
|
declare function setState(proto: Phecda, key: PropertyKey, state: Record<string, any>): void;
|
|
71
75
|
declare function getOwnState(instance: Phecda, key: PropertyKey): Object;
|
|
72
76
|
declare function getState(instance: Phecda, key: PropertyKey): any;
|
|
73
|
-
declare function
|
|
74
|
-
declare function registerAsync(instance: Phecda): Promise<void>;
|
|
77
|
+
declare function invokeHandler(event: string, instance: Phecda): Promise<any[]>;
|
|
75
78
|
|
|
79
|
+
interface StorageParam {
|
|
80
|
+
key?: string;
|
|
81
|
+
instance: any;
|
|
82
|
+
tag: string;
|
|
83
|
+
toJSON: (str: string) => any;
|
|
84
|
+
toString: (arg: any) => string;
|
|
85
|
+
}
|
|
86
|
+
interface WatcherParam {
|
|
87
|
+
key: string;
|
|
88
|
+
instance: any;
|
|
89
|
+
eventName: string;
|
|
90
|
+
options?: {
|
|
91
|
+
once?: boolean;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
76
94
|
declare const activeInstance: Record<string, any>;
|
|
77
95
|
declare function injectProperty(key: string, value: any): Record<string, any>;
|
|
78
96
|
declare function getProperty(key: string): any;
|
|
79
97
|
declare function Watcher(eventName: keyof Events, options?: {
|
|
80
|
-
once
|
|
98
|
+
once?: boolean;
|
|
81
99
|
}): (proto: any, key: string) => void;
|
|
82
100
|
declare function Effect(eventName: string, options?: any): (proto: any, key: string) => void;
|
|
83
|
-
declare function Storage(
|
|
101
|
+
declare function Storage({ key: storeKey, toJSON, toString }?: {
|
|
102
|
+
toJSON?: (str: string) => any;
|
|
103
|
+
toString?: (arg: any) => string;
|
|
104
|
+
key?: string;
|
|
105
|
+
}): (proto: any, key?: PropertyKey) => void;
|
|
84
106
|
|
|
85
|
-
export { Assign, Bind, ClassValue, Clear, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, NameSpace, Nested, Phecda, Pipeline, Provide, SHARE_KEY, Storage, Tag, To, Watcher, activeInstance, addDecoToClass, classToValue, getBind, getExposeKey, getHandler, getModuleState, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnModuleState, getOwnState, getProperty, getState,
|
|
107
|
+
export { AbConstruct, Assign, Bind, ClassValue, Clear, Construct, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, Isolate, NameSpace, Nested, Phecda, Pipeline, Provide, SHARE_KEY, Storage, StorageParam, Tag, To, Unique, Unmount, Watcher, WatcherParam, activeInstance, addDecoToClass, classToValue, getBind, getExposeKey, getHandler, getModuleState, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnModuleState, getOwnState, getProperty, getState, getTag, init, injectProperty, invokeHandler, isPhecda, plainToClass, regisHandler, setExposeKey, setIgnoreKey, setState, setVar, snapShot, transformClass };
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(src_exports, {
|
|
|
33
33
|
Ignore: () => Ignore,
|
|
34
34
|
Init: () => Init,
|
|
35
35
|
Inject: () => Inject,
|
|
36
|
+
Isolate: () => Isolate,
|
|
36
37
|
Nested: () => Nested,
|
|
37
38
|
Pipeline: () => Pipeline,
|
|
38
39
|
Provide: () => Provide,
|
|
@@ -40,6 +41,8 @@ __export(src_exports, {
|
|
|
40
41
|
Storage: () => Storage,
|
|
41
42
|
Tag: () => Tag,
|
|
42
43
|
To: () => To,
|
|
44
|
+
Unique: () => Unique,
|
|
45
|
+
Unmount: () => Unmount,
|
|
43
46
|
Watcher: () => Watcher,
|
|
44
47
|
activeInstance: () => activeInstance,
|
|
45
48
|
addDecoToClass: () => addDecoToClass,
|
|
@@ -55,15 +58,13 @@ __export(src_exports, {
|
|
|
55
58
|
getOwnState: () => getOwnState,
|
|
56
59
|
getProperty: () => getProperty,
|
|
57
60
|
getState: () => getState,
|
|
58
|
-
|
|
59
|
-
getTag: () => getTag,
|
|
61
|
+
getTag: () => getTag2,
|
|
60
62
|
init: () => init,
|
|
61
63
|
injectProperty: () => injectProperty,
|
|
64
|
+
invokeHandler: () => invokeHandler,
|
|
62
65
|
isPhecda: () => isPhecda,
|
|
63
66
|
plainToClass: () => plainToClass,
|
|
64
67
|
regisHandler: () => regisHandler,
|
|
65
|
-
register: () => register,
|
|
66
|
-
registerAsync: () => registerAsync,
|
|
67
68
|
setExposeKey: () => setExposeKey,
|
|
68
69
|
setIgnoreKey: () => setIgnoreKey,
|
|
69
70
|
setState: () => setState,
|
|
@@ -213,35 +214,22 @@ function getState(instance, key) {
|
|
|
213
214
|
return ret;
|
|
214
215
|
}
|
|
215
216
|
__name(getState, "getState");
|
|
216
|
-
function
|
|
217
|
+
function invokeHandler(event, instance) {
|
|
217
218
|
const stateVars = getExposeKey(instance);
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
219
|
+
const initHandlers = stateVars.map((item) => {
|
|
220
|
+
return getHandler(instance, item).filter((h) => !!h[event]).map((h) => h[event](instance));
|
|
221
|
+
}).flat();
|
|
222
|
+
return Promise.all(initHandlers);
|
|
223
223
|
}
|
|
224
|
-
__name(
|
|
225
|
-
async function registerAsync(instance) {
|
|
226
|
-
const stateVars = getExposeKey(instance);
|
|
227
|
-
for (const item of stateVars) {
|
|
228
|
-
const handlers = getHandler(instance, item);
|
|
229
|
-
for (const hanlder of handlers)
|
|
230
|
-
await hanlder.init?.(instance);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
__name(registerAsync, "registerAsync");
|
|
224
|
+
__name(invokeHandler, "invokeHandler");
|
|
234
225
|
|
|
235
226
|
// src/helper.ts
|
|
236
|
-
function
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
function getSymbol(instance) {
|
|
241
|
-
const module2 = instance.constructor;
|
|
242
|
-
return getTag(module2) || module2.name;
|
|
227
|
+
function getTag2(moduleOrInstance) {
|
|
228
|
+
if (typeof moduleOrInstance === "object")
|
|
229
|
+
moduleOrInstance = moduleOrInstance.constructor;
|
|
230
|
+
return moduleOrInstance.prototype?.__TAG__ || moduleOrInstance.name;
|
|
243
231
|
}
|
|
244
|
-
__name(
|
|
232
|
+
__name(getTag2, "getTag");
|
|
245
233
|
function getBind(module2) {
|
|
246
234
|
const instance = new module2();
|
|
247
235
|
const keys = getModuleState(instance);
|
|
@@ -325,11 +313,20 @@ function Init(proto, key) {
|
|
|
325
313
|
setVar(proto, key);
|
|
326
314
|
regisHandler(proto, key, {
|
|
327
315
|
async init(instance) {
|
|
328
|
-
instance[key]();
|
|
316
|
+
return instance[key]();
|
|
329
317
|
}
|
|
330
318
|
});
|
|
331
319
|
}
|
|
332
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");
|
|
333
330
|
function Bind(value) {
|
|
334
331
|
return (proto, k) => {
|
|
335
332
|
setVar(proto, k);
|
|
@@ -365,12 +362,13 @@ function Expose(proto, key) {
|
|
|
365
362
|
setExposeKey(proto, key);
|
|
366
363
|
}
|
|
367
364
|
__name(Expose, "Expose");
|
|
368
|
-
function To(
|
|
365
|
+
function To(...callbacks) {
|
|
369
366
|
return (proto, key) => {
|
|
370
367
|
setVar(proto, key);
|
|
371
368
|
regisHandler(proto, key, {
|
|
372
369
|
async pipe(instance) {
|
|
373
|
-
|
|
370
|
+
for (const cb of callbacks)
|
|
371
|
+
instance[key] = await cb(instance[key], instance, key);
|
|
374
372
|
}
|
|
375
373
|
});
|
|
376
374
|
};
|
|
@@ -383,6 +381,13 @@ function Tag(tag) {
|
|
|
383
381
|
};
|
|
384
382
|
}
|
|
385
383
|
__name(Tag, "Tag");
|
|
384
|
+
function Unique(desc) {
|
|
385
|
+
return (module2) => {
|
|
386
|
+
init(module2.prototype);
|
|
387
|
+
module2.prototype.__TAG__ = Symbol(desc || module2.name);
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
__name(Unique, "Unique");
|
|
386
391
|
function Assign(cb) {
|
|
387
392
|
return (module2) => {
|
|
388
393
|
init(module2.prototype);
|
|
@@ -442,6 +447,13 @@ function Nested(module2) {
|
|
|
442
447
|
});
|
|
443
448
|
}
|
|
444
449
|
__name(Nested, "Nested");
|
|
450
|
+
function Isolate() {
|
|
451
|
+
return (target) => {
|
|
452
|
+
init(target.prototype);
|
|
453
|
+
target.prototype.__ISOLATE__ = true;
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
__name(Isolate, "Isolate");
|
|
445
457
|
|
|
446
458
|
// src/custom/decorator.ts
|
|
447
459
|
var activeInstance = {};
|
|
@@ -455,16 +467,20 @@ function getProperty(key) {
|
|
|
455
467
|
}
|
|
456
468
|
__name(getProperty, "getProperty");
|
|
457
469
|
function Watcher(eventName, options) {
|
|
470
|
+
let cb;
|
|
458
471
|
return (proto, key) => {
|
|
459
472
|
setVar(proto, key);
|
|
460
473
|
regisHandler(proto, key, {
|
|
461
474
|
init(instance) {
|
|
462
|
-
getProperty("watcher")?.({
|
|
475
|
+
return cb = getProperty("watcher")?.({
|
|
463
476
|
eventName,
|
|
464
477
|
instance,
|
|
465
478
|
key,
|
|
466
479
|
options
|
|
467
480
|
});
|
|
481
|
+
},
|
|
482
|
+
unmount() {
|
|
483
|
+
return cb?.();
|
|
468
484
|
}
|
|
469
485
|
});
|
|
470
486
|
};
|
|
@@ -496,34 +512,40 @@ function Effect(eventName, options) {
|
|
|
496
512
|
};
|
|
497
513
|
}
|
|
498
514
|
__name(Effect, "Effect");
|
|
499
|
-
function Storage(storeKey) {
|
|
515
|
+
function Storage({ key: storeKey, toJSON, toString } = {}) {
|
|
516
|
+
if (!toJSON)
|
|
517
|
+
toJSON = /* @__PURE__ */ __name((v) => JSON.parse(v), "toJSON");
|
|
518
|
+
if (!toString)
|
|
519
|
+
toString = /* @__PURE__ */ __name((v) => JSON.stringify(v), "toString");
|
|
500
520
|
return (proto, key) => {
|
|
501
521
|
let tag;
|
|
502
522
|
if (key) {
|
|
503
523
|
init(proto);
|
|
504
|
-
tag = storeKey || proto
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
regisHandler(proto, uniTag, {
|
|
524
|
+
tag = storeKey || `${getTag(proto)}_${key}`;
|
|
525
|
+
setVar(proto, key);
|
|
526
|
+
regisHandler(proto, key, {
|
|
508
527
|
init: (instance) => {
|
|
509
|
-
getProperty("storage")?.({
|
|
528
|
+
return getProperty("storage")?.({
|
|
510
529
|
instance,
|
|
511
530
|
key,
|
|
512
|
-
tag
|
|
531
|
+
tag,
|
|
532
|
+
toJSON,
|
|
533
|
+
toString
|
|
513
534
|
});
|
|
514
535
|
}
|
|
515
536
|
});
|
|
516
537
|
} else {
|
|
517
538
|
init(proto.prototype);
|
|
518
|
-
tag = storeKey ||
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
regisHandler(proto.prototype, uniTag, {
|
|
539
|
+
tag = storeKey || getTag(proto);
|
|
540
|
+
setVar(proto.prototype, SHARE_KEY);
|
|
541
|
+
regisHandler(proto.prototype, SHARE_KEY, {
|
|
522
542
|
init: (instance) => {
|
|
523
|
-
getProperty("storage")?.({
|
|
543
|
+
return getProperty("storage")?.({
|
|
524
544
|
instance,
|
|
525
|
-
key
|
|
526
|
-
tag
|
|
545
|
+
key,
|
|
546
|
+
tag,
|
|
547
|
+
toJSON,
|
|
548
|
+
toString
|
|
527
549
|
});
|
|
528
550
|
}
|
|
529
551
|
});
|
|
@@ -545,6 +567,7 @@ __name(Storage, "Storage");
|
|
|
545
567
|
Ignore,
|
|
546
568
|
Init,
|
|
547
569
|
Inject,
|
|
570
|
+
Isolate,
|
|
548
571
|
Nested,
|
|
549
572
|
Pipeline,
|
|
550
573
|
Provide,
|
|
@@ -552,6 +575,8 @@ __name(Storage, "Storage");
|
|
|
552
575
|
Storage,
|
|
553
576
|
Tag,
|
|
554
577
|
To,
|
|
578
|
+
Unique,
|
|
579
|
+
Unmount,
|
|
555
580
|
Watcher,
|
|
556
581
|
activeInstance,
|
|
557
582
|
addDecoToClass,
|
|
@@ -567,15 +592,13 @@ __name(Storage, "Storage");
|
|
|
567
592
|
getOwnState,
|
|
568
593
|
getProperty,
|
|
569
594
|
getState,
|
|
570
|
-
getSymbol,
|
|
571
595
|
getTag,
|
|
572
596
|
init,
|
|
573
597
|
injectProperty,
|
|
598
|
+
invokeHandler,
|
|
574
599
|
isPhecda,
|
|
575
600
|
plainToClass,
|
|
576
601
|
regisHandler,
|
|
577
|
-
register,
|
|
578
|
-
registerAsync,
|
|
579
602
|
setExposeKey,
|
|
580
603
|
setIgnoreKey,
|
|
581
604
|
setState,
|
package/dist/index.mjs
CHANGED
|
@@ -141,35 +141,22 @@ function getState(instance, key) {
|
|
|
141
141
|
return ret;
|
|
142
142
|
}
|
|
143
143
|
__name(getState, "getState");
|
|
144
|
-
function
|
|
144
|
+
function invokeHandler(event, instance) {
|
|
145
145
|
const stateVars = getExposeKey(instance);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
146
|
+
const initHandlers = stateVars.map((item) => {
|
|
147
|
+
return getHandler(instance, item).filter((h) => !!h[event]).map((h) => h[event](instance));
|
|
148
|
+
}).flat();
|
|
149
|
+
return Promise.all(initHandlers);
|
|
151
150
|
}
|
|
152
|
-
__name(
|
|
153
|
-
async function registerAsync(instance) {
|
|
154
|
-
const stateVars = getExposeKey(instance);
|
|
155
|
-
for (const item of stateVars) {
|
|
156
|
-
const handlers = getHandler(instance, item);
|
|
157
|
-
for (const hanlder of handlers)
|
|
158
|
-
await hanlder.init?.(instance);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
__name(registerAsync, "registerAsync");
|
|
151
|
+
__name(invokeHandler, "invokeHandler");
|
|
162
152
|
|
|
163
153
|
// src/helper.ts
|
|
164
|
-
function
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
function getSymbol(instance) {
|
|
169
|
-
const module = instance.constructor;
|
|
170
|
-
return getTag(module) || module.name;
|
|
154
|
+
function getTag2(moduleOrInstance) {
|
|
155
|
+
if (typeof moduleOrInstance === "object")
|
|
156
|
+
moduleOrInstance = moduleOrInstance.constructor;
|
|
157
|
+
return moduleOrInstance.prototype?.__TAG__ || moduleOrInstance.name;
|
|
171
158
|
}
|
|
172
|
-
__name(
|
|
159
|
+
__name(getTag2, "getTag");
|
|
173
160
|
function getBind(module) {
|
|
174
161
|
const instance = new module();
|
|
175
162
|
const keys = getModuleState(instance);
|
|
@@ -253,11 +240,20 @@ function Init(proto, key) {
|
|
|
253
240
|
setVar(proto, key);
|
|
254
241
|
regisHandler(proto, key, {
|
|
255
242
|
async init(instance) {
|
|
256
|
-
instance[key]();
|
|
243
|
+
return instance[key]();
|
|
257
244
|
}
|
|
258
245
|
});
|
|
259
246
|
}
|
|
260
247
|
__name(Init, "Init");
|
|
248
|
+
function Unmount(proto, key) {
|
|
249
|
+
setVar(proto, key);
|
|
250
|
+
regisHandler(proto, key, {
|
|
251
|
+
async unmount(instance) {
|
|
252
|
+
return instance[key]();
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
__name(Unmount, "Unmount");
|
|
261
257
|
function Bind(value) {
|
|
262
258
|
return (proto, k) => {
|
|
263
259
|
setVar(proto, k);
|
|
@@ -293,12 +289,13 @@ function Expose(proto, key) {
|
|
|
293
289
|
setExposeKey(proto, key);
|
|
294
290
|
}
|
|
295
291
|
__name(Expose, "Expose");
|
|
296
|
-
function To(
|
|
292
|
+
function To(...callbacks) {
|
|
297
293
|
return (proto, key) => {
|
|
298
294
|
setVar(proto, key);
|
|
299
295
|
regisHandler(proto, key, {
|
|
300
296
|
async pipe(instance) {
|
|
301
|
-
|
|
297
|
+
for (const cb of callbacks)
|
|
298
|
+
instance[key] = await cb(instance[key], instance, key);
|
|
302
299
|
}
|
|
303
300
|
});
|
|
304
301
|
};
|
|
@@ -311,6 +308,13 @@ function Tag(tag) {
|
|
|
311
308
|
};
|
|
312
309
|
}
|
|
313
310
|
__name(Tag, "Tag");
|
|
311
|
+
function Unique(desc) {
|
|
312
|
+
return (module) => {
|
|
313
|
+
init(module.prototype);
|
|
314
|
+
module.prototype.__TAG__ = Symbol(desc || module.name);
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
__name(Unique, "Unique");
|
|
314
318
|
function Assign(cb) {
|
|
315
319
|
return (module) => {
|
|
316
320
|
init(module.prototype);
|
|
@@ -370,6 +374,13 @@ function Nested(module) {
|
|
|
370
374
|
});
|
|
371
375
|
}
|
|
372
376
|
__name(Nested, "Nested");
|
|
377
|
+
function Isolate() {
|
|
378
|
+
return (target) => {
|
|
379
|
+
init(target.prototype);
|
|
380
|
+
target.prototype.__ISOLATE__ = true;
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
__name(Isolate, "Isolate");
|
|
373
384
|
|
|
374
385
|
// src/custom/decorator.ts
|
|
375
386
|
var activeInstance = {};
|
|
@@ -383,16 +394,20 @@ function getProperty(key) {
|
|
|
383
394
|
}
|
|
384
395
|
__name(getProperty, "getProperty");
|
|
385
396
|
function Watcher(eventName, options) {
|
|
397
|
+
let cb;
|
|
386
398
|
return (proto, key) => {
|
|
387
399
|
setVar(proto, key);
|
|
388
400
|
regisHandler(proto, key, {
|
|
389
401
|
init(instance) {
|
|
390
|
-
getProperty("watcher")?.({
|
|
402
|
+
return cb = getProperty("watcher")?.({
|
|
391
403
|
eventName,
|
|
392
404
|
instance,
|
|
393
405
|
key,
|
|
394
406
|
options
|
|
395
407
|
});
|
|
408
|
+
},
|
|
409
|
+
unmount() {
|
|
410
|
+
return cb?.();
|
|
396
411
|
}
|
|
397
412
|
});
|
|
398
413
|
};
|
|
@@ -424,34 +439,40 @@ function Effect(eventName, options) {
|
|
|
424
439
|
};
|
|
425
440
|
}
|
|
426
441
|
__name(Effect, "Effect");
|
|
427
|
-
function Storage(storeKey) {
|
|
442
|
+
function Storage({ key: storeKey, toJSON, toString } = {}) {
|
|
443
|
+
if (!toJSON)
|
|
444
|
+
toJSON = /* @__PURE__ */ __name((v) => JSON.parse(v), "toJSON");
|
|
445
|
+
if (!toString)
|
|
446
|
+
toString = /* @__PURE__ */ __name((v) => JSON.stringify(v), "toString");
|
|
428
447
|
return (proto, key) => {
|
|
429
448
|
let tag;
|
|
430
449
|
if (key) {
|
|
431
450
|
init(proto);
|
|
432
|
-
tag = storeKey || proto
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
regisHandler(proto, uniTag, {
|
|
451
|
+
tag = storeKey || `${getTag(proto)}_${key}`;
|
|
452
|
+
setVar(proto, key);
|
|
453
|
+
regisHandler(proto, key, {
|
|
436
454
|
init: (instance) => {
|
|
437
|
-
getProperty("storage")?.({
|
|
455
|
+
return getProperty("storage")?.({
|
|
438
456
|
instance,
|
|
439
457
|
key,
|
|
440
|
-
tag
|
|
458
|
+
tag,
|
|
459
|
+
toJSON,
|
|
460
|
+
toString
|
|
441
461
|
});
|
|
442
462
|
}
|
|
443
463
|
});
|
|
444
464
|
} else {
|
|
445
465
|
init(proto.prototype);
|
|
446
|
-
tag = storeKey ||
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
regisHandler(proto.prototype, uniTag, {
|
|
466
|
+
tag = storeKey || getTag(proto);
|
|
467
|
+
setVar(proto.prototype, SHARE_KEY);
|
|
468
|
+
regisHandler(proto.prototype, SHARE_KEY, {
|
|
450
469
|
init: (instance) => {
|
|
451
|
-
getProperty("storage")?.({
|
|
470
|
+
return getProperty("storage")?.({
|
|
452
471
|
instance,
|
|
453
|
-
key
|
|
454
|
-
tag
|
|
472
|
+
key,
|
|
473
|
+
tag,
|
|
474
|
+
toJSON,
|
|
475
|
+
toString
|
|
455
476
|
});
|
|
456
477
|
}
|
|
457
478
|
});
|
|
@@ -472,6 +493,7 @@ export {
|
|
|
472
493
|
Ignore,
|
|
473
494
|
Init,
|
|
474
495
|
Inject,
|
|
496
|
+
Isolate,
|
|
475
497
|
Nested,
|
|
476
498
|
Pipeline,
|
|
477
499
|
Provide,
|
|
@@ -479,6 +501,8 @@ export {
|
|
|
479
501
|
Storage,
|
|
480
502
|
Tag,
|
|
481
503
|
To,
|
|
504
|
+
Unique,
|
|
505
|
+
Unmount,
|
|
482
506
|
Watcher,
|
|
483
507
|
activeInstance,
|
|
484
508
|
addDecoToClass,
|
|
@@ -494,15 +518,13 @@ export {
|
|
|
494
518
|
getOwnState,
|
|
495
519
|
getProperty,
|
|
496
520
|
getState,
|
|
497
|
-
|
|
498
|
-
getTag,
|
|
521
|
+
getTag2 as getTag,
|
|
499
522
|
init,
|
|
500
523
|
injectProperty,
|
|
524
|
+
invokeHandler,
|
|
501
525
|
isPhecda,
|
|
502
526
|
plainToClass,
|
|
503
527
|
regisHandler,
|
|
504
|
-
register,
|
|
505
|
-
registerAsync,
|
|
506
528
|
setExposeKey,
|
|
507
529
|
setIgnoreKey,
|
|
508
530
|
setState,
|