phecda-core 3.0.0-alpha.2 → 3.0.0-alpha.4

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
@@ -39,19 +39,19 @@ declare const DataMap: InjectData;
39
39
  declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
40
40
  declare function Inject<K extends keyof InjectData>(key: K): InjectData[K];
41
41
  declare function Nested<M extends new (...args: any) => any>(module: M): (proto: any, key: PropertyKey) => void;
42
+ declare function Isolate(): (target: any) => void;
42
43
 
43
- declare function getTag<M extends new (...args: any) => any>(module: M): any;
44
- declare function getSymbol<M extends new (...args: any) => any>(instance: InstanceType<M>): any;
45
- declare function getBind<M extends new (...args: any) => any>(module: M): any;
46
- declare function plainToClass<M extends new (...args: any) => any, Data extends Record<PropertyKey, any>>(module: M, input: Data): InstanceType<M>;
47
- declare function transformClass<M extends new (...args: any) => any>(instance: InstanceType<M>, force?: boolean): Promise<string[]>;
44
+ declare function getTag<M extends Construct>(moduleOrInstance: M | InstanceType<M>): any;
45
+ declare function getBind<M extends Construct>(module: M): any;
46
+ declare function plainToClass<M extends Construct, Data extends Record<PropertyKey, any>>(module: M, input: Data): InstanceType<M>;
47
+ declare function transformClass<M extends Construct>(instance: InstanceType<M>, force?: boolean): Promise<string[]>;
48
48
  declare function classToValue<M>(instance: M): ClassValue<M>;
49
- declare function snapShot<T extends new (...args: any) => any>(data: InstanceType<T>): {
49
+ declare function snapShot<T extends Construct>(data: InstanceType<T>): {
50
50
  data: InstanceType<T>;
51
51
  clear(): void;
52
52
  apply(): void;
53
53
  };
54
- declare function addDecoToClass<M extends new (...args: any) => any>(c: M, key: keyof InstanceType<M> | string, handler: ((target: any, key: PropertyKey) => void), type?: 'property' | 'class'): void;
54
+ declare function addDecoToClass<M extends Construct>(c: M, key: keyof InstanceType<M> | string, handler: ((target: any, key: PropertyKey) => void), type?: 'property' | 'class'): void;
55
55
  declare function Pipeline(...decos: ((...args: any) => void)[]): (...args: any) => void;
56
56
 
57
57
  declare function isPhecda(module: any): module is Construct;
@@ -71,8 +71,8 @@ declare function getHandler(instance: Phecda, key: PropertyKey): any[];
71
71
  declare function setState(proto: Phecda, key: PropertyKey, state: Record<string, any>): void;
72
72
  declare function getOwnState(instance: Phecda, key: PropertyKey): Object;
73
73
  declare function getState(instance: Phecda, key: PropertyKey): any;
74
- declare function register(instance: Phecda): void;
75
- declare function registerAsync(instance: Phecda): Promise<void>;
74
+ declare function registerParallel(instance: Phecda): Promise<any[]>;
75
+ declare function registerSerial(instance: Phecda): Promise<void>;
76
76
 
77
77
  declare const activeInstance: Record<string, any>;
78
78
  declare function injectProperty(key: string, value: any): Record<string, any>;
@@ -83,4 +83,4 @@ declare function Watcher(eventName: keyof Events, options?: {
83
83
  declare function Effect(eventName: string, options?: any): (proto: any, key: string) => void;
84
84
  declare function Storage(storeKey?: string): (proto: any, key?: PropertyKey) => void;
85
85
 
86
- export { Assign, Bind, ClassValue, Clear, Construct, 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, getSymbol, getTag, init, injectProperty, isPhecda, plainToClass, regisHandler, register, registerAsync, setExposeKey, setIgnoreKey, setState, setVar, snapShot, transformClass };
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 };
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,
@@ -55,15 +56,14 @@ __export(src_exports, {
55
56
  getOwnState: () => getOwnState,
56
57
  getProperty: () => getProperty,
57
58
  getState: () => getState,
58
- getSymbol: () => getSymbol,
59
59
  getTag: () => getTag,
60
60
  init: () => init,
61
61
  injectProperty: () => injectProperty,
62
62
  isPhecda: () => isPhecda,
63
63
  plainToClass: () => plainToClass,
64
64
  regisHandler: () => regisHandler,
65
- register: () => register,
66
- registerAsync: () => registerAsync,
65
+ registerParallel: () => registerParallel,
66
+ registerSerial: () => registerSerial,
67
67
  setExposeKey: () => setExposeKey,
68
68
  setIgnoreKey: () => setIgnoreKey,
69
69
  setState: () => setState,
@@ -213,16 +213,15 @@ function getState(instance, key) {
213
213
  return ret;
214
214
  }
215
215
  __name(getState, "getState");
216
- function register(instance) {
216
+ function registerParallel(instance) {
217
217
  const stateVars = getExposeKey(instance);
218
- for (const item of stateVars) {
219
- const handlers = getHandler(instance, item);
220
- for (const hanlder of handlers)
221
- hanlder.init?.(instance);
222
- }
218
+ const initHandlers = stateVars.map((item) => {
219
+ return getHandler(instance, item).filter((h) => h.init).map((h) => h.init(instance));
220
+ }).flat();
221
+ return Promise.all(initHandlers);
223
222
  }
224
- __name(register, "register");
225
- async function registerAsync(instance) {
223
+ __name(registerParallel, "registerParallel");
224
+ async function registerSerial(instance) {
226
225
  const stateVars = getExposeKey(instance);
227
226
  for (const item of stateVars) {
228
227
  const handlers = getHandler(instance, item);
@@ -230,18 +229,15 @@ async function registerAsync(instance) {
230
229
  await hanlder.init?.(instance);
231
230
  }
232
231
  }
233
- __name(registerAsync, "registerAsync");
232
+ __name(registerSerial, "registerSerial");
234
233
 
235
234
  // src/helper.ts
236
- function getTag(module2) {
237
- return module2.prototype?.__TAG__;
235
+ function getTag(moduleOrInstance) {
236
+ if (typeof moduleOrInstance === "object")
237
+ moduleOrInstance = moduleOrInstance.constructor;
238
+ return moduleOrInstance.prototype?.__TAG__ || moduleOrInstance.name;
238
239
  }
239
240
  __name(getTag, "getTag");
240
- function getSymbol(instance) {
241
- const module2 = instance.constructor;
242
- return getTag(module2) || module2.name;
243
- }
244
- __name(getSymbol, "getSymbol");
245
241
  function getBind(module2) {
246
242
  const instance = new module2();
247
243
  const keys = getModuleState(instance);
@@ -442,6 +438,12 @@ function Nested(module2) {
442
438
  });
443
439
  }
444
440
  __name(Nested, "Nested");
441
+ function Isolate() {
442
+ return (target) => {
443
+ target.prototype.__ISOLATE__ = true;
444
+ };
445
+ }
446
+ __name(Isolate, "Isolate");
445
447
 
446
448
  // src/custom/decorator.ts
447
449
  var activeInstance = {};
@@ -545,6 +547,7 @@ __name(Storage, "Storage");
545
547
  Ignore,
546
548
  Init,
547
549
  Inject,
550
+ Isolate,
548
551
  Nested,
549
552
  Pipeline,
550
553
  Provide,
@@ -567,15 +570,14 @@ __name(Storage, "Storage");
567
570
  getOwnState,
568
571
  getProperty,
569
572
  getState,
570
- getSymbol,
571
573
  getTag,
572
574
  init,
573
575
  injectProperty,
574
576
  isPhecda,
575
577
  plainToClass,
576
578
  regisHandler,
577
- register,
578
- registerAsync,
579
+ registerParallel,
580
+ registerSerial,
579
581
  setExposeKey,
580
582
  setIgnoreKey,
581
583
  setState,
package/dist/index.mjs CHANGED
@@ -141,16 +141,15 @@ function getState(instance, key) {
141
141
  return ret;
142
142
  }
143
143
  __name(getState, "getState");
144
- function register(instance) {
144
+ function registerParallel(instance) {
145
145
  const stateVars = getExposeKey(instance);
146
- for (const item of stateVars) {
147
- const handlers = getHandler(instance, item);
148
- for (const hanlder of handlers)
149
- hanlder.init?.(instance);
150
- }
146
+ const initHandlers = stateVars.map((item) => {
147
+ return getHandler(instance, item).filter((h) => h.init).map((h) => h.init(instance));
148
+ }).flat();
149
+ return Promise.all(initHandlers);
151
150
  }
152
- __name(register, "register");
153
- async function registerAsync(instance) {
151
+ __name(registerParallel, "registerParallel");
152
+ async function registerSerial(instance) {
154
153
  const stateVars = getExposeKey(instance);
155
154
  for (const item of stateVars) {
156
155
  const handlers = getHandler(instance, item);
@@ -158,18 +157,15 @@ async function registerAsync(instance) {
158
157
  await hanlder.init?.(instance);
159
158
  }
160
159
  }
161
- __name(registerAsync, "registerAsync");
160
+ __name(registerSerial, "registerSerial");
162
161
 
163
162
  // src/helper.ts
164
- function getTag(module) {
165
- return module.prototype?.__TAG__;
163
+ function getTag(moduleOrInstance) {
164
+ if (typeof moduleOrInstance === "object")
165
+ moduleOrInstance = moduleOrInstance.constructor;
166
+ return moduleOrInstance.prototype?.__TAG__ || moduleOrInstance.name;
166
167
  }
167
168
  __name(getTag, "getTag");
168
- function getSymbol(instance) {
169
- const module = instance.constructor;
170
- return getTag(module) || module.name;
171
- }
172
- __name(getSymbol, "getSymbol");
173
169
  function getBind(module) {
174
170
  const instance = new module();
175
171
  const keys = getModuleState(instance);
@@ -370,6 +366,12 @@ function Nested(module) {
370
366
  });
371
367
  }
372
368
  __name(Nested, "Nested");
369
+ function Isolate() {
370
+ return (target) => {
371
+ target.prototype.__ISOLATE__ = true;
372
+ };
373
+ }
374
+ __name(Isolate, "Isolate");
373
375
 
374
376
  // src/custom/decorator.ts
375
377
  var activeInstance = {};
@@ -472,6 +474,7 @@ export {
472
474
  Ignore,
473
475
  Init,
474
476
  Inject,
477
+ Isolate,
475
478
  Nested,
476
479
  Pipeline,
477
480
  Provide,
@@ -494,15 +497,14 @@ export {
494
497
  getOwnState,
495
498
  getProperty,
496
499
  getState,
497
- getSymbol,
498
500
  getTag,
499
501
  init,
500
502
  injectProperty,
501
503
  isPhecda,
502
504
  plainToClass,
503
505
  regisHandler,
504
- register,
505
- registerAsync,
506
+ registerParallel,
507
+ registerSerial,
506
508
  setExposeKey,
507
509
  setIgnoreKey,
508
510
  setState,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.0-alpha.4",
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",