phecda-core 3.0.0-alpha.6 → 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 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
34
  declare function To(...callbacks: ((arg: any, instance: any, key: string) => any)[]): (proto: any, key: PropertyKey) => void;
34
- declare function Tag(tag: string): (module: any) => 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>): any;
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);
@@ -380,6 +400,13 @@ function Tag(tag) {
380
400
  };
381
401
  }
382
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");
383
410
  function Assign(cb) {
384
411
  return (module2) => {
385
412
  init(module2.prototype);
@@ -458,16 +485,20 @@ function getProperty(key) {
458
485
  }
459
486
  __name(getProperty, "getProperty");
460
487
  function Watcher(eventName, options) {
488
+ let cb;
461
489
  return (proto, key) => {
462
490
  setVar(proto, key);
463
491
  regisHandler(proto, key, {
464
492
  init(instance) {
465
- getProperty("watcher")?.({
493
+ return cb = getProperty("watcher")?.({
466
494
  eventName,
467
495
  instance,
468
496
  key,
469
497
  options
470
498
  });
499
+ },
500
+ unmount() {
501
+ return cb?.();
471
502
  }
472
503
  });
473
504
  };
@@ -509,7 +540,7 @@ function Storage(storeKey) {
509
540
  setVar(proto, uniTag);
510
541
  regisHandler(proto, uniTag, {
511
542
  init: (instance) => {
512
- getProperty("storage")?.({
543
+ return getProperty("storage")?.({
513
544
  instance,
514
545
  key,
515
546
  tag
@@ -523,7 +554,7 @@ function Storage(storeKey) {
523
554
  setVar(proto.prototype, uniTag);
524
555
  regisHandler(proto.prototype, uniTag, {
525
556
  init: (instance) => {
526
- getProperty("storage")?.({
557
+ return getProperty("storage")?.({
527
558
  instance,
528
559
  key: "",
529
560
  tag
@@ -556,6 +587,8 @@ __name(Storage, "Storage");
556
587
  Storage,
557
588
  Tag,
558
589
  To,
590
+ Unique,
591
+ Unmount,
559
592
  Watcher,
560
593
  activeInstance,
561
594
  addDecoToClass,
@@ -584,5 +617,6 @@ __name(Storage, "Storage");
584
617
  setState,
585
618
  setVar,
586
619
  snapShot,
587
- transformClass
620
+ transformClass,
621
+ unmountParallel
588
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);
@@ -308,6 +325,13 @@ function Tag(tag) {
308
325
  };
309
326
  }
310
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");
311
335
  function Assign(cb) {
312
336
  return (module) => {
313
337
  init(module.prototype);
@@ -386,16 +410,20 @@ function getProperty(key) {
386
410
  }
387
411
  __name(getProperty, "getProperty");
388
412
  function Watcher(eventName, options) {
413
+ let cb;
389
414
  return (proto, key) => {
390
415
  setVar(proto, key);
391
416
  regisHandler(proto, key, {
392
417
  init(instance) {
393
- getProperty("watcher")?.({
418
+ return cb = getProperty("watcher")?.({
394
419
  eventName,
395
420
  instance,
396
421
  key,
397
422
  options
398
423
  });
424
+ },
425
+ unmount() {
426
+ return cb?.();
399
427
  }
400
428
  });
401
429
  };
@@ -437,7 +465,7 @@ function Storage(storeKey) {
437
465
  setVar(proto, uniTag);
438
466
  regisHandler(proto, uniTag, {
439
467
  init: (instance) => {
440
- getProperty("storage")?.({
468
+ return getProperty("storage")?.({
441
469
  instance,
442
470
  key,
443
471
  tag
@@ -451,7 +479,7 @@ function Storage(storeKey) {
451
479
  setVar(proto.prototype, uniTag);
452
480
  regisHandler(proto.prototype, uniTag, {
453
481
  init: (instance) => {
454
- getProperty("storage")?.({
482
+ return getProperty("storage")?.({
455
483
  instance,
456
484
  key: "",
457
485
  tag
@@ -483,6 +511,8 @@ export {
483
511
  Storage,
484
512
  Tag,
485
513
  To,
514
+ Unique,
515
+ Unmount,
486
516
  Watcher,
487
517
  activeInstance,
488
518
  addDecoToClass,
@@ -511,5 +541,6 @@ export {
511
541
  setState,
512
542
  setVar,
513
543
  snapShot,
514
- transformClass
544
+ transformClass,
545
+ unmountParallel
515
546
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "3.0.0-alpha.6",
3
+ "version": "3.0.0-alpha.7",
4
4
  "description": "provide base function and abstract limit to other phecda module ",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",