phecda-core 3.0.0-alpha.5 → 3.0.0-alpha.7
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 +7 -4
- package/dist/index.js +42 -7
- package/dist/index.mjs +38 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -25,13 +25,15 @@ interface Events {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
declare function Init(proto: any, key: PropertyKey): void;
|
|
28
|
+
declare function Unmount(proto: any, key: PropertyKey): void;
|
|
28
29
|
declare function Bind(value: any): (proto: any, k: PropertyKey) => void;
|
|
29
30
|
declare function Ignore(proto: any, key: PropertyKey): void;
|
|
30
31
|
declare function Clear(proto: any, key: PropertyKey): void;
|
|
31
32
|
declare function Err<Fn extends (...args: any) => any>(cb: Fn): (proto: any, key: PropertyKey) => void;
|
|
32
33
|
declare function Expose(proto: any, key: PropertyKey): void;
|
|
33
|
-
declare function To(
|
|
34
|
-
declare function Tag(tag:
|
|
34
|
+
declare function To(...callbacks: ((arg: any, instance: any, key: string) => any)[]): (proto: any, key: PropertyKey) => void;
|
|
35
|
+
declare function Tag(tag: PropertyKey): (module: any) => void;
|
|
36
|
+
declare function Unique(desc?: string): (module: any) => void;
|
|
35
37
|
declare function Assign(cb: (instance?: any) => any): (module: any) => void;
|
|
36
38
|
declare function Global(module: any): void;
|
|
37
39
|
declare function Empty(module: any): void;
|
|
@@ -41,7 +43,7 @@ declare function Inject<K extends keyof InjectData>(key: K): InjectData[K];
|
|
|
41
43
|
declare function Nested<M extends new (...args: any) => any>(module: M): (proto: any, key: PropertyKey) => void;
|
|
42
44
|
declare function Isolate(): (target: any) => void;
|
|
43
45
|
|
|
44
|
-
declare function getTag<M extends Construct>(moduleOrInstance: M | InstanceType<M>):
|
|
46
|
+
declare function getTag<M extends Construct>(moduleOrInstance: M | InstanceType<M>): PropertyKey;
|
|
45
47
|
declare function getBind<M extends Construct>(module: M): any;
|
|
46
48
|
declare function plainToClass<M extends Construct, Data extends Record<PropertyKey, any>>(module: M, input: Data): InstanceType<M>;
|
|
47
49
|
declare function transformClass<M extends Construct>(instance: InstanceType<M>, force?: boolean): Promise<string[]>;
|
|
@@ -73,6 +75,7 @@ declare function getOwnState(instance: Phecda, key: PropertyKey): Object;
|
|
|
73
75
|
declare function getState(instance: Phecda, key: PropertyKey): any;
|
|
74
76
|
declare function registerParallel(instance: Phecda): Promise<any[]>;
|
|
75
77
|
declare function registerSerial(instance: Phecda): Promise<void>;
|
|
78
|
+
declare function unmountParallel(instance: Phecda): Promise<any[]>;
|
|
76
79
|
|
|
77
80
|
declare const activeInstance: Record<string, any>;
|
|
78
81
|
declare function injectProperty(key: string, value: any): Record<string, any>;
|
|
@@ -83,4 +86,4 @@ declare function Watcher(eventName: keyof Events, options?: {
|
|
|
83
86
|
declare function Effect(eventName: string, options?: any): (proto: any, key: string) => void;
|
|
84
87
|
declare function Storage(storeKey?: string): (proto: any, key?: PropertyKey) => void;
|
|
85
88
|
|
|
86
|
-
export { 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, Tag, To, Watcher, activeInstance, addDecoToClass, classToValue, getBind, getExposeKey, getHandler, getModuleState, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnModuleState, getOwnState, getProperty, getState, getTag, init, injectProperty, isPhecda, plainToClass, regisHandler, registerParallel, registerSerial, setExposeKey, setIgnoreKey, setState, setVar, snapShot, transformClass };
|
|
89
|
+
export { 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, Tag, To, Unique, Unmount, Watcher, activeInstance, addDecoToClass, classToValue, getBind, getExposeKey, getHandler, getModuleState, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnModuleState, getOwnState, getProperty, getState, getTag, init, injectProperty, isPhecda, plainToClass, regisHandler, registerParallel, registerSerial, setExposeKey, setIgnoreKey, setState, setVar, snapShot, transformClass, unmountParallel };
|
package/dist/index.js
CHANGED
|
@@ -41,6 +41,8 @@ __export(src_exports, {
|
|
|
41
41
|
Storage: () => Storage,
|
|
42
42
|
Tag: () => Tag,
|
|
43
43
|
To: () => To,
|
|
44
|
+
Unique: () => Unique,
|
|
45
|
+
Unmount: () => Unmount,
|
|
44
46
|
Watcher: () => Watcher,
|
|
45
47
|
activeInstance: () => activeInstance,
|
|
46
48
|
addDecoToClass: () => addDecoToClass,
|
|
@@ -69,7 +71,8 @@ __export(src_exports, {
|
|
|
69
71
|
setState: () => setState,
|
|
70
72
|
setVar: () => setVar,
|
|
71
73
|
snapShot: () => snapShot,
|
|
72
|
-
transformClass: () => transformClass
|
|
74
|
+
transformClass: () => transformClass,
|
|
75
|
+
unmountParallel: () => unmountParallel
|
|
73
76
|
});
|
|
74
77
|
module.exports = __toCommonJS(src_exports);
|
|
75
78
|
|
|
@@ -230,6 +233,14 @@ async function registerSerial(instance) {
|
|
|
230
233
|
}
|
|
231
234
|
}
|
|
232
235
|
__name(registerSerial, "registerSerial");
|
|
236
|
+
function unmountParallel(instance) {
|
|
237
|
+
const stateVars = getExposeKey(instance);
|
|
238
|
+
const initHandlers = stateVars.map((item) => {
|
|
239
|
+
return getHandler(instance, item).filter((h) => h.unmount).map((h) => h.init(instance));
|
|
240
|
+
}).flat();
|
|
241
|
+
return Promise.all(initHandlers);
|
|
242
|
+
}
|
|
243
|
+
__name(unmountParallel, "unmountParallel");
|
|
233
244
|
|
|
234
245
|
// src/helper.ts
|
|
235
246
|
function getTag(moduleOrInstance) {
|
|
@@ -326,6 +337,15 @@ function Init(proto, key) {
|
|
|
326
337
|
});
|
|
327
338
|
}
|
|
328
339
|
__name(Init, "Init");
|
|
340
|
+
function Unmount(proto, key) {
|
|
341
|
+
setVar(proto, key);
|
|
342
|
+
regisHandler(proto, key, {
|
|
343
|
+
async unmount(instance) {
|
|
344
|
+
return instance[key]();
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
__name(Unmount, "Unmount");
|
|
329
349
|
function Bind(value) {
|
|
330
350
|
return (proto, k) => {
|
|
331
351
|
setVar(proto, k);
|
|
@@ -361,12 +381,13 @@ function Expose(proto, key) {
|
|
|
361
381
|
setExposeKey(proto, key);
|
|
362
382
|
}
|
|
363
383
|
__name(Expose, "Expose");
|
|
364
|
-
function To(
|
|
384
|
+
function To(...callbacks) {
|
|
365
385
|
return (proto, key) => {
|
|
366
386
|
setVar(proto, key);
|
|
367
387
|
regisHandler(proto, key, {
|
|
368
388
|
async pipe(instance) {
|
|
369
|
-
|
|
389
|
+
for (const cb of callbacks)
|
|
390
|
+
instance[key] = await cb(instance[key], instance, key);
|
|
370
391
|
}
|
|
371
392
|
});
|
|
372
393
|
};
|
|
@@ -379,6 +400,13 @@ function Tag(tag) {
|
|
|
379
400
|
};
|
|
380
401
|
}
|
|
381
402
|
__name(Tag, "Tag");
|
|
403
|
+
function Unique(desc) {
|
|
404
|
+
return (module2) => {
|
|
405
|
+
init(module2.prototype);
|
|
406
|
+
module2.prototype.__TAG__ = Symbol(desc || module2.name);
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
__name(Unique, "Unique");
|
|
382
410
|
function Assign(cb) {
|
|
383
411
|
return (module2) => {
|
|
384
412
|
init(module2.prototype);
|
|
@@ -457,16 +485,20 @@ function getProperty(key) {
|
|
|
457
485
|
}
|
|
458
486
|
__name(getProperty, "getProperty");
|
|
459
487
|
function Watcher(eventName, options) {
|
|
488
|
+
let cb;
|
|
460
489
|
return (proto, key) => {
|
|
461
490
|
setVar(proto, key);
|
|
462
491
|
regisHandler(proto, key, {
|
|
463
492
|
init(instance) {
|
|
464
|
-
getProperty("watcher")?.({
|
|
493
|
+
return cb = getProperty("watcher")?.({
|
|
465
494
|
eventName,
|
|
466
495
|
instance,
|
|
467
496
|
key,
|
|
468
497
|
options
|
|
469
498
|
});
|
|
499
|
+
},
|
|
500
|
+
unmount() {
|
|
501
|
+
return cb?.();
|
|
470
502
|
}
|
|
471
503
|
});
|
|
472
504
|
};
|
|
@@ -508,7 +540,7 @@ function Storage(storeKey) {
|
|
|
508
540
|
setVar(proto, uniTag);
|
|
509
541
|
regisHandler(proto, uniTag, {
|
|
510
542
|
init: (instance) => {
|
|
511
|
-
getProperty("storage")?.({
|
|
543
|
+
return getProperty("storage")?.({
|
|
512
544
|
instance,
|
|
513
545
|
key,
|
|
514
546
|
tag
|
|
@@ -522,7 +554,7 @@ function Storage(storeKey) {
|
|
|
522
554
|
setVar(proto.prototype, uniTag);
|
|
523
555
|
regisHandler(proto.prototype, uniTag, {
|
|
524
556
|
init: (instance) => {
|
|
525
|
-
getProperty("storage")?.({
|
|
557
|
+
return getProperty("storage")?.({
|
|
526
558
|
instance,
|
|
527
559
|
key: "",
|
|
528
560
|
tag
|
|
@@ -555,6 +587,8 @@ __name(Storage, "Storage");
|
|
|
555
587
|
Storage,
|
|
556
588
|
Tag,
|
|
557
589
|
To,
|
|
590
|
+
Unique,
|
|
591
|
+
Unmount,
|
|
558
592
|
Watcher,
|
|
559
593
|
activeInstance,
|
|
560
594
|
addDecoToClass,
|
|
@@ -583,5 +617,6 @@ __name(Storage, "Storage");
|
|
|
583
617
|
setState,
|
|
584
618
|
setVar,
|
|
585
619
|
snapShot,
|
|
586
|
-
transformClass
|
|
620
|
+
transformClass,
|
|
621
|
+
unmountParallel
|
|
587
622
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -158,6 +158,14 @@ async function registerSerial(instance) {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
__name(registerSerial, "registerSerial");
|
|
161
|
+
function unmountParallel(instance) {
|
|
162
|
+
const stateVars = getExposeKey(instance);
|
|
163
|
+
const initHandlers = stateVars.map((item) => {
|
|
164
|
+
return getHandler(instance, item).filter((h) => h.unmount).map((h) => h.init(instance));
|
|
165
|
+
}).flat();
|
|
166
|
+
return Promise.all(initHandlers);
|
|
167
|
+
}
|
|
168
|
+
__name(unmountParallel, "unmountParallel");
|
|
161
169
|
|
|
162
170
|
// src/helper.ts
|
|
163
171
|
function getTag(moduleOrInstance) {
|
|
@@ -254,6 +262,15 @@ function Init(proto, key) {
|
|
|
254
262
|
});
|
|
255
263
|
}
|
|
256
264
|
__name(Init, "Init");
|
|
265
|
+
function Unmount(proto, key) {
|
|
266
|
+
setVar(proto, key);
|
|
267
|
+
regisHandler(proto, key, {
|
|
268
|
+
async unmount(instance) {
|
|
269
|
+
return instance[key]();
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
__name(Unmount, "Unmount");
|
|
257
274
|
function Bind(value) {
|
|
258
275
|
return (proto, k) => {
|
|
259
276
|
setVar(proto, k);
|
|
@@ -289,12 +306,13 @@ function Expose(proto, key) {
|
|
|
289
306
|
setExposeKey(proto, key);
|
|
290
307
|
}
|
|
291
308
|
__name(Expose, "Expose");
|
|
292
|
-
function To(
|
|
309
|
+
function To(...callbacks) {
|
|
293
310
|
return (proto, key) => {
|
|
294
311
|
setVar(proto, key);
|
|
295
312
|
regisHandler(proto, key, {
|
|
296
313
|
async pipe(instance) {
|
|
297
|
-
|
|
314
|
+
for (const cb of callbacks)
|
|
315
|
+
instance[key] = await cb(instance[key], instance, key);
|
|
298
316
|
}
|
|
299
317
|
});
|
|
300
318
|
};
|
|
@@ -307,6 +325,13 @@ function Tag(tag) {
|
|
|
307
325
|
};
|
|
308
326
|
}
|
|
309
327
|
__name(Tag, "Tag");
|
|
328
|
+
function Unique(desc) {
|
|
329
|
+
return (module) => {
|
|
330
|
+
init(module.prototype);
|
|
331
|
+
module.prototype.__TAG__ = Symbol(desc || module.name);
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
__name(Unique, "Unique");
|
|
310
335
|
function Assign(cb) {
|
|
311
336
|
return (module) => {
|
|
312
337
|
init(module.prototype);
|
|
@@ -385,16 +410,20 @@ function getProperty(key) {
|
|
|
385
410
|
}
|
|
386
411
|
__name(getProperty, "getProperty");
|
|
387
412
|
function Watcher(eventName, options) {
|
|
413
|
+
let cb;
|
|
388
414
|
return (proto, key) => {
|
|
389
415
|
setVar(proto, key);
|
|
390
416
|
regisHandler(proto, key, {
|
|
391
417
|
init(instance) {
|
|
392
|
-
getProperty("watcher")?.({
|
|
418
|
+
return cb = getProperty("watcher")?.({
|
|
393
419
|
eventName,
|
|
394
420
|
instance,
|
|
395
421
|
key,
|
|
396
422
|
options
|
|
397
423
|
});
|
|
424
|
+
},
|
|
425
|
+
unmount() {
|
|
426
|
+
return cb?.();
|
|
398
427
|
}
|
|
399
428
|
});
|
|
400
429
|
};
|
|
@@ -436,7 +465,7 @@ function Storage(storeKey) {
|
|
|
436
465
|
setVar(proto, uniTag);
|
|
437
466
|
regisHandler(proto, uniTag, {
|
|
438
467
|
init: (instance) => {
|
|
439
|
-
getProperty("storage")?.({
|
|
468
|
+
return getProperty("storage")?.({
|
|
440
469
|
instance,
|
|
441
470
|
key,
|
|
442
471
|
tag
|
|
@@ -450,7 +479,7 @@ function Storage(storeKey) {
|
|
|
450
479
|
setVar(proto.prototype, uniTag);
|
|
451
480
|
regisHandler(proto.prototype, uniTag, {
|
|
452
481
|
init: (instance) => {
|
|
453
|
-
getProperty("storage")?.({
|
|
482
|
+
return getProperty("storage")?.({
|
|
454
483
|
instance,
|
|
455
484
|
key: "",
|
|
456
485
|
tag
|
|
@@ -482,6 +511,8 @@ export {
|
|
|
482
511
|
Storage,
|
|
483
512
|
Tag,
|
|
484
513
|
To,
|
|
514
|
+
Unique,
|
|
515
|
+
Unmount,
|
|
485
516
|
Watcher,
|
|
486
517
|
activeInstance,
|
|
487
518
|
addDecoToClass,
|
|
@@ -510,5 +541,6 @@ export {
|
|
|
510
541
|
setState,
|
|
511
542
|
setVar,
|
|
512
543
|
snapShot,
|
|
513
|
-
transformClass
|
|
544
|
+
transformClass,
|
|
545
|
+
unmountParallel
|
|
514
546
|
};
|