phecda-core 3.0.0-alpha.3 → 3.0.0-alpha.5

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
@@ -41,18 +41,17 @@ 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
42
  declare function Isolate(): (target: any) => void;
43
43
 
44
- declare function getTag<M extends new (...args: any) => any>(module: M): any;
45
- declare function getSymbol<M extends new (...args: any) => any>(instance: InstanceType<M>): any;
46
- declare function getBind<M extends new (...args: any) => any>(module: M): any;
47
- declare function plainToClass<M extends new (...args: any) => any, Data extends Record<PropertyKey, any>>(module: M, input: Data): InstanceType<M>;
48
- 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[]>;
49
48
  declare function classToValue<M>(instance: M): ClassValue<M>;
50
- declare function snapShot<T extends new (...args: any) => any>(data: InstanceType<T>): {
49
+ declare function snapShot<T extends Construct>(data: InstanceType<T>): {
51
50
  data: InstanceType<T>;
52
51
  clear(): void;
53
52
  apply(): void;
54
53
  };
55
- 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;
56
55
  declare function Pipeline(...decos: ((...args: any) => void)[]): (...args: any) => void;
57
56
 
58
57
  declare function isPhecda(module: any): module is Construct;
@@ -72,8 +71,8 @@ declare function getHandler(instance: Phecda, key: PropertyKey): any[];
72
71
  declare function setState(proto: Phecda, key: PropertyKey, state: Record<string, any>): void;
73
72
  declare function getOwnState(instance: Phecda, key: PropertyKey): Object;
74
73
  declare function getState(instance: Phecda, key: PropertyKey): any;
75
- declare function register(instance: Phecda): void;
76
- declare function registerAsync(instance: Phecda): Promise<void>;
74
+ declare function registerParallel(instance: Phecda): Promise<any[]>;
75
+ declare function registerSerial(instance: Phecda): Promise<void>;
77
76
 
78
77
  declare const activeInstance: Record<string, any>;
79
78
  declare function injectProperty(key: string, value: any): Record<string, any>;
@@ -84,4 +83,4 @@ declare function Watcher(eventName: keyof Events, options?: {
84
83
  declare function Effect(eventName: string, options?: any): (proto: any, key: string) => void;
85
84
  declare function Storage(storeKey?: string): (proto: any, key?: PropertyKey) => void;
86
85
 
87
- 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, 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
@@ -56,15 +56,14 @@ __export(src_exports, {
56
56
  getOwnState: () => getOwnState,
57
57
  getProperty: () => getProperty,
58
58
  getState: () => getState,
59
- getSymbol: () => getSymbol,
60
59
  getTag: () => getTag,
61
60
  init: () => init,
62
61
  injectProperty: () => injectProperty,
63
62
  isPhecda: () => isPhecda,
64
63
  plainToClass: () => plainToClass,
65
64
  regisHandler: () => regisHandler,
66
- register: () => register,
67
- registerAsync: () => registerAsync,
65
+ registerParallel: () => registerParallel,
66
+ registerSerial: () => registerSerial,
68
67
  setExposeKey: () => setExposeKey,
69
68
  setIgnoreKey: () => setIgnoreKey,
70
69
  setState: () => setState,
@@ -214,16 +213,15 @@ function getState(instance, key) {
214
213
  return ret;
215
214
  }
216
215
  __name(getState, "getState");
217
- function register(instance) {
216
+ function registerParallel(instance) {
218
217
  const stateVars = getExposeKey(instance);
219
- for (const item of stateVars) {
220
- const handlers = getHandler(instance, item);
221
- for (const hanlder of handlers)
222
- hanlder.init?.(instance);
223
- }
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);
224
222
  }
225
- __name(register, "register");
226
- async function registerAsync(instance) {
223
+ __name(registerParallel, "registerParallel");
224
+ async function registerSerial(instance) {
227
225
  const stateVars = getExposeKey(instance);
228
226
  for (const item of stateVars) {
229
227
  const handlers = getHandler(instance, item);
@@ -231,18 +229,15 @@ async function registerAsync(instance) {
231
229
  await hanlder.init?.(instance);
232
230
  }
233
231
  }
234
- __name(registerAsync, "registerAsync");
232
+ __name(registerSerial, "registerSerial");
235
233
 
236
234
  // src/helper.ts
237
- function getTag(module2) {
238
- return module2.prototype?.__TAG__;
235
+ function getTag(moduleOrInstance) {
236
+ if (typeof moduleOrInstance === "object")
237
+ moduleOrInstance = moduleOrInstance.constructor;
238
+ return moduleOrInstance.prototype?.__TAG__ || moduleOrInstance.name;
239
239
  }
240
240
  __name(getTag, "getTag");
241
- function getSymbol(instance) {
242
- const module2 = instance.constructor;
243
- return getTag(module2) || module2.name;
244
- }
245
- __name(getSymbol, "getSymbol");
246
241
  function getBind(module2) {
247
242
  const instance = new module2();
248
243
  const keys = getModuleState(instance);
@@ -326,7 +321,7 @@ function Init(proto, key) {
326
321
  setVar(proto, key);
327
322
  regisHandler(proto, key, {
328
323
  async init(instance) {
329
- instance[key]();
324
+ return instance[key]();
330
325
  }
331
326
  });
332
327
  }
@@ -575,15 +570,14 @@ __name(Storage, "Storage");
575
570
  getOwnState,
576
571
  getProperty,
577
572
  getState,
578
- getSymbol,
579
573
  getTag,
580
574
  init,
581
575
  injectProperty,
582
576
  isPhecda,
583
577
  plainToClass,
584
578
  regisHandler,
585
- register,
586
- registerAsync,
579
+ registerParallel,
580
+ registerSerial,
587
581
  setExposeKey,
588
582
  setIgnoreKey,
589
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);
@@ -253,7 +249,7 @@ function Init(proto, key) {
253
249
  setVar(proto, key);
254
250
  regisHandler(proto, key, {
255
251
  async init(instance) {
256
- instance[key]();
252
+ return instance[key]();
257
253
  }
258
254
  });
259
255
  }
@@ -501,15 +497,14 @@ export {
501
497
  getOwnState,
502
498
  getProperty,
503
499
  getState,
504
- getSymbol,
505
500
  getTag,
506
501
  init,
507
502
  injectProperty,
508
503
  isPhecda,
509
504
  plainToClass,
510
505
  regisHandler,
511
- register,
512
- registerAsync,
506
+ registerParallel,
507
+ registerSerial,
513
508
  setExposeKey,
514
509
  setIgnoreKey,
515
510
  setState,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "3.0.0-alpha.3",
3
+ "version": "3.0.0-alpha.5",
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",