phecda-core 2.1.1 → 3.0.0-alpha.1

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
@@ -10,7 +10,6 @@ interface Handler {
10
10
  interface Phecda {
11
11
  prototype: any;
12
12
  _namespace: {
13
- __INIT_EVENT__: Set<PropertyKey>;
14
13
  __EXPOSE_VAR__: Set<PropertyKey>;
15
14
  __IGNORE_VAR__: Set<PropertyKey>;
16
15
  __STATE_VAR__: Set<PropertyKey>;
@@ -24,26 +23,26 @@ type ClassValue<I> = {
24
23
  interface Events {
25
24
  }
26
25
 
27
- declare function Init(target: any, key: PropertyKey): void;
28
- declare function Bind(value: any): (target: any, k: PropertyKey) => void;
29
- declare function Ignore(target: any, key: PropertyKey): void;
30
- declare function Clear(target: any, key: PropertyKey): void;
31
- declare function Err<Fn extends (...args: any) => any>(cb: Fn): (target: any, key: PropertyKey) => void;
32
- declare function Expose(target: any, key: PropertyKey): void;
33
- declare function To(cb: (arg: any, instance: any, key: string) => any): (obj: any, key: PropertyKey) => void;
34
- declare function Tag(tag: string): (target: any) => void;
35
- declare function Assign(cb: (instance?: any) => any): (target: any) => void;
36
- declare function Global(target: any): void;
37
- declare function Empty(_target: any): void;
26
+ declare function Init(proto: any, key: PropertyKey): void;
27
+ declare function Bind(value: any): (proto: any, k: PropertyKey) => void;
28
+ declare function Ignore(proto: any, key: PropertyKey): void;
29
+ declare function Clear(proto: any, key: PropertyKey): void;
30
+ declare function Err<Fn extends (...args: any) => any>(cb: Fn): (proto: any, key: PropertyKey) => void;
31
+ declare function Expose(proto: any, key: PropertyKey): void;
32
+ declare function To(cb: (arg: any, instance: any, key: string) => any): (proto: any, key: PropertyKey) => void;
33
+ declare function Tag(tag: string): (module: any) => void;
34
+ declare function Assign(cb: (instance?: any) => any): (module: any) => void;
35
+ declare function Global(module: any): void;
36
+ declare function Empty(module: any): void;
38
37
  declare const DataMap: InjectData;
39
38
  declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
40
39
  declare function Inject<K extends keyof InjectData>(key: K): InjectData[K];
41
- declare function Nested<M extends new (...args: any) => any>(Model: M): (obj: any, key: PropertyKey) => void;
40
+ declare function Nested<M extends new (...args: any) => any>(module: M): (proto: any, key: PropertyKey) => void;
42
41
 
43
- declare function getTag<M extends new (...args: any) => any>(Model: M): any;
42
+ declare function getTag<M extends new (...args: any) => any>(module: M): any;
44
43
  declare function getSymbol<M extends new (...args: any) => any>(instance: InstanceType<M>): any;
45
- declare function getBind<M extends new (...args: any) => any>(Model: M): any;
46
- declare function plainToClass<M extends new (...args: any) => any, Data extends Record<PropertyKey, any>>(Model: M, input: Data): InstanceType<M>;
44
+ declare function getBind<M extends new (...args: any) => any>(module: M): any;
45
+ declare function plainToClass<M extends new (...args: any) => any, Data extends Record<PropertyKey, any>>(module: M, input: Data): InstanceType<M>;
47
46
  declare function transformClass<M extends new (...args: any) => any>(instance: InstanceType<M>, force?: boolean): Promise<string[]>;
48
47
  declare function classToValue<M>(instance: M): ClassValue<M>;
49
48
  declare function snapShot<T extends new (...args: any) => any>(data: InstanceType<T>): {
@@ -51,39 +50,36 @@ declare function snapShot<T extends new (...args: any) => any>(data: InstanceTyp
51
50
  clear(): void;
52
51
  apply(): void;
53
52
  };
54
- declare function addDecoToClass<M extends new (...args: any) => any>(c: M, key: keyof InstanceType<M> | string, handler: ((target: any, key: PropertyKey) => void), type?: 'static' | 'class' | 'normal'): void;
53
+ 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;
55
54
  declare function Pipeline(...decos: ((...args: any) => void)[]): (...args: any) => void;
56
55
 
57
- declare function isPhecda(target: any): any;
58
- declare function init(target: Phecda): void;
59
- declare function regisInitEvent(target: Phecda, key: string): void;
60
- declare function getOwnInitEvent(target: Phecda): string[];
61
- declare function getInitEvent(target: Phecda): PropertyKey[];
62
- declare function setModelVar(target: Phecda, key: PropertyKey): void;
63
- declare function setExposeKey(target: Phecda, key: PropertyKey): void;
64
- declare function setIgnoreKey(target: Phecda, key: PropertyKey): void;
65
- declare function getOwnModelState(target: Phecda): string[];
66
- declare function getModelState(target: Phecda): PropertyKey[];
67
- declare function getOwnExposeKey(target: Phecda): string[];
68
- declare function getExposeKey(target: Phecda): PropertyKey[];
69
- declare function getOwnIgnoreKey(target: Phecda): string[];
70
- declare function regisHandler(target: Phecda, key: PropertyKey, handler: Handler): void;
71
- declare function getOwnHandler(target: Phecda, key: PropertyKey): Handler[];
72
- declare function getHandler(target: Phecda, key: PropertyKey): any[];
73
- declare function setState(target: Phecda, key: PropertyKey, state: Record<string, any>): void;
74
- declare function getOwnState(target: Phecda, key: PropertyKey): Object;
75
- declare function getState(target: Phecda, key: PropertyKey): any;
56
+ declare function isPhecda(module: any): boolean;
57
+ declare const SHARE_KEY: unique symbol;
58
+ declare function init(proto: Phecda): void;
59
+ declare function setVar(proto: Phecda, key: PropertyKey): void;
60
+ declare function setExposeKey(proto: Phecda, key: PropertyKey): void;
61
+ declare function setIgnoreKey(proto: Phecda, key: PropertyKey): void;
62
+ declare function getOwnModuleState(instance: Phecda): string[];
63
+ declare function getModuleState(instance: Phecda): PropertyKey[];
64
+ declare function getOwnExposeKey(instance: Phecda): string[];
65
+ declare function getExposeKey(instance: Phecda): PropertyKey[];
66
+ declare function getOwnIgnoreKey(instance: Phecda): string[];
67
+ declare function regisHandler(proto: Phecda, key: PropertyKey, handler: Handler): void;
68
+ declare function getOwnHandler(instance: Phecda, key: PropertyKey): Handler[];
69
+ declare function getHandler(instance: Phecda, key: PropertyKey): any[];
70
+ declare function setState(proto: Phecda, key: PropertyKey, state: Record<string, any>): void;
71
+ declare function getOwnState(instance: Phecda, key: PropertyKey): Object;
72
+ declare function getState(instance: Phecda, key: PropertyKey): any;
76
73
  declare function register(instance: Phecda): void;
77
74
  declare function registerAsync(instance: Phecda): Promise<void>;
78
75
 
79
76
  declare const activeInstance: Record<string, any>;
80
77
  declare function injectProperty(key: string, value: any): Record<string, any>;
81
78
  declare function getProperty(key: string): any;
82
-
83
79
  declare function Watcher(eventName: keyof Events, options?: {
84
80
  once: boolean;
85
- }): (obj: any, key: string) => void;
86
- declare function Effect(eventName: string, options?: any): (obj: any, key: string) => void;
87
- declare function Storage(storeKey?: string): (target: any, key?: PropertyKey) => void;
81
+ }): (proto: any, key: string) => void;
82
+ declare function Effect(eventName: string, options?: any): (proto: any, key: string) => void;
83
+ declare function Storage(storeKey?: string): (proto: any, key?: PropertyKey) => void;
88
84
 
89
- export { Assign, Bind, ClassValue, Clear, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, NameSpace, Nested, Phecda, Pipeline, Provide, Storage, Tag, To, Watcher, activeInstance, addDecoToClass, classToValue, getBind, getExposeKey, getHandler, getInitEvent, getModelState, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnInitEvent, getOwnModelState, getOwnState, getProperty, getState, getSymbol, getTag, init, injectProperty, isPhecda, plainToClass, regisHandler, regisInitEvent, register, registerAsync, setExposeKey, setIgnoreKey, setModelVar, setState, snapShot, transformClass };
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, getSymbol, getTag, init, injectProperty, isPhecda, plainToClass, regisHandler, register, registerAsync, setExposeKey, setIgnoreKey, setState, setVar, snapShot, transformClass };
package/dist/index.js CHANGED
@@ -36,6 +36,7 @@ __export(src_exports, {
36
36
  Nested: () => Nested,
37
37
  Pipeline: () => Pipeline,
38
38
  Provide: () => Provide,
39
+ SHARE_KEY: () => SHARE_KEY,
39
40
  Storage: () => Storage,
40
41
  Tag: () => Tag,
41
42
  To: () => To,
@@ -46,13 +47,11 @@ __export(src_exports, {
46
47
  getBind: () => getBind,
47
48
  getExposeKey: () => getExposeKey,
48
49
  getHandler: () => getHandler,
49
- getInitEvent: () => getInitEvent,
50
- getModelState: () => getModelState,
50
+ getModuleState: () => getModuleState,
51
51
  getOwnExposeKey: () => getOwnExposeKey,
52
52
  getOwnHandler: () => getOwnHandler,
53
53
  getOwnIgnoreKey: () => getOwnIgnoreKey,
54
- getOwnInitEvent: () => getOwnInitEvent,
55
- getOwnModelState: () => getOwnModelState,
54
+ getOwnModuleState: () => getOwnModuleState,
56
55
  getOwnState: () => getOwnState,
57
56
  getProperty: () => getProperty,
58
57
  getState: () => getState,
@@ -63,29 +62,30 @@ __export(src_exports, {
63
62
  isPhecda: () => isPhecda,
64
63
  plainToClass: () => plainToClass,
65
64
  regisHandler: () => regisHandler,
66
- regisInitEvent: () => regisInitEvent,
67
65
  register: () => register,
68
66
  registerAsync: () => registerAsync,
69
67
  setExposeKey: () => setExposeKey,
70
68
  setIgnoreKey: () => setIgnoreKey,
71
- setModelVar: () => setModelVar,
72
69
  setState: () => setState,
70
+ setVar: () => setVar,
73
71
  snapShot: () => snapShot,
74
72
  transformClass: () => transformClass
75
73
  });
76
74
  module.exports = __toCommonJS(src_exports);
77
75
 
78
76
  // src/core.ts
79
- function isPhecda(target) {
80
- return target && !!target.prototype._namespace;
77
+ function isPhecda(module2) {
78
+ if (typeof module2 === "function")
79
+ return !!module2.prototype?._namespace;
80
+ return false;
81
81
  }
82
82
  __name(isPhecda, "isPhecda");
83
- function init(target) {
84
- if (!target)
83
+ var SHARE_KEY = Symbol("phecda-core");
84
+ function init(proto) {
85
+ if (!proto)
85
86
  return;
86
- if (!target.hasOwnProperty("_namespace")) {
87
- target._namespace = {
88
- __INIT_EVENT__: /* @__PURE__ */ new Set(),
87
+ if (!proto.hasOwnProperty("_namespace")) {
88
+ proto._namespace = {
89
89
  __EXPOSE_VAR__: /* @__PURE__ */ new Set(),
90
90
  __IGNORE_VAR__: /* @__PURE__ */ new Set(),
91
91
  __STATE_VAR__: /* @__PURE__ */ new Set(),
@@ -95,56 +95,31 @@ function init(target) {
95
95
  }
96
96
  }
97
97
  __name(init, "init");
98
- function regisInitEvent(target, key) {
99
- init(target);
100
- target._namespace.__INIT_EVENT__.add(key);
98
+ function setVar(proto, key) {
99
+ init(proto);
100
+ proto._namespace.__STATE_VAR__.add(key);
101
+ setExposeKey(proto, key);
101
102
  }
102
- __name(regisInitEvent, "regisInitEvent");
103
- function getOwnInitEvent(target) {
104
- if (!target?._namespace)
105
- return [];
106
- return [
107
- ...target._namespace.__INIT_EVENT__
108
- ];
109
- }
110
- __name(getOwnInitEvent, "getOwnInitEvent");
111
- function getInitEvent(target) {
112
- let proto = Object.getPrototypeOf(target);
113
- const set = /* @__PURE__ */ new Set();
114
- while (proto?._namespace) {
115
- proto._namespace.__INIT_EVENT__.forEach((item) => set.add(item));
116
- proto = Object.getPrototypeOf(proto);
117
- }
118
- return [
119
- ...set
120
- ];
121
- }
122
- __name(getInitEvent, "getInitEvent");
123
- function setModelVar(target, key) {
124
- init(target);
125
- target._namespace.__STATE_VAR__.add(key);
126
- setExposeKey(target, key);
127
- }
128
- __name(setModelVar, "setModelVar");
129
- function setExposeKey(target, key) {
130
- init(target);
131
- target._namespace.__EXPOSE_VAR__.add(key);
103
+ __name(setVar, "setVar");
104
+ function setExposeKey(proto, key) {
105
+ init(proto);
106
+ proto._namespace.__EXPOSE_VAR__.add(key);
132
107
  }
133
108
  __name(setExposeKey, "setExposeKey");
134
- function setIgnoreKey(target, key) {
135
- init(target);
136
- target._namespace.__IGNORE_VAR__.add(key);
109
+ function setIgnoreKey(proto, key) {
110
+ init(proto);
111
+ proto._namespace.__IGNORE_VAR__.add(key);
137
112
  }
138
113
  __name(setIgnoreKey, "setIgnoreKey");
139
- function getOwnModelState(target) {
140
- target = Object.getPrototypeOf(target);
114
+ function getOwnModuleState(instance) {
115
+ instance = Object.getPrototypeOf(instance);
141
116
  return [
142
- ...target._namespace.__STATE_VAR__
117
+ ...instance._namespace.__STATE_VAR__
143
118
  ];
144
119
  }
145
- __name(getOwnModelState, "getOwnModelState");
146
- function getModelState(target) {
147
- let proto = Object.getPrototypeOf(target);
120
+ __name(getOwnModuleState, "getOwnModuleState");
121
+ function getModuleState(instance) {
122
+ let proto = Object.getPrototypeOf(instance);
148
123
  const set = /* @__PURE__ */ new Set();
149
124
  while (proto?._namespace) {
150
125
  proto._namespace.__STATE_VAR__.forEach((item) => set.add(item));
@@ -154,16 +129,16 @@ function getModelState(target) {
154
129
  ...set
155
130
  ];
156
131
  }
157
- __name(getModelState, "getModelState");
158
- function getOwnExposeKey(target) {
159
- target = Object.getPrototypeOf(target);
132
+ __name(getModuleState, "getModuleState");
133
+ function getOwnExposeKey(instance) {
134
+ instance = Object.getPrototypeOf(instance);
160
135
  return [
161
- ...target._namespace.__EXPOSE_VAR__
162
- ].filter((item) => !target._namespace.__IGNORE_VAR__.has(item));
136
+ ...instance._namespace.__EXPOSE_VAR__
137
+ ].filter((item) => !instance._namespace.__IGNORE_VAR__.has(item));
163
138
  }
164
139
  __name(getOwnExposeKey, "getOwnExposeKey");
165
- function getExposeKey(target) {
166
- let proto = Object.getPrototypeOf(target);
140
+ function getExposeKey(instance) {
141
+ let proto = Object.getPrototypeOf(instance);
167
142
  const set = /* @__PURE__ */ new Set();
168
143
  while (proto?._namespace) {
169
144
  [
@@ -176,32 +151,32 @@ function getExposeKey(target) {
176
151
  ];
177
152
  }
178
153
  __name(getExposeKey, "getExposeKey");
179
- function getOwnIgnoreKey(target) {
180
- if (!target?._namespace)
154
+ function getOwnIgnoreKey(instance) {
155
+ if (!instance?._namespace)
181
156
  return [];
182
157
  return [
183
- ...target._namespace.__IGNORE_VAR__
158
+ ...instance._namespace.__IGNORE_VAR__
184
159
  ];
185
160
  }
186
161
  __name(getOwnIgnoreKey, "getOwnIgnoreKey");
187
- function regisHandler(target, key, handler) {
188
- init(target);
189
- if (!target._namespace.__STATE_HANDLER__.has(key))
190
- target._namespace.__STATE_HANDLER__.set(key, [
162
+ function regisHandler(proto, key, handler) {
163
+ init(proto);
164
+ if (!proto._namespace.__STATE_HANDLER__.has(key))
165
+ proto._namespace.__STATE_HANDLER__.set(key, [
191
166
  handler
192
167
  ]);
193
168
  else
194
- target._namespace.__STATE_HANDLER__.get(key).push(handler);
169
+ proto._namespace.__STATE_HANDLER__.get(key).push(handler);
195
170
  }
196
171
  __name(regisHandler, "regisHandler");
197
- function getOwnHandler(target, key) {
198
- if (!target?._namespace)
172
+ function getOwnHandler(instance, key) {
173
+ if (!instance?._namespace)
199
174
  return [];
200
- return target._namespace.__STATE_HANDLER__.get(key) || [];
175
+ return instance._namespace.__STATE_HANDLER__.get(key) || [];
201
176
  }
202
177
  __name(getOwnHandler, "getOwnHandler");
203
- function getHandler(target, key) {
204
- let proto = Object.getPrototypeOf(target);
178
+ function getHandler(instance, key) {
179
+ let proto = Object.getPrototypeOf(instance);
205
180
  const set = /* @__PURE__ */ new Set();
206
181
  while (proto?._namespace) {
207
182
  proto._namespace.__STATE_HANDLER__.get(key)?.forEach((item) => set.add(item));
@@ -212,19 +187,19 @@ function getHandler(target, key) {
212
187
  ];
213
188
  }
214
189
  __name(getHandler, "getHandler");
215
- function setState(target, key, state) {
216
- init(target);
217
- const namespace = target._namespace.__STATE_NAMESPACE__;
190
+ function setState(proto, key, state) {
191
+ init(proto);
192
+ const namespace = proto._namespace.__STATE_NAMESPACE__;
218
193
  namespace.set(key, state);
219
194
  }
220
195
  __name(setState, "setState");
221
- function getOwnState(target, key) {
222
- target = Object.getPrototypeOf(target);
223
- return target._namespace.__STATE_NAMESPACE__.get(key) || {};
196
+ function getOwnState(instance, key) {
197
+ instance = Object.getPrototypeOf(instance);
198
+ return instance._namespace.__STATE_NAMESPACE__.get(key) || {};
224
199
  }
225
200
  __name(getOwnState, "getOwnState");
226
- function getState(target, key) {
227
- let proto = Object.getPrototypeOf(target);
201
+ function getState(instance, key) {
202
+ let proto = Object.getPrototypeOf(instance);
228
203
  let ret = {};
229
204
  while (proto?._namespace) {
230
205
  const state = proto._namespace.__STATE_NAMESPACE__.get(key);
@@ -258,18 +233,18 @@ async function registerAsync(instance) {
258
233
  __name(registerAsync, "registerAsync");
259
234
 
260
235
  // src/helper.ts
261
- function getTag(Model) {
262
- return Model.prototype?.__TAG__;
236
+ function getTag(module2) {
237
+ return module2.prototype?.__TAG__;
263
238
  }
264
239
  __name(getTag, "getTag");
265
240
  function getSymbol(instance) {
266
- const Model = instance.constructor;
267
- return getTag(Model) || Model.name;
241
+ const module2 = instance.constructor;
242
+ return getTag(module2) || module2.name;
268
243
  }
269
244
  __name(getSymbol, "getSymbol");
270
- function getBind(Model) {
271
- const instance = new Model();
272
- const keys = getModelState(instance);
245
+ function getBind(module2) {
246
+ const instance = new module2();
247
+ const keys = getModuleState(instance);
273
248
  const ret = {};
274
249
  for (const item of keys) {
275
250
  const state = getState(instance, item);
@@ -279,8 +254,8 @@ function getBind(Model) {
279
254
  return ret;
280
255
  }
281
256
  __name(getBind, "getBind");
282
- function plainToClass(Model, input) {
283
- const instance = new Model();
257
+ function plainToClass(module2, input) {
258
+ const instance = new module2();
284
259
  const keys = getExposeKey(instance);
285
260
  for (const item of keys)
286
261
  instance[item] = input[item];
@@ -289,7 +264,7 @@ function plainToClass(Model, input) {
289
264
  __name(plainToClass, "plainToClass");
290
265
  async function transformClass(instance, force = false) {
291
266
  const err = [];
292
- const stateVars = getModelState(instance);
267
+ const stateVars = getModuleState(instance);
293
268
  for (const item of stateVars) {
294
269
  const handlers = getHandler(instance, item);
295
270
  if (handlers) {
@@ -333,8 +308,8 @@ function snapShot(data) {
333
308
  };
334
309
  }
335
310
  __name(snapShot, "snapShot");
336
- function addDecoToClass(c, key, handler, type = "normal") {
337
- handler(type === "normal" ? c.prototype : c, key);
311
+ function addDecoToClass(c, key, handler, type = "class") {
312
+ handler(type === "class" ? c.prototype : c, key);
338
313
  }
339
314
  __name(addDecoToClass, "addDecoToClass");
340
315
  function Pipeline(...decos) {
@@ -346,9 +321,9 @@ function Pipeline(...decos) {
346
321
  __name(Pipeline, "Pipeline");
347
322
 
348
323
  // src/decorators.ts
349
- function Init(target, key) {
350
- setModelVar(target, key);
351
- regisHandler(target, key, {
324
+ function Init(proto, key) {
325
+ setVar(proto, key);
326
+ regisHandler(proto, key, {
352
327
  async init(instance) {
353
328
  instance[key]();
354
329
  }
@@ -356,45 +331,44 @@ function Init(target, key) {
356
331
  }
357
332
  __name(Init, "Init");
358
333
  function Bind(value) {
359
- return (target, k) => {
360
- setModelVar(target, k);
361
- setState(target, k, {
334
+ return (proto, k) => {
335
+ setVar(proto, k);
336
+ setState(proto, k, {
362
337
  value
363
338
  });
364
339
  };
365
340
  }
366
341
  __name(Bind, "Bind");
367
- function Ignore(target, key) {
368
- setIgnoreKey(target, key);
342
+ function Ignore(proto, key) {
343
+ setIgnoreKey(proto, key);
369
344
  }
370
345
  __name(Ignore, "Ignore");
371
- function Clear(target, key) {
372
- init(target);
373
- target._namespace.__INIT_EVENT__.delete(key);
374
- target._namespace.__EXPOSE_VAR__.delete(key);
375
- target._namespace.__IGNORE_VAR__.delete(key);
376
- target._namespace.__STATE_VAR__.delete(key);
377
- target._namespace.__STATE_HANDLER__.delete(key);
378
- target._namespace.__STATE_NAMESPACE__.delete(key);
346
+ function Clear(proto, key) {
347
+ init(proto);
348
+ proto._namespace.__EXPOSE_VAR__.delete(key);
349
+ proto._namespace.__IGNORE_VAR__.delete(key);
350
+ proto._namespace.__STATE_VAR__.delete(key);
351
+ proto._namespace.__STATE_HANDLER__.delete(key);
352
+ proto._namespace.__STATE_NAMESPACE__.delete(key);
379
353
  }
380
354
  __name(Clear, "Clear");
381
355
  function Err(cb) {
382
- return (target, key) => {
383
- setModelVar(target, key);
384
- regisHandler(target, key, {
356
+ return (proto, key) => {
357
+ setVar(proto, key);
358
+ regisHandler(proto, key, {
385
359
  error: cb
386
360
  });
387
361
  };
388
362
  }
389
363
  __name(Err, "Err");
390
- function Expose(target, key) {
391
- setExposeKey(target, key);
364
+ function Expose(proto, key) {
365
+ setExposeKey(proto, key);
392
366
  }
393
367
  __name(Expose, "Expose");
394
368
  function To(cb) {
395
- return (obj, key) => {
396
- setModelVar(obj, key);
397
- regisHandler(obj, key, {
369
+ return (proto, key) => {
370
+ setVar(proto, key);
371
+ regisHandler(proto, key, {
398
372
  async pipe(instance) {
399
373
  instance[key] = await cb(instance[key], instance, key);
400
374
  }
@@ -403,17 +377,17 @@ function To(cb) {
403
377
  }
404
378
  __name(To, "To");
405
379
  function Tag(tag) {
406
- return (target) => {
407
- init(target.prototype);
408
- target.prototype.__TAG__ = tag;
380
+ return (module2) => {
381
+ init(module2.prototype);
382
+ module2.prototype.__TAG__ = tag;
409
383
  };
410
384
  }
411
385
  __name(Tag, "Tag");
412
386
  function Assign(cb) {
413
- return (target) => {
414
- init(target.prototype);
415
- setModelVar(target.prototype, "__CLASS");
416
- regisHandler(target.prototype, "__CLASS", {
387
+ return (module2) => {
388
+ init(module2.prototype);
389
+ setVar(module2.prototype, SHARE_KEY);
390
+ regisHandler(module2.prototype, SHARE_KEY, {
417
391
  init: async (instance) => {
418
392
  const value = await cb(instance);
419
393
  if (value && typeof value === "object" && !Array.isArray(value)) {
@@ -425,10 +399,10 @@ function Assign(cb) {
425
399
  };
426
400
  }
427
401
  __name(Assign, "Assign");
428
- function Global(target) {
429
- init(target.prototype);
430
- setModelVar(target.prototype, "__CLASS");
431
- regisHandler(target.prototype, "__CLASS", {
402
+ function Global(module2) {
403
+ init(module2.prototype);
404
+ setVar(module2.prototype, SHARE_KEY);
405
+ regisHandler(module2.prototype, SHARE_KEY, {
432
406
  init: async (instance) => {
433
407
  const tag = instance.__TAG__;
434
408
  if (!tag)
@@ -440,8 +414,8 @@ function Global(target) {
440
414
  });
441
415
  }
442
416
  __name(Global, "Global");
443
- function Empty(_target) {
444
- init(_target.prototype);
417
+ function Empty(module2) {
418
+ init(module2.prototype);
445
419
  }
446
420
  __name(Empty, "Empty");
447
421
  var DataMap = {};
@@ -458,9 +432,9 @@ function Inject(key) {
458
432
  return DataMap[key] || EmptyProxy;
459
433
  }
460
434
  __name(Inject, "Inject");
461
- function Nested(Model) {
435
+ function Nested(module2) {
462
436
  return To(async (property) => {
463
- const instance = plainToClass(Model, property);
437
+ const instance = plainToClass(module2, property);
464
438
  const err = await transformClass(instance);
465
439
  if (err.length > 0)
466
440
  throw new Error(err[0]);
@@ -469,7 +443,7 @@ function Nested(Model) {
469
443
  }
470
444
  __name(Nested, "Nested");
471
445
 
472
- // src/namespace.ts
446
+ // src/custom/decorator.ts
473
447
  var activeInstance = {};
474
448
  function injectProperty(key, value) {
475
449
  activeInstance[key] = value;
@@ -480,12 +454,10 @@ function getProperty(key) {
480
454
  return activeInstance[key];
481
455
  }
482
456
  __name(getProperty, "getProperty");
483
-
484
- // src/custom/decorator.ts
485
457
  function Watcher(eventName, options) {
486
- return (obj, key) => {
487
- setModelVar(obj, key);
488
- regisHandler(obj, key, {
458
+ return (proto, key) => {
459
+ setVar(proto, key);
460
+ regisHandler(proto, key, {
489
461
  init(instance) {
490
462
  getProperty("watcher")?.({
491
463
  eventName,
@@ -499,9 +471,9 @@ function Watcher(eventName, options) {
499
471
  }
500
472
  __name(Watcher, "Watcher");
501
473
  function Effect(eventName, options) {
502
- return (obj, key) => {
503
- setModelVar(obj, key);
504
- regisHandler(obj, key, {
474
+ return (proto, key) => {
475
+ setVar(proto, key);
476
+ regisHandler(proto, key, {
505
477
  init(instance) {
506
478
  instance[`$_${key}`] = instance[key];
507
479
  Object.defineProperty(instance, key, {
@@ -525,14 +497,14 @@ function Effect(eventName, options) {
525
497
  }
526
498
  __name(Effect, "Effect");
527
499
  function Storage(storeKey) {
528
- return (target, key) => {
500
+ return (proto, key) => {
529
501
  let tag;
530
502
  if (key) {
531
- init(target);
532
- tag = storeKey || target.__TAG__;
503
+ init(proto);
504
+ tag = storeKey || proto.__TAG__;
533
505
  const uniTag = Symbol(tag);
534
- setModelVar(target, uniTag);
535
- regisHandler(target, uniTag, {
506
+ setVar(proto, uniTag);
507
+ regisHandler(proto, uniTag, {
536
508
  init: (instance) => {
537
509
  getProperty("storage")?.({
538
510
  instance,
@@ -542,11 +514,11 @@ function Storage(storeKey) {
542
514
  }
543
515
  });
544
516
  } else {
545
- init(target.prototype);
546
- tag = storeKey || `${target.prototype.__TAG__}_${key}`;
517
+ init(proto.prototype);
518
+ tag = storeKey || `${proto.prototype.__TAG__}_${key}`;
547
519
  const uniTag = Symbol(tag);
548
- setModelVar(target.prototype, uniTag);
549
- regisHandler(target.prototype, uniTag, {
520
+ setVar(proto.prototype, uniTag);
521
+ regisHandler(proto.prototype, uniTag, {
550
522
  init: (instance) => {
551
523
  getProperty("storage")?.({
552
524
  instance,
@@ -576,6 +548,7 @@ __name(Storage, "Storage");
576
548
  Nested,
577
549
  Pipeline,
578
550
  Provide,
551
+ SHARE_KEY,
579
552
  Storage,
580
553
  Tag,
581
554
  To,
@@ -586,13 +559,11 @@ __name(Storage, "Storage");
586
559
  getBind,
587
560
  getExposeKey,
588
561
  getHandler,
589
- getInitEvent,
590
- getModelState,
562
+ getModuleState,
591
563
  getOwnExposeKey,
592
564
  getOwnHandler,
593
565
  getOwnIgnoreKey,
594
- getOwnInitEvent,
595
- getOwnModelState,
566
+ getOwnModuleState,
596
567
  getOwnState,
597
568
  getProperty,
598
569
  getState,
@@ -603,13 +574,12 @@ __name(Storage, "Storage");
603
574
  isPhecda,
604
575
  plainToClass,
605
576
  regisHandler,
606
- regisInitEvent,
607
577
  register,
608
578
  registerAsync,
609
579
  setExposeKey,
610
580
  setIgnoreKey,
611
- setModelVar,
612
581
  setState,
582
+ setVar,
613
583
  snapShot,
614
584
  transformClass
615
585
  });
package/dist/index.mjs CHANGED
@@ -2,16 +2,18 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
4
  // src/core.ts
5
- function isPhecda(target) {
6
- return target && !!target.prototype._namespace;
5
+ function isPhecda(module) {
6
+ if (typeof module === "function")
7
+ return !!module.prototype?._namespace;
8
+ return false;
7
9
  }
8
10
  __name(isPhecda, "isPhecda");
9
- function init(target) {
10
- if (!target)
11
+ var SHARE_KEY = Symbol("phecda-core");
12
+ function init(proto) {
13
+ if (!proto)
11
14
  return;
12
- if (!target.hasOwnProperty("_namespace")) {
13
- target._namespace = {
14
- __INIT_EVENT__: /* @__PURE__ */ new Set(),
15
+ if (!proto.hasOwnProperty("_namespace")) {
16
+ proto._namespace = {
15
17
  __EXPOSE_VAR__: /* @__PURE__ */ new Set(),
16
18
  __IGNORE_VAR__: /* @__PURE__ */ new Set(),
17
19
  __STATE_VAR__: /* @__PURE__ */ new Set(),
@@ -21,56 +23,31 @@ function init(target) {
21
23
  }
22
24
  }
23
25
  __name(init, "init");
24
- function regisInitEvent(target, key) {
25
- init(target);
26
- target._namespace.__INIT_EVENT__.add(key);
26
+ function setVar(proto, key) {
27
+ init(proto);
28
+ proto._namespace.__STATE_VAR__.add(key);
29
+ setExposeKey(proto, key);
27
30
  }
28
- __name(regisInitEvent, "regisInitEvent");
29
- function getOwnInitEvent(target) {
30
- if (!target?._namespace)
31
- return [];
32
- return [
33
- ...target._namespace.__INIT_EVENT__
34
- ];
35
- }
36
- __name(getOwnInitEvent, "getOwnInitEvent");
37
- function getInitEvent(target) {
38
- let proto = Object.getPrototypeOf(target);
39
- const set = /* @__PURE__ */ new Set();
40
- while (proto?._namespace) {
41
- proto._namespace.__INIT_EVENT__.forEach((item) => set.add(item));
42
- proto = Object.getPrototypeOf(proto);
43
- }
44
- return [
45
- ...set
46
- ];
47
- }
48
- __name(getInitEvent, "getInitEvent");
49
- function setModelVar(target, key) {
50
- init(target);
51
- target._namespace.__STATE_VAR__.add(key);
52
- setExposeKey(target, key);
53
- }
54
- __name(setModelVar, "setModelVar");
55
- function setExposeKey(target, key) {
56
- init(target);
57
- target._namespace.__EXPOSE_VAR__.add(key);
31
+ __name(setVar, "setVar");
32
+ function setExposeKey(proto, key) {
33
+ init(proto);
34
+ proto._namespace.__EXPOSE_VAR__.add(key);
58
35
  }
59
36
  __name(setExposeKey, "setExposeKey");
60
- function setIgnoreKey(target, key) {
61
- init(target);
62
- target._namespace.__IGNORE_VAR__.add(key);
37
+ function setIgnoreKey(proto, key) {
38
+ init(proto);
39
+ proto._namespace.__IGNORE_VAR__.add(key);
63
40
  }
64
41
  __name(setIgnoreKey, "setIgnoreKey");
65
- function getOwnModelState(target) {
66
- target = Object.getPrototypeOf(target);
42
+ function getOwnModuleState(instance) {
43
+ instance = Object.getPrototypeOf(instance);
67
44
  return [
68
- ...target._namespace.__STATE_VAR__
45
+ ...instance._namespace.__STATE_VAR__
69
46
  ];
70
47
  }
71
- __name(getOwnModelState, "getOwnModelState");
72
- function getModelState(target) {
73
- let proto = Object.getPrototypeOf(target);
48
+ __name(getOwnModuleState, "getOwnModuleState");
49
+ function getModuleState(instance) {
50
+ let proto = Object.getPrototypeOf(instance);
74
51
  const set = /* @__PURE__ */ new Set();
75
52
  while (proto?._namespace) {
76
53
  proto._namespace.__STATE_VAR__.forEach((item) => set.add(item));
@@ -80,16 +57,16 @@ function getModelState(target) {
80
57
  ...set
81
58
  ];
82
59
  }
83
- __name(getModelState, "getModelState");
84
- function getOwnExposeKey(target) {
85
- target = Object.getPrototypeOf(target);
60
+ __name(getModuleState, "getModuleState");
61
+ function getOwnExposeKey(instance) {
62
+ instance = Object.getPrototypeOf(instance);
86
63
  return [
87
- ...target._namespace.__EXPOSE_VAR__
88
- ].filter((item) => !target._namespace.__IGNORE_VAR__.has(item));
64
+ ...instance._namespace.__EXPOSE_VAR__
65
+ ].filter((item) => !instance._namespace.__IGNORE_VAR__.has(item));
89
66
  }
90
67
  __name(getOwnExposeKey, "getOwnExposeKey");
91
- function getExposeKey(target) {
92
- let proto = Object.getPrototypeOf(target);
68
+ function getExposeKey(instance) {
69
+ let proto = Object.getPrototypeOf(instance);
93
70
  const set = /* @__PURE__ */ new Set();
94
71
  while (proto?._namespace) {
95
72
  [
@@ -102,32 +79,32 @@ function getExposeKey(target) {
102
79
  ];
103
80
  }
104
81
  __name(getExposeKey, "getExposeKey");
105
- function getOwnIgnoreKey(target) {
106
- if (!target?._namespace)
82
+ function getOwnIgnoreKey(instance) {
83
+ if (!instance?._namespace)
107
84
  return [];
108
85
  return [
109
- ...target._namespace.__IGNORE_VAR__
86
+ ...instance._namespace.__IGNORE_VAR__
110
87
  ];
111
88
  }
112
89
  __name(getOwnIgnoreKey, "getOwnIgnoreKey");
113
- function regisHandler(target, key, handler) {
114
- init(target);
115
- if (!target._namespace.__STATE_HANDLER__.has(key))
116
- target._namespace.__STATE_HANDLER__.set(key, [
90
+ function regisHandler(proto, key, handler) {
91
+ init(proto);
92
+ if (!proto._namespace.__STATE_HANDLER__.has(key))
93
+ proto._namespace.__STATE_HANDLER__.set(key, [
117
94
  handler
118
95
  ]);
119
96
  else
120
- target._namespace.__STATE_HANDLER__.get(key).push(handler);
97
+ proto._namespace.__STATE_HANDLER__.get(key).push(handler);
121
98
  }
122
99
  __name(regisHandler, "regisHandler");
123
- function getOwnHandler(target, key) {
124
- if (!target?._namespace)
100
+ function getOwnHandler(instance, key) {
101
+ if (!instance?._namespace)
125
102
  return [];
126
- return target._namespace.__STATE_HANDLER__.get(key) || [];
103
+ return instance._namespace.__STATE_HANDLER__.get(key) || [];
127
104
  }
128
105
  __name(getOwnHandler, "getOwnHandler");
129
- function getHandler(target, key) {
130
- let proto = Object.getPrototypeOf(target);
106
+ function getHandler(instance, key) {
107
+ let proto = Object.getPrototypeOf(instance);
131
108
  const set = /* @__PURE__ */ new Set();
132
109
  while (proto?._namespace) {
133
110
  proto._namespace.__STATE_HANDLER__.get(key)?.forEach((item) => set.add(item));
@@ -138,19 +115,19 @@ function getHandler(target, key) {
138
115
  ];
139
116
  }
140
117
  __name(getHandler, "getHandler");
141
- function setState(target, key, state) {
142
- init(target);
143
- const namespace = target._namespace.__STATE_NAMESPACE__;
118
+ function setState(proto, key, state) {
119
+ init(proto);
120
+ const namespace = proto._namespace.__STATE_NAMESPACE__;
144
121
  namespace.set(key, state);
145
122
  }
146
123
  __name(setState, "setState");
147
- function getOwnState(target, key) {
148
- target = Object.getPrototypeOf(target);
149
- return target._namespace.__STATE_NAMESPACE__.get(key) || {};
124
+ function getOwnState(instance, key) {
125
+ instance = Object.getPrototypeOf(instance);
126
+ return instance._namespace.__STATE_NAMESPACE__.get(key) || {};
150
127
  }
151
128
  __name(getOwnState, "getOwnState");
152
- function getState(target, key) {
153
- let proto = Object.getPrototypeOf(target);
129
+ function getState(instance, key) {
130
+ let proto = Object.getPrototypeOf(instance);
154
131
  let ret = {};
155
132
  while (proto?._namespace) {
156
133
  const state = proto._namespace.__STATE_NAMESPACE__.get(key);
@@ -184,18 +161,18 @@ async function registerAsync(instance) {
184
161
  __name(registerAsync, "registerAsync");
185
162
 
186
163
  // src/helper.ts
187
- function getTag(Model) {
188
- return Model.prototype?.__TAG__;
164
+ function getTag(module) {
165
+ return module.prototype?.__TAG__;
189
166
  }
190
167
  __name(getTag, "getTag");
191
168
  function getSymbol(instance) {
192
- const Model = instance.constructor;
193
- return getTag(Model) || Model.name;
169
+ const module = instance.constructor;
170
+ return getTag(module) || module.name;
194
171
  }
195
172
  __name(getSymbol, "getSymbol");
196
- function getBind(Model) {
197
- const instance = new Model();
198
- const keys = getModelState(instance);
173
+ function getBind(module) {
174
+ const instance = new module();
175
+ const keys = getModuleState(instance);
199
176
  const ret = {};
200
177
  for (const item of keys) {
201
178
  const state = getState(instance, item);
@@ -205,8 +182,8 @@ function getBind(Model) {
205
182
  return ret;
206
183
  }
207
184
  __name(getBind, "getBind");
208
- function plainToClass(Model, input) {
209
- const instance = new Model();
185
+ function plainToClass(module, input) {
186
+ const instance = new module();
210
187
  const keys = getExposeKey(instance);
211
188
  for (const item of keys)
212
189
  instance[item] = input[item];
@@ -215,7 +192,7 @@ function plainToClass(Model, input) {
215
192
  __name(plainToClass, "plainToClass");
216
193
  async function transformClass(instance, force = false) {
217
194
  const err = [];
218
- const stateVars = getModelState(instance);
195
+ const stateVars = getModuleState(instance);
219
196
  for (const item of stateVars) {
220
197
  const handlers = getHandler(instance, item);
221
198
  if (handlers) {
@@ -259,8 +236,8 @@ function snapShot(data) {
259
236
  };
260
237
  }
261
238
  __name(snapShot, "snapShot");
262
- function addDecoToClass(c, key, handler, type = "normal") {
263
- handler(type === "normal" ? c.prototype : c, key);
239
+ function addDecoToClass(c, key, handler, type = "class") {
240
+ handler(type === "class" ? c.prototype : c, key);
264
241
  }
265
242
  __name(addDecoToClass, "addDecoToClass");
266
243
  function Pipeline(...decos) {
@@ -272,9 +249,9 @@ function Pipeline(...decos) {
272
249
  __name(Pipeline, "Pipeline");
273
250
 
274
251
  // src/decorators.ts
275
- function Init(target, key) {
276
- setModelVar(target, key);
277
- regisHandler(target, key, {
252
+ function Init(proto, key) {
253
+ setVar(proto, key);
254
+ regisHandler(proto, key, {
278
255
  async init(instance) {
279
256
  instance[key]();
280
257
  }
@@ -282,45 +259,44 @@ function Init(target, key) {
282
259
  }
283
260
  __name(Init, "Init");
284
261
  function Bind(value) {
285
- return (target, k) => {
286
- setModelVar(target, k);
287
- setState(target, k, {
262
+ return (proto, k) => {
263
+ setVar(proto, k);
264
+ setState(proto, k, {
288
265
  value
289
266
  });
290
267
  };
291
268
  }
292
269
  __name(Bind, "Bind");
293
- function Ignore(target, key) {
294
- setIgnoreKey(target, key);
270
+ function Ignore(proto, key) {
271
+ setIgnoreKey(proto, key);
295
272
  }
296
273
  __name(Ignore, "Ignore");
297
- function Clear(target, key) {
298
- init(target);
299
- target._namespace.__INIT_EVENT__.delete(key);
300
- target._namespace.__EXPOSE_VAR__.delete(key);
301
- target._namespace.__IGNORE_VAR__.delete(key);
302
- target._namespace.__STATE_VAR__.delete(key);
303
- target._namespace.__STATE_HANDLER__.delete(key);
304
- target._namespace.__STATE_NAMESPACE__.delete(key);
274
+ function Clear(proto, key) {
275
+ init(proto);
276
+ proto._namespace.__EXPOSE_VAR__.delete(key);
277
+ proto._namespace.__IGNORE_VAR__.delete(key);
278
+ proto._namespace.__STATE_VAR__.delete(key);
279
+ proto._namespace.__STATE_HANDLER__.delete(key);
280
+ proto._namespace.__STATE_NAMESPACE__.delete(key);
305
281
  }
306
282
  __name(Clear, "Clear");
307
283
  function Err(cb) {
308
- return (target, key) => {
309
- setModelVar(target, key);
310
- regisHandler(target, key, {
284
+ return (proto, key) => {
285
+ setVar(proto, key);
286
+ regisHandler(proto, key, {
311
287
  error: cb
312
288
  });
313
289
  };
314
290
  }
315
291
  __name(Err, "Err");
316
- function Expose(target, key) {
317
- setExposeKey(target, key);
292
+ function Expose(proto, key) {
293
+ setExposeKey(proto, key);
318
294
  }
319
295
  __name(Expose, "Expose");
320
296
  function To(cb) {
321
- return (obj, key) => {
322
- setModelVar(obj, key);
323
- regisHandler(obj, key, {
297
+ return (proto, key) => {
298
+ setVar(proto, key);
299
+ regisHandler(proto, key, {
324
300
  async pipe(instance) {
325
301
  instance[key] = await cb(instance[key], instance, key);
326
302
  }
@@ -329,17 +305,17 @@ function To(cb) {
329
305
  }
330
306
  __name(To, "To");
331
307
  function Tag(tag) {
332
- return (target) => {
333
- init(target.prototype);
334
- target.prototype.__TAG__ = tag;
308
+ return (module) => {
309
+ init(module.prototype);
310
+ module.prototype.__TAG__ = tag;
335
311
  };
336
312
  }
337
313
  __name(Tag, "Tag");
338
314
  function Assign(cb) {
339
- return (target) => {
340
- init(target.prototype);
341
- setModelVar(target.prototype, "__CLASS");
342
- regisHandler(target.prototype, "__CLASS", {
315
+ return (module) => {
316
+ init(module.prototype);
317
+ setVar(module.prototype, SHARE_KEY);
318
+ regisHandler(module.prototype, SHARE_KEY, {
343
319
  init: async (instance) => {
344
320
  const value = await cb(instance);
345
321
  if (value && typeof value === "object" && !Array.isArray(value)) {
@@ -351,10 +327,10 @@ function Assign(cb) {
351
327
  };
352
328
  }
353
329
  __name(Assign, "Assign");
354
- function Global(target) {
355
- init(target.prototype);
356
- setModelVar(target.prototype, "__CLASS");
357
- regisHandler(target.prototype, "__CLASS", {
330
+ function Global(module) {
331
+ init(module.prototype);
332
+ setVar(module.prototype, SHARE_KEY);
333
+ regisHandler(module.prototype, SHARE_KEY, {
358
334
  init: async (instance) => {
359
335
  const tag = instance.__TAG__;
360
336
  if (!tag)
@@ -366,8 +342,8 @@ function Global(target) {
366
342
  });
367
343
  }
368
344
  __name(Global, "Global");
369
- function Empty(_target) {
370
- init(_target.prototype);
345
+ function Empty(module) {
346
+ init(module.prototype);
371
347
  }
372
348
  __name(Empty, "Empty");
373
349
  var DataMap = {};
@@ -384,9 +360,9 @@ function Inject(key) {
384
360
  return DataMap[key] || EmptyProxy;
385
361
  }
386
362
  __name(Inject, "Inject");
387
- function Nested(Model) {
363
+ function Nested(module) {
388
364
  return To(async (property) => {
389
- const instance = plainToClass(Model, property);
365
+ const instance = plainToClass(module, property);
390
366
  const err = await transformClass(instance);
391
367
  if (err.length > 0)
392
368
  throw new Error(err[0]);
@@ -395,7 +371,7 @@ function Nested(Model) {
395
371
  }
396
372
  __name(Nested, "Nested");
397
373
 
398
- // src/namespace.ts
374
+ // src/custom/decorator.ts
399
375
  var activeInstance = {};
400
376
  function injectProperty(key, value) {
401
377
  activeInstance[key] = value;
@@ -406,12 +382,10 @@ function getProperty(key) {
406
382
  return activeInstance[key];
407
383
  }
408
384
  __name(getProperty, "getProperty");
409
-
410
- // src/custom/decorator.ts
411
385
  function Watcher(eventName, options) {
412
- return (obj, key) => {
413
- setModelVar(obj, key);
414
- regisHandler(obj, key, {
386
+ return (proto, key) => {
387
+ setVar(proto, key);
388
+ regisHandler(proto, key, {
415
389
  init(instance) {
416
390
  getProperty("watcher")?.({
417
391
  eventName,
@@ -425,9 +399,9 @@ function Watcher(eventName, options) {
425
399
  }
426
400
  __name(Watcher, "Watcher");
427
401
  function Effect(eventName, options) {
428
- return (obj, key) => {
429
- setModelVar(obj, key);
430
- regisHandler(obj, key, {
402
+ return (proto, key) => {
403
+ setVar(proto, key);
404
+ regisHandler(proto, key, {
431
405
  init(instance) {
432
406
  instance[`$_${key}`] = instance[key];
433
407
  Object.defineProperty(instance, key, {
@@ -451,14 +425,14 @@ function Effect(eventName, options) {
451
425
  }
452
426
  __name(Effect, "Effect");
453
427
  function Storage(storeKey) {
454
- return (target, key) => {
428
+ return (proto, key) => {
455
429
  let tag;
456
430
  if (key) {
457
- init(target);
458
- tag = storeKey || target.__TAG__;
431
+ init(proto);
432
+ tag = storeKey || proto.__TAG__;
459
433
  const uniTag = Symbol(tag);
460
- setModelVar(target, uniTag);
461
- regisHandler(target, uniTag, {
434
+ setVar(proto, uniTag);
435
+ regisHandler(proto, uniTag, {
462
436
  init: (instance) => {
463
437
  getProperty("storage")?.({
464
438
  instance,
@@ -468,11 +442,11 @@ function Storage(storeKey) {
468
442
  }
469
443
  });
470
444
  } else {
471
- init(target.prototype);
472
- tag = storeKey || `${target.prototype.__TAG__}_${key}`;
445
+ init(proto.prototype);
446
+ tag = storeKey || `${proto.prototype.__TAG__}_${key}`;
473
447
  const uniTag = Symbol(tag);
474
- setModelVar(target.prototype, uniTag);
475
- regisHandler(target.prototype, uniTag, {
448
+ setVar(proto.prototype, uniTag);
449
+ regisHandler(proto.prototype, uniTag, {
476
450
  init: (instance) => {
477
451
  getProperty("storage")?.({
478
452
  instance,
@@ -501,6 +475,7 @@ export {
501
475
  Nested,
502
476
  Pipeline,
503
477
  Provide,
478
+ SHARE_KEY,
504
479
  Storage,
505
480
  Tag,
506
481
  To,
@@ -511,13 +486,11 @@ export {
511
486
  getBind,
512
487
  getExposeKey,
513
488
  getHandler,
514
- getInitEvent,
515
- getModelState,
489
+ getModuleState,
516
490
  getOwnExposeKey,
517
491
  getOwnHandler,
518
492
  getOwnIgnoreKey,
519
- getOwnInitEvent,
520
- getOwnModelState,
493
+ getOwnModuleState,
521
494
  getOwnState,
522
495
  getProperty,
523
496
  getState,
@@ -528,13 +501,12 @@ export {
528
501
  isPhecda,
529
502
  plainToClass,
530
503
  regisHandler,
531
- regisInitEvent,
532
504
  register,
533
505
  registerAsync,
534
506
  setExposeKey,
535
507
  setIgnoreKey,
536
- setModelVar,
537
508
  setState,
509
+ setVar,
538
510
  snapShot,
539
511
  transformClass
540
512
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "2.1.1",
3
+ "version": "3.0.0-alpha.1",
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",