phecda-core 3.0.0-beta.14 → 3.0.0-beta.16

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
@@ -1,8 +1,8 @@
1
1
  declare function Init(proto: any, key: PropertyKey): void;
2
2
  declare function Unmount(proto: any, key: PropertyKey): void;
3
3
  declare function Bind(value: any): (proto: any, k: PropertyKey) => void;
4
- declare function Ignore(proto: any, key: PropertyKey): void;
5
- declare function Clear(proto: any, key: PropertyKey): void;
4
+ declare function Ignore(proto: any, key?: PropertyKey): void;
5
+ declare function Clear(proto: any, key?: PropertyKey): void;
6
6
  declare function Expose(proto: any, key: PropertyKey): void;
7
7
  declare function Empty(model: any): void;
8
8
 
@@ -10,13 +10,14 @@ declare const SHARE_KEY: unique symbol;
10
10
  declare const PHECDA_KEY: unique symbol;
11
11
  declare function isPhecda(model: any): model is Construct;
12
12
  declare function init(proto: Phecda): void;
13
- declare function setStateVar(proto: Phecda, key: PropertyKey): void;
13
+ declare function getPhecdaFromTarget(target: any): any;
14
+ declare function setStateKey(proto: Phecda, key: PropertyKey): void;
14
15
  declare function setExposeKey(proto: Phecda, key: PropertyKey): void;
15
16
  declare function setIgnoreKey(proto: Phecda, key: PropertyKey): void;
16
17
  declare function setHandler(proto: Phecda, key: PropertyKey, handler: Handler): void;
17
18
  declare function setState(proto: Phecda, key: PropertyKey, state: Record<string, any>): void;
18
- declare function getOwnStateVars(target: any): string[];
19
- declare function getStateVars(target: any): PropertyKey[];
19
+ declare function getOwnStateKey(target: any): string[];
20
+ declare function getStateKey(target: any): PropertyKey[];
20
21
  declare function getOwnExposeKey(target: any): string[];
21
22
  declare function getExposeKey(target: any): PropertyKey[];
22
23
  declare function getOwnIgnoreKey(target: any): string[];
@@ -25,8 +26,8 @@ declare function getHandler(target: any, key: PropertyKey): any[];
25
26
  declare function getState(target: any, key: PropertyKey): any;
26
27
  declare function getOwnState(target: any, key: PropertyKey): Record<string, any>;
27
28
  declare function invokeHandler(event: string, module: Phecda): Promise<any[]>;
28
- declare function set(proto: Phecda, key: string, value: any): void;
29
- declare function get(proto: Phecda, key: string): any;
29
+ declare function set(proto: any, key: string, value: any): void;
30
+ declare function get(proto: any, key: string): any;
30
31
 
31
32
  interface NameSpace {
32
33
  [name: string]: Phecda;
@@ -42,12 +43,12 @@ interface Handler {
42
43
  interface Phecda {
43
44
  prototype: any;
44
45
  [PHECDA_KEY]: {
45
- __EXPOSE_VAR__: Set<PropertyKey>;
46
- __IGNORE_VAR__: Set<PropertyKey>;
47
- __STATE_VAR__: Set<PropertyKey>;
46
+ __EXPOSE_KEY: Set<PropertyKey>;
47
+ __IGNORE_KEY: Set<PropertyKey>;
48
+ __CLEAR_KEY: Set<PropertyKey>;
49
+ __STATE_KEY: Set<PropertyKey>;
48
50
  __STATE_HANDLER__: Map<PropertyKey, Handler[]>;
49
51
  __STATE_NAMESPACE__: Map<PropertyKey, Object>;
50
- [key: string]: any;
51
52
  };
52
53
  }
53
54
  type ClassValue<I> = {
@@ -65,7 +66,7 @@ declare function To(...callbacks: ((arg: any, instance: any, key: string) => any
65
66
  declare function Rule(cb: ((arg: any) => boolean | Promise<boolean>), info: string | (() => string)): (proto: any, key: PropertyKey) => void;
66
67
  declare function Err(cb: (e: Error | any, instance: any, key: string) => void, isCatch?: boolean): (proto: any, key: PropertyKey) => void;
67
68
  interface StorageParam {
68
- key?: string;
69
+ key: PropertyKey;
69
70
  instance: any;
70
71
  tag: string;
71
72
  toJSON: (str: string) => any;
@@ -83,9 +84,9 @@ declare function Watcher(eventName: keyof Events, options?: {
83
84
  once?: boolean;
84
85
  }): (proto: any, key: string) => void;
85
86
  declare function Effect(cb: (value: any, instance: any, key: string) => void): (proto: any, key: string) => void;
86
- declare function Storage({ key: storeKey, toJSON, toString }?: {
87
- toJSON?: (str: string) => any;
88
- toString?: (arg: any) => string;
87
+ declare function Storage({ key: storeKey, json, stringify }?: {
88
+ json?: (str: string) => any;
89
+ stringify?: (arg: any) => string;
89
90
  key?: string;
90
91
  }): (proto: any, key?: PropertyKey) => void;
91
92
 
@@ -110,7 +111,7 @@ declare const DataMap: InjectData;
110
111
  declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
111
112
  declare function Inject<K extends keyof InjectData>(key: K): InjectData[K];
112
113
  declare const activeInstance: Record<string, any>;
113
- declare function injectKey(key: string, value: any): Record<string, any>;
114
- declare function getKey(key: string): any;
114
+ declare function setInject(key: string, value: any): Record<string, any>;
115
+ declare function getInject(key: string): any;
115
116
 
116
- export { AbConstruct, Assign, Bind, ClassValue, Clear, Construct, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, Isolate, NameSpace, PHECDA_KEY, Phecda, Pipeline, Provide, Rule, SHARE_KEY, Storage, StorageParam, Tag, To, Unique, Unmount, Watcher, WatcherParam, activeInstance, addDecoToClass, classToPlain, get, getBind, getExposeKey, getHandler, getKey, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnState, getOwnStateVars, getState, getStateVars, getTag, init, injectKey, invokeHandler, isAsyncFunc, isPhecda, plainToClass, set, setExposeKey, setHandler, setIgnoreKey, setState, setStateVar, snapShot, transformInstance, transformInstanceAsync, transformProperty, transformPropertyAsync };
117
+ export { AbConstruct, Assign, Bind, ClassValue, Clear, Construct, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, Isolate, NameSpace, PHECDA_KEY, Phecda, Pipeline, Provide, Rule, SHARE_KEY, Storage, StorageParam, Tag, To, Unique, Unmount, Watcher, WatcherParam, activeInstance, addDecoToClass, classToPlain, get, getBind, getExposeKey, getHandler, getInject, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnState, getOwnStateKey, getPhecdaFromTarget, getState, getStateKey, getTag, init, invokeHandler, isAsyncFunc, isPhecda, plainToClass, set, setExposeKey, setHandler, setIgnoreKey, setInject, setState, setStateKey, snapShot, transformInstance, transformInstanceAsync, transformProperty, transformPropertyAsync };
package/dist/index.js CHANGED
@@ -52,17 +52,17 @@ __export(src_exports, {
52
52
  getBind: () => getBind,
53
53
  getExposeKey: () => getExposeKey,
54
54
  getHandler: () => getHandler,
55
- getKey: () => getKey,
55
+ getInject: () => getInject,
56
56
  getOwnExposeKey: () => getOwnExposeKey,
57
57
  getOwnHandler: () => getOwnHandler,
58
58
  getOwnIgnoreKey: () => getOwnIgnoreKey,
59
59
  getOwnState: () => getOwnState,
60
- getOwnStateVars: () => getOwnStateVars,
60
+ getOwnStateKey: () => getOwnStateKey,
61
+ getPhecdaFromTarget: () => getPhecdaFromTarget,
61
62
  getState: () => getState,
62
- getStateVars: () => getStateVars,
63
+ getStateKey: () => getStateKey,
63
64
  getTag: () => getTag,
64
65
  init: () => init,
65
- injectKey: () => injectKey,
66
66
  invokeHandler: () => invokeHandler,
67
67
  isAsyncFunc: () => isAsyncFunc,
68
68
  isPhecda: () => isPhecda,
@@ -71,8 +71,9 @@ __export(src_exports, {
71
71
  setExposeKey: () => setExposeKey,
72
72
  setHandler: () => setHandler,
73
73
  setIgnoreKey: () => setIgnoreKey,
74
+ setInject: () => setInject,
74
75
  setState: () => setState,
75
- setStateVar: () => setStateVar,
76
+ setStateKey: () => setStateKey,
76
77
  snapShot: () => snapShot,
77
78
  transformInstance: () => transformInstance,
78
79
  transformInstanceAsync: () => transformInstanceAsync,
@@ -95,9 +96,10 @@ function init(proto) {
95
96
  return;
96
97
  if (!proto.hasOwnProperty(PHECDA_KEY)) {
97
98
  proto[PHECDA_KEY] = {
98
- __EXPOSE_VAR__: /* @__PURE__ */ new Set(),
99
- __IGNORE_VAR__: /* @__PURE__ */ new Set(),
100
- __STATE_VAR__: /* @__PURE__ */ new Set(),
99
+ __EXPOSE_KEY: /* @__PURE__ */ new Set(),
100
+ __IGNORE_KEY: /* @__PURE__ */ new Set(),
101
+ __CLEAR_KEY: /* @__PURE__ */ new Set(),
102
+ __STATE_KEY: /* @__PURE__ */ new Set(),
101
103
  __STATE_HANDLER__: /* @__PURE__ */ new Map(),
102
104
  __STATE_NAMESPACE__: /* @__PURE__ */ new Map()
103
105
  };
@@ -112,20 +114,20 @@ function getPhecdaFromTarget(target) {
112
114
  return Object.getPrototypeOf(target);
113
115
  }
114
116
  __name(getPhecdaFromTarget, "getPhecdaFromTarget");
115
- function setStateVar(proto, key) {
117
+ function setStateKey(proto, key) {
116
118
  init(proto);
117
- proto[PHECDA_KEY].__STATE_VAR__.add(key);
119
+ proto[PHECDA_KEY].__STATE_KEY.add(key);
118
120
  setExposeKey(proto, key);
119
121
  }
120
- __name(setStateVar, "setStateVar");
122
+ __name(setStateKey, "setStateKey");
121
123
  function setExposeKey(proto, key) {
122
124
  init(proto);
123
- proto[PHECDA_KEY].__EXPOSE_VAR__.add(key);
125
+ proto[PHECDA_KEY].__EXPOSE_KEY.add(key);
124
126
  }
125
127
  __name(setExposeKey, "setExposeKey");
126
128
  function setIgnoreKey(proto, key) {
127
129
  init(proto);
128
- proto[PHECDA_KEY].__IGNORE_VAR__.add(key);
130
+ proto[PHECDA_KEY].__IGNORE_KEY.add(key);
129
131
  }
130
132
  __name(setIgnoreKey, "setIgnoreKey");
131
133
  function setHandler(proto, key, handler) {
@@ -144,39 +146,42 @@ function setState(proto, key, state) {
144
146
  namespace.set(key, state);
145
147
  }
146
148
  __name(setState, "setState");
147
- function getOwnStateVars(target) {
149
+ function getOwnStateKey(target) {
148
150
  const proto = getPhecdaFromTarget(target);
149
151
  return [
150
- ...proto[PHECDA_KEY].__STATE_VAR__
152
+ ...proto[PHECDA_KEY].__STATE_KEY
151
153
  ];
152
154
  }
153
- __name(getOwnStateVars, "getOwnStateVars");
154
- function getStateVars(target) {
155
+ __name(getOwnStateKey, "getOwnStateKey");
156
+ function getStateKey(target) {
155
157
  let proto = getPhecdaFromTarget(target);
156
158
  const set2 = /* @__PURE__ */ new Set();
157
159
  while (proto?.[PHECDA_KEY]) {
158
- proto[PHECDA_KEY].__STATE_VAR__.forEach((item) => set2.add(item));
160
+ if (proto.hasOwnProperty(PHECDA_KEY))
161
+ proto[PHECDA_KEY].__STATE_KEY.forEach((item) => set2.add(item));
159
162
  proto = Object.getPrototypeOf(proto);
160
163
  }
161
164
  return [
162
165
  ...set2
163
166
  ];
164
167
  }
165
- __name(getStateVars, "getStateVars");
168
+ __name(getStateKey, "getStateKey");
166
169
  function getOwnExposeKey(target) {
167
170
  const proto = getPhecdaFromTarget(target);
168
171
  return [
169
- ...proto[PHECDA_KEY].__EXPOSE_VAR__
170
- ].filter((item) => !proto[PHECDA_KEY].__IGNORE_VAR__.has(item));
172
+ ...proto[PHECDA_KEY].__EXPOSE_KEY
173
+ ].filter((item) => !proto[PHECDA_KEY].__IGNORE_KEY.has(item));
171
174
  }
172
175
  __name(getOwnExposeKey, "getOwnExposeKey");
173
176
  function getExposeKey(target) {
174
177
  let proto = getPhecdaFromTarget(target);
175
178
  const set2 = /* @__PURE__ */ new Set();
179
+ const origin = proto;
176
180
  while (proto?.[PHECDA_KEY]) {
177
- [
178
- ...proto[PHECDA_KEY].__EXPOSE_VAR__
179
- ].forEach((item) => !proto[PHECDA_KEY].__IGNORE_VAR__.has(item) && set2.add(item));
181
+ if (proto.hasOwnProperty(PHECDA_KEY))
182
+ [
183
+ ...proto[PHECDA_KEY].__EXPOSE_KEY
184
+ ].forEach((item) => !origin[PHECDA_KEY].__IGNORE_KEY.has(item) && set2.add(item));
180
185
  proto = Object.getPrototypeOf(proto);
181
186
  }
182
187
  return [
@@ -187,7 +192,7 @@ __name(getExposeKey, "getExposeKey");
187
192
  function getOwnIgnoreKey(target) {
188
193
  const proto = getPhecdaFromTarget(target);
189
194
  return [
190
- ...proto[PHECDA_KEY]?.__IGNORE_VAR__
195
+ ...proto[PHECDA_KEY]?.__IGNORE_KEY
191
196
  ];
192
197
  }
193
198
  __name(getOwnIgnoreKey, "getOwnIgnoreKey");
@@ -200,7 +205,11 @@ function getHandler(target, key) {
200
205
  let proto = getPhecdaFromTarget(target);
201
206
  const set2 = /* @__PURE__ */ new Set();
202
207
  while (proto?.[PHECDA_KEY]) {
203
- proto[PHECDA_KEY].__STATE_HANDLER__.get(key)?.forEach((item) => set2.add(item));
208
+ if (proto.hasOwnProperty(PHECDA_KEY)) {
209
+ proto[PHECDA_KEY].__STATE_HANDLER__.get(key)?.forEach((item) => set2.add(item));
210
+ if (proto[PHECDA_KEY].__CLEAR_KEY.has(key))
211
+ break;
212
+ }
204
213
  proto = Object.getPrototypeOf(proto);
205
214
  }
206
215
  return [
@@ -212,12 +221,16 @@ function getState(target, key) {
212
221
  let proto = getPhecdaFromTarget(target);
213
222
  let ret = {};
214
223
  while (proto?.[PHECDA_KEY]) {
215
- const state = proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key);
216
- if (state)
217
- ret = {
218
- ...state,
219
- ...ret
220
- };
224
+ if (proto.hasOwnProperty(PHECDA_KEY)) {
225
+ const state = proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key);
226
+ if (state)
227
+ ret = {
228
+ ...state,
229
+ ...ret
230
+ };
231
+ if (proto[PHECDA_KEY].__CLEAR_KEY.has(key))
232
+ break;
233
+ }
221
234
  proto = Object.getPrototypeOf(proto);
222
235
  }
223
236
  return ret;
@@ -238,17 +251,17 @@ function invokeHandler(event, module2) {
238
251
  __name(invokeHandler, "invokeHandler");
239
252
  function set(proto, key, value) {
240
253
  init(proto);
241
- proto[PHECDA_KEY][`__${key.toUpperCase()}__`] = value;
254
+ proto[`__${key.toUpperCase()}__`] = value;
242
255
  }
243
256
  __name(set, "set");
244
257
  function get(proto, key) {
245
- return proto[PHECDA_KEY]?.[`__${key.toUpperCase()}__`];
258
+ return proto[`__${key.toUpperCase()}__`];
246
259
  }
247
260
  __name(get, "get");
248
261
 
249
262
  // src/decorators/core.ts
250
263
  function Init(proto, key) {
251
- setStateVar(proto, key);
264
+ setStateKey(proto, key);
252
265
  setHandler(proto, key, {
253
266
  async init(instance) {
254
267
  return instance[key]();
@@ -257,7 +270,7 @@ function Init(proto, key) {
257
270
  }
258
271
  __name(Init, "Init");
259
272
  function Unmount(proto, key) {
260
- setStateVar(proto, key);
273
+ setStateKey(proto, key);
261
274
  setHandler(proto, key, {
262
275
  async unmount(instance) {
263
276
  return instance[key]();
@@ -267,24 +280,20 @@ function Unmount(proto, key) {
267
280
  __name(Unmount, "Unmount");
268
281
  function Bind(value) {
269
282
  return (proto, k) => {
270
- setStateVar(proto, k);
283
+ setStateKey(proto, k);
271
284
  setState(proto, k, {
272
285
  value
273
286
  });
274
287
  };
275
288
  }
276
289
  __name(Bind, "Bind");
277
- function Ignore(proto, key) {
290
+ function Ignore(proto, key = SHARE_KEY) {
278
291
  setIgnoreKey(proto, key);
279
292
  }
280
293
  __name(Ignore, "Ignore");
281
- function Clear(proto, key) {
294
+ function Clear(proto, key = SHARE_KEY) {
282
295
  init(proto);
283
- proto[PHECDA_KEY].__EXPOSE_VAR__.delete(key);
284
- proto[PHECDA_KEY].__IGNORE_VAR__.delete(key);
285
- proto[PHECDA_KEY].__STATE_VAR__.delete(key);
286
- proto[PHECDA_KEY].__STATE_HANDLER__.delete(key);
287
- proto[PHECDA_KEY].__STATE_NAMESPACE__.delete(key);
296
+ proto[PHECDA_KEY].__CLEAR_KEY.add(key);
288
297
  }
289
298
  __name(Clear, "Clear");
290
299
  function Expose(proto, key) {
@@ -300,12 +309,12 @@ __name(Empty, "Empty");
300
309
  function getTag(moduleOrInstance) {
301
310
  if (typeof moduleOrInstance === "object")
302
311
  moduleOrInstance = moduleOrInstance.constructor;
303
- return moduleOrInstance.prototype[PHECDA_KEY]?.__TAG__ || moduleOrInstance.name;
312
+ return get(moduleOrInstance.prototype, "tag") || moduleOrInstance.name;
304
313
  }
305
314
  __name(getTag, "getTag");
306
315
  function getBind(model) {
307
316
  const instance = new model();
308
- const keys = getStateVars(instance);
317
+ const keys = getStateKey(instance);
309
318
  const ret = {};
310
319
  for (const item of keys) {
311
320
  const state = getState(instance, item);
@@ -449,15 +458,15 @@ function Inject(key) {
449
458
  }
450
459
  __name(Inject, "Inject");
451
460
  var activeInstance = {};
452
- function injectKey(key, value) {
461
+ function setInject(key, value) {
453
462
  activeInstance[key] = value;
454
463
  return activeInstance;
455
464
  }
456
- __name(injectKey, "injectKey");
457
- function getKey(key) {
465
+ __name(setInject, "setInject");
466
+ function getInject(key) {
458
467
  return activeInstance[key];
459
468
  }
460
- __name(getKey, "getKey");
469
+ __name(getInject, "getInject");
461
470
 
462
471
  // src/decorators/function.ts
463
472
  function Isolate(model) {
@@ -480,7 +489,7 @@ __name(Unique, "Unique");
480
489
  function Assign(cb) {
481
490
  return (model) => {
482
491
  init(model.prototype);
483
- setStateVar(model.prototype, SHARE_KEY);
492
+ setStateKey(model.prototype, SHARE_KEY);
484
493
  setHandler(model.prototype, SHARE_KEY, {
485
494
  init: async (instance) => {
486
495
  const value = await cb(instance);
@@ -495,7 +504,7 @@ function Assign(cb) {
495
504
  __name(Assign, "Assign");
496
505
  function Global(model) {
497
506
  init(model.prototype);
498
- setStateVar(model.prototype, SHARE_KEY);
507
+ setStateKey(model.prototype, SHARE_KEY);
499
508
  setHandler(model.prototype, SHARE_KEY, {
500
509
  init: async (instance) => {
501
510
  const tag = instance[PHECDA_KEY].__TAG__;
@@ -510,7 +519,7 @@ function Global(model) {
510
519
  __name(Global, "Global");
511
520
  function To(...callbacks) {
512
521
  return (proto, key) => {
513
- setStateVar(proto, key);
522
+ setStateKey(proto, key);
514
523
  setHandler(proto, key, {
515
524
  async pipe(instance, addError) {
516
525
  for (const cb of callbacks) {
@@ -530,7 +539,7 @@ function To(...callbacks) {
530
539
  __name(To, "To");
531
540
  function Rule(cb, info) {
532
541
  return (proto, key) => {
533
- setStateVar(proto, key);
542
+ setStateKey(proto, key);
534
543
  setHandler(proto, key, {
535
544
  async pipe(instance, addError) {
536
545
  let ret;
@@ -551,7 +560,7 @@ function Rule(cb, info) {
551
560
  __name(Rule, "Rule");
552
561
  function Err(cb, isCatch = false) {
553
562
  return (proto, key) => {
554
- setStateVar(proto, key);
563
+ setStateKey(proto, key);
555
564
  setHandler(proto, key, {
556
565
  init: (instance) => {
557
566
  if (typeof instance[key] === "function") {
@@ -586,10 +595,10 @@ __name(Err, "Err");
586
595
  function Watcher(eventName, options) {
587
596
  let cb;
588
597
  return (proto, key) => {
589
- setStateVar(proto, key);
598
+ setStateKey(proto, key);
590
599
  setHandler(proto, key, {
591
600
  init(instance) {
592
- return cb = getKey("watcher")?.({
601
+ return cb = getInject("watcher")?.({
593
602
  eventName,
594
603
  instance,
595
604
  key,
@@ -605,7 +614,7 @@ function Watcher(eventName, options) {
605
614
  __name(Watcher, "Watcher");
606
615
  function Effect(cb) {
607
616
  return (proto, key) => {
608
- setStateVar(proto, key);
617
+ setStateKey(proto, key);
609
618
  setHandler(proto, key, {
610
619
  init(instance) {
611
620
  instance[`$_${key}`] = instance[key];
@@ -624,44 +633,28 @@ function Effect(cb) {
624
633
  };
625
634
  }
626
635
  __name(Effect, "Effect");
627
- function Storage({ key: storeKey, toJSON, toString } = {}) {
628
- if (!toJSON)
629
- toJSON = /* @__PURE__ */ __name((v) => JSON.parse(v), "toJSON");
630
- if (!toString)
631
- toString = /* @__PURE__ */ __name((v) => JSON.stringify(v), "toString");
632
- return (proto, key) => {
633
- let tag;
634
- if (key) {
635
- init(proto);
636
- tag = storeKey || `${getTag(proto)}_${key}`;
637
- setStateVar(proto, key);
638
- setHandler(proto, key, {
639
- init: (instance) => {
640
- return getKey("storage")?.({
641
- instance,
642
- key,
643
- tag,
644
- toJSON,
645
- toString
646
- });
647
- }
648
- });
649
- } else {
650
- init(proto.prototype);
651
- tag = storeKey || getTag(proto);
652
- setStateVar(proto.prototype, SHARE_KEY);
653
- setHandler(proto.prototype, SHARE_KEY, {
654
- init: (instance) => {
655
- return getKey("storage")?.({
656
- instance,
657
- key,
658
- tag,
659
- toJSON,
660
- toString
661
- });
662
- }
663
- });
664
- }
636
+ function Storage({ key: storeKey, json, stringify } = {}) {
637
+ if (!json)
638
+ json = /* @__PURE__ */ __name((v) => JSON.parse(v), "json");
639
+ if (!stringify)
640
+ stringify = /* @__PURE__ */ __name((v) => JSON.stringify(v), "stringify");
641
+ return (proto, key = SHARE_KEY) => {
642
+ if (typeof proto === "function")
643
+ proto = proto.prototype;
644
+ const tag = storeKey || getTag(proto);
645
+ init(proto);
646
+ setStateKey(proto, key);
647
+ setHandler(proto, key, {
648
+ init: (instance) => {
649
+ return getInject("storage")?.({
650
+ instance,
651
+ key,
652
+ tag,
653
+ toJSON: json,
654
+ toString: stringify
655
+ });
656
+ }
657
+ });
665
658
  };
666
659
  }
667
660
  __name(Storage, "Storage");
@@ -698,17 +691,17 @@ __name(Storage, "Storage");
698
691
  getBind,
699
692
  getExposeKey,
700
693
  getHandler,
701
- getKey,
694
+ getInject,
702
695
  getOwnExposeKey,
703
696
  getOwnHandler,
704
697
  getOwnIgnoreKey,
705
698
  getOwnState,
706
- getOwnStateVars,
699
+ getOwnStateKey,
700
+ getPhecdaFromTarget,
707
701
  getState,
708
- getStateVars,
702
+ getStateKey,
709
703
  getTag,
710
704
  init,
711
- injectKey,
712
705
  invokeHandler,
713
706
  isAsyncFunc,
714
707
  isPhecda,
@@ -717,8 +710,9 @@ __name(Storage, "Storage");
717
710
  setExposeKey,
718
711
  setHandler,
719
712
  setIgnoreKey,
713
+ setInject,
720
714
  setState,
721
- setStateVar,
715
+ setStateKey,
722
716
  snapShot,
723
717
  transformInstance,
724
718
  transformInstanceAsync,
package/dist/index.mjs CHANGED
@@ -15,9 +15,10 @@ function init(proto) {
15
15
  return;
16
16
  if (!proto.hasOwnProperty(PHECDA_KEY)) {
17
17
  proto[PHECDA_KEY] = {
18
- __EXPOSE_VAR__: /* @__PURE__ */ new Set(),
19
- __IGNORE_VAR__: /* @__PURE__ */ new Set(),
20
- __STATE_VAR__: /* @__PURE__ */ new Set(),
18
+ __EXPOSE_KEY: /* @__PURE__ */ new Set(),
19
+ __IGNORE_KEY: /* @__PURE__ */ new Set(),
20
+ __CLEAR_KEY: /* @__PURE__ */ new Set(),
21
+ __STATE_KEY: /* @__PURE__ */ new Set(),
21
22
  __STATE_HANDLER__: /* @__PURE__ */ new Map(),
22
23
  __STATE_NAMESPACE__: /* @__PURE__ */ new Map()
23
24
  };
@@ -32,20 +33,20 @@ function getPhecdaFromTarget(target) {
32
33
  return Object.getPrototypeOf(target);
33
34
  }
34
35
  __name(getPhecdaFromTarget, "getPhecdaFromTarget");
35
- function setStateVar(proto, key) {
36
+ function setStateKey(proto, key) {
36
37
  init(proto);
37
- proto[PHECDA_KEY].__STATE_VAR__.add(key);
38
+ proto[PHECDA_KEY].__STATE_KEY.add(key);
38
39
  setExposeKey(proto, key);
39
40
  }
40
- __name(setStateVar, "setStateVar");
41
+ __name(setStateKey, "setStateKey");
41
42
  function setExposeKey(proto, key) {
42
43
  init(proto);
43
- proto[PHECDA_KEY].__EXPOSE_VAR__.add(key);
44
+ proto[PHECDA_KEY].__EXPOSE_KEY.add(key);
44
45
  }
45
46
  __name(setExposeKey, "setExposeKey");
46
47
  function setIgnoreKey(proto, key) {
47
48
  init(proto);
48
- proto[PHECDA_KEY].__IGNORE_VAR__.add(key);
49
+ proto[PHECDA_KEY].__IGNORE_KEY.add(key);
49
50
  }
50
51
  __name(setIgnoreKey, "setIgnoreKey");
51
52
  function setHandler(proto, key, handler) {
@@ -64,39 +65,42 @@ function setState(proto, key, state) {
64
65
  namespace.set(key, state);
65
66
  }
66
67
  __name(setState, "setState");
67
- function getOwnStateVars(target) {
68
+ function getOwnStateKey(target) {
68
69
  const proto = getPhecdaFromTarget(target);
69
70
  return [
70
- ...proto[PHECDA_KEY].__STATE_VAR__
71
+ ...proto[PHECDA_KEY].__STATE_KEY
71
72
  ];
72
73
  }
73
- __name(getOwnStateVars, "getOwnStateVars");
74
- function getStateVars(target) {
74
+ __name(getOwnStateKey, "getOwnStateKey");
75
+ function getStateKey(target) {
75
76
  let proto = getPhecdaFromTarget(target);
76
77
  const set2 = /* @__PURE__ */ new Set();
77
78
  while (proto?.[PHECDA_KEY]) {
78
- proto[PHECDA_KEY].__STATE_VAR__.forEach((item) => set2.add(item));
79
+ if (proto.hasOwnProperty(PHECDA_KEY))
80
+ proto[PHECDA_KEY].__STATE_KEY.forEach((item) => set2.add(item));
79
81
  proto = Object.getPrototypeOf(proto);
80
82
  }
81
83
  return [
82
84
  ...set2
83
85
  ];
84
86
  }
85
- __name(getStateVars, "getStateVars");
87
+ __name(getStateKey, "getStateKey");
86
88
  function getOwnExposeKey(target) {
87
89
  const proto = getPhecdaFromTarget(target);
88
90
  return [
89
- ...proto[PHECDA_KEY].__EXPOSE_VAR__
90
- ].filter((item) => !proto[PHECDA_KEY].__IGNORE_VAR__.has(item));
91
+ ...proto[PHECDA_KEY].__EXPOSE_KEY
92
+ ].filter((item) => !proto[PHECDA_KEY].__IGNORE_KEY.has(item));
91
93
  }
92
94
  __name(getOwnExposeKey, "getOwnExposeKey");
93
95
  function getExposeKey(target) {
94
96
  let proto = getPhecdaFromTarget(target);
95
97
  const set2 = /* @__PURE__ */ new Set();
98
+ const origin = proto;
96
99
  while (proto?.[PHECDA_KEY]) {
97
- [
98
- ...proto[PHECDA_KEY].__EXPOSE_VAR__
99
- ].forEach((item) => !proto[PHECDA_KEY].__IGNORE_VAR__.has(item) && set2.add(item));
100
+ if (proto.hasOwnProperty(PHECDA_KEY))
101
+ [
102
+ ...proto[PHECDA_KEY].__EXPOSE_KEY
103
+ ].forEach((item) => !origin[PHECDA_KEY].__IGNORE_KEY.has(item) && set2.add(item));
100
104
  proto = Object.getPrototypeOf(proto);
101
105
  }
102
106
  return [
@@ -107,7 +111,7 @@ __name(getExposeKey, "getExposeKey");
107
111
  function getOwnIgnoreKey(target) {
108
112
  const proto = getPhecdaFromTarget(target);
109
113
  return [
110
- ...proto[PHECDA_KEY]?.__IGNORE_VAR__
114
+ ...proto[PHECDA_KEY]?.__IGNORE_KEY
111
115
  ];
112
116
  }
113
117
  __name(getOwnIgnoreKey, "getOwnIgnoreKey");
@@ -120,7 +124,11 @@ function getHandler(target, key) {
120
124
  let proto = getPhecdaFromTarget(target);
121
125
  const set2 = /* @__PURE__ */ new Set();
122
126
  while (proto?.[PHECDA_KEY]) {
123
- proto[PHECDA_KEY].__STATE_HANDLER__.get(key)?.forEach((item) => set2.add(item));
127
+ if (proto.hasOwnProperty(PHECDA_KEY)) {
128
+ proto[PHECDA_KEY].__STATE_HANDLER__.get(key)?.forEach((item) => set2.add(item));
129
+ if (proto[PHECDA_KEY].__CLEAR_KEY.has(key))
130
+ break;
131
+ }
124
132
  proto = Object.getPrototypeOf(proto);
125
133
  }
126
134
  return [
@@ -132,12 +140,16 @@ function getState(target, key) {
132
140
  let proto = getPhecdaFromTarget(target);
133
141
  let ret = {};
134
142
  while (proto?.[PHECDA_KEY]) {
135
- const state = proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key);
136
- if (state)
137
- ret = {
138
- ...state,
139
- ...ret
140
- };
143
+ if (proto.hasOwnProperty(PHECDA_KEY)) {
144
+ const state = proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key);
145
+ if (state)
146
+ ret = {
147
+ ...state,
148
+ ...ret
149
+ };
150
+ if (proto[PHECDA_KEY].__CLEAR_KEY.has(key))
151
+ break;
152
+ }
141
153
  proto = Object.getPrototypeOf(proto);
142
154
  }
143
155
  return ret;
@@ -158,17 +170,17 @@ function invokeHandler(event, module) {
158
170
  __name(invokeHandler, "invokeHandler");
159
171
  function set(proto, key, value) {
160
172
  init(proto);
161
- proto[PHECDA_KEY][`__${key.toUpperCase()}__`] = value;
173
+ proto[`__${key.toUpperCase()}__`] = value;
162
174
  }
163
175
  __name(set, "set");
164
176
  function get(proto, key) {
165
- return proto[PHECDA_KEY]?.[`__${key.toUpperCase()}__`];
177
+ return proto[`__${key.toUpperCase()}__`];
166
178
  }
167
179
  __name(get, "get");
168
180
 
169
181
  // src/decorators/core.ts
170
182
  function Init(proto, key) {
171
- setStateVar(proto, key);
183
+ setStateKey(proto, key);
172
184
  setHandler(proto, key, {
173
185
  async init(instance) {
174
186
  return instance[key]();
@@ -177,7 +189,7 @@ function Init(proto, key) {
177
189
  }
178
190
  __name(Init, "Init");
179
191
  function Unmount(proto, key) {
180
- setStateVar(proto, key);
192
+ setStateKey(proto, key);
181
193
  setHandler(proto, key, {
182
194
  async unmount(instance) {
183
195
  return instance[key]();
@@ -187,24 +199,20 @@ function Unmount(proto, key) {
187
199
  __name(Unmount, "Unmount");
188
200
  function Bind(value) {
189
201
  return (proto, k) => {
190
- setStateVar(proto, k);
202
+ setStateKey(proto, k);
191
203
  setState(proto, k, {
192
204
  value
193
205
  });
194
206
  };
195
207
  }
196
208
  __name(Bind, "Bind");
197
- function Ignore(proto, key) {
209
+ function Ignore(proto, key = SHARE_KEY) {
198
210
  setIgnoreKey(proto, key);
199
211
  }
200
212
  __name(Ignore, "Ignore");
201
- function Clear(proto, key) {
213
+ function Clear(proto, key = SHARE_KEY) {
202
214
  init(proto);
203
- proto[PHECDA_KEY].__EXPOSE_VAR__.delete(key);
204
- proto[PHECDA_KEY].__IGNORE_VAR__.delete(key);
205
- proto[PHECDA_KEY].__STATE_VAR__.delete(key);
206
- proto[PHECDA_KEY].__STATE_HANDLER__.delete(key);
207
- proto[PHECDA_KEY].__STATE_NAMESPACE__.delete(key);
215
+ proto[PHECDA_KEY].__CLEAR_KEY.add(key);
208
216
  }
209
217
  __name(Clear, "Clear");
210
218
  function Expose(proto, key) {
@@ -220,12 +228,12 @@ __name(Empty, "Empty");
220
228
  function getTag(moduleOrInstance) {
221
229
  if (typeof moduleOrInstance === "object")
222
230
  moduleOrInstance = moduleOrInstance.constructor;
223
- return moduleOrInstance.prototype[PHECDA_KEY]?.__TAG__ || moduleOrInstance.name;
231
+ return get(moduleOrInstance.prototype, "tag") || moduleOrInstance.name;
224
232
  }
225
233
  __name(getTag, "getTag");
226
234
  function getBind(model) {
227
235
  const instance = new model();
228
- const keys = getStateVars(instance);
236
+ const keys = getStateKey(instance);
229
237
  const ret = {};
230
238
  for (const item of keys) {
231
239
  const state = getState(instance, item);
@@ -369,15 +377,15 @@ function Inject(key) {
369
377
  }
370
378
  __name(Inject, "Inject");
371
379
  var activeInstance = {};
372
- function injectKey(key, value) {
380
+ function setInject(key, value) {
373
381
  activeInstance[key] = value;
374
382
  return activeInstance;
375
383
  }
376
- __name(injectKey, "injectKey");
377
- function getKey(key) {
384
+ __name(setInject, "setInject");
385
+ function getInject(key) {
378
386
  return activeInstance[key];
379
387
  }
380
- __name(getKey, "getKey");
388
+ __name(getInject, "getInject");
381
389
 
382
390
  // src/decorators/function.ts
383
391
  function Isolate(model) {
@@ -400,7 +408,7 @@ __name(Unique, "Unique");
400
408
  function Assign(cb) {
401
409
  return (model) => {
402
410
  init(model.prototype);
403
- setStateVar(model.prototype, SHARE_KEY);
411
+ setStateKey(model.prototype, SHARE_KEY);
404
412
  setHandler(model.prototype, SHARE_KEY, {
405
413
  init: async (instance) => {
406
414
  const value = await cb(instance);
@@ -415,7 +423,7 @@ function Assign(cb) {
415
423
  __name(Assign, "Assign");
416
424
  function Global(model) {
417
425
  init(model.prototype);
418
- setStateVar(model.prototype, SHARE_KEY);
426
+ setStateKey(model.prototype, SHARE_KEY);
419
427
  setHandler(model.prototype, SHARE_KEY, {
420
428
  init: async (instance) => {
421
429
  const tag = instance[PHECDA_KEY].__TAG__;
@@ -430,7 +438,7 @@ function Global(model) {
430
438
  __name(Global, "Global");
431
439
  function To(...callbacks) {
432
440
  return (proto, key) => {
433
- setStateVar(proto, key);
441
+ setStateKey(proto, key);
434
442
  setHandler(proto, key, {
435
443
  async pipe(instance, addError) {
436
444
  for (const cb of callbacks) {
@@ -450,7 +458,7 @@ function To(...callbacks) {
450
458
  __name(To, "To");
451
459
  function Rule(cb, info) {
452
460
  return (proto, key) => {
453
- setStateVar(proto, key);
461
+ setStateKey(proto, key);
454
462
  setHandler(proto, key, {
455
463
  async pipe(instance, addError) {
456
464
  let ret;
@@ -471,7 +479,7 @@ function Rule(cb, info) {
471
479
  __name(Rule, "Rule");
472
480
  function Err(cb, isCatch = false) {
473
481
  return (proto, key) => {
474
- setStateVar(proto, key);
482
+ setStateKey(proto, key);
475
483
  setHandler(proto, key, {
476
484
  init: (instance) => {
477
485
  if (typeof instance[key] === "function") {
@@ -506,10 +514,10 @@ __name(Err, "Err");
506
514
  function Watcher(eventName, options) {
507
515
  let cb;
508
516
  return (proto, key) => {
509
- setStateVar(proto, key);
517
+ setStateKey(proto, key);
510
518
  setHandler(proto, key, {
511
519
  init(instance) {
512
- return cb = getKey("watcher")?.({
520
+ return cb = getInject("watcher")?.({
513
521
  eventName,
514
522
  instance,
515
523
  key,
@@ -525,7 +533,7 @@ function Watcher(eventName, options) {
525
533
  __name(Watcher, "Watcher");
526
534
  function Effect(cb) {
527
535
  return (proto, key) => {
528
- setStateVar(proto, key);
536
+ setStateKey(proto, key);
529
537
  setHandler(proto, key, {
530
538
  init(instance) {
531
539
  instance[`$_${key}`] = instance[key];
@@ -544,44 +552,28 @@ function Effect(cb) {
544
552
  };
545
553
  }
546
554
  __name(Effect, "Effect");
547
- function Storage({ key: storeKey, toJSON, toString } = {}) {
548
- if (!toJSON)
549
- toJSON = /* @__PURE__ */ __name((v) => JSON.parse(v), "toJSON");
550
- if (!toString)
551
- toString = /* @__PURE__ */ __name((v) => JSON.stringify(v), "toString");
552
- return (proto, key) => {
553
- let tag;
554
- if (key) {
555
- init(proto);
556
- tag = storeKey || `${getTag(proto)}_${key}`;
557
- setStateVar(proto, key);
558
- setHandler(proto, key, {
559
- init: (instance) => {
560
- return getKey("storage")?.({
561
- instance,
562
- key,
563
- tag,
564
- toJSON,
565
- toString
566
- });
567
- }
568
- });
569
- } else {
570
- init(proto.prototype);
571
- tag = storeKey || getTag(proto);
572
- setStateVar(proto.prototype, SHARE_KEY);
573
- setHandler(proto.prototype, SHARE_KEY, {
574
- init: (instance) => {
575
- return getKey("storage")?.({
576
- instance,
577
- key,
578
- tag,
579
- toJSON,
580
- toString
581
- });
582
- }
583
- });
584
- }
555
+ function Storage({ key: storeKey, json, stringify } = {}) {
556
+ if (!json)
557
+ json = /* @__PURE__ */ __name((v) => JSON.parse(v), "json");
558
+ if (!stringify)
559
+ stringify = /* @__PURE__ */ __name((v) => JSON.stringify(v), "stringify");
560
+ return (proto, key = SHARE_KEY) => {
561
+ if (typeof proto === "function")
562
+ proto = proto.prototype;
563
+ const tag = storeKey || getTag(proto);
564
+ init(proto);
565
+ setStateKey(proto, key);
566
+ setHandler(proto, key, {
567
+ init: (instance) => {
568
+ return getInject("storage")?.({
569
+ instance,
570
+ key,
571
+ tag,
572
+ toJSON: json,
573
+ toString: stringify
574
+ });
575
+ }
576
+ });
585
577
  };
586
578
  }
587
579
  __name(Storage, "Storage");
@@ -617,17 +609,17 @@ export {
617
609
  getBind,
618
610
  getExposeKey,
619
611
  getHandler,
620
- getKey,
612
+ getInject,
621
613
  getOwnExposeKey,
622
614
  getOwnHandler,
623
615
  getOwnIgnoreKey,
624
616
  getOwnState,
625
- getOwnStateVars,
617
+ getOwnStateKey,
618
+ getPhecdaFromTarget,
626
619
  getState,
627
- getStateVars,
620
+ getStateKey,
628
621
  getTag,
629
622
  init,
630
- injectKey,
631
623
  invokeHandler,
632
624
  isAsyncFunc,
633
625
  isPhecda,
@@ -636,8 +628,9 @@ export {
636
628
  setExposeKey,
637
629
  setHandler,
638
630
  setIgnoreKey,
631
+ setInject,
639
632
  setState,
640
- setStateVar,
633
+ setStateKey,
641
634
  snapShot,
642
635
  transformInstance,
643
636
  transformInstanceAsync,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "3.0.0-beta.14",
3
+ "version": "3.0.0-beta.16",
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",