phecda-core 3.0.2 → 3.1.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.mjs CHANGED
@@ -1,56 +1,65 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result) __defProp(target, key, result);
9
+ return result;
10
+ };
3
11
 
4
12
  // src/core.ts
5
13
  var SHARE_KEY = Symbol("phecda");
6
14
  var PHECDA_KEY = Symbol("phecda");
7
15
  function isPhecda(model) {
8
- if (typeof model === "function") return !!model.prototype[PHECDA_KEY];
16
+ if (typeof model === "function")
17
+ return !!model.prototype[PHECDA_KEY];
9
18
  return false;
10
19
  }
11
- __name(isPhecda, "isPhecda");
12
20
  function init(proto) {
13
- if (!proto) return;
21
+ if (!proto)
22
+ return;
14
23
  if (!proto.hasOwnProperty(PHECDA_KEY)) {
15
24
  proto[PHECDA_KEY] = {
16
25
  /**
17
- * 暴露的变量,
18
- * 只要属性上存在至少一个装饰器,该属性就会被捕捉到
19
- */
26
+ * 暴露的变量,
27
+ * 只要属性上存在至少一个装饰器,该属性就会被捕捉到
28
+ */
20
29
  __EXPOSE_KEY: /* @__PURE__ */ new Set(),
21
30
  /**
22
- * @Ignore 绑定的属性,
23
- * 某属性即使被捕捉,可被强行忽略,优先级最高
24
- */
31
+ * @Ignore 绑定的属性,
32
+ * 某属性即使被捕捉,可被强行忽略,优先级最高
33
+ */
25
34
  __IGNORE_KEY: /* @__PURE__ */ new Set(),
26
35
  /**
27
- * @Clear 绑定的属性,
28
- * 消除父类在该key上的state/handler, 但export key 和 state
29
- */
36
+ * @Clear 绑定的属性,
37
+ * 消除父类在该key上的state/handler, 但export key 和 state
38
+ */
30
39
  __CLEAR_KEY: /* @__PURE__ */ new Set(),
31
40
  /**
32
- * 存在状态的变量
33
- * @deprecated
34
- */
41
+ * 存在状态的变量
42
+ * @deprecated
43
+ */
35
44
  __STATE_KEY: /* @__PURE__ */ new Set(),
36
45
  /**
37
- * 状态变量的处理器
38
- */
46
+ * 状态变量的处理器
47
+ */
39
48
  __STATE_HANDLER__: /* @__PURE__ */ new Map(),
40
49
  /**
41
- * 状态变量的共有状态
42
- */
50
+ * 状态变量的共有状态
51
+ */
43
52
  __STATE_NAMESPACE__: /* @__PURE__ */ new Map()
44
53
  };
45
54
  }
46
55
  }
47
- __name(init, "init");
48
56
  function getPhecdaFromTarget(target) {
49
- if (typeof target === "function") return target.prototype;
50
- if (target.hasOwnProperty(PHECDA_KEY)) return target;
57
+ if (typeof target === "function")
58
+ return target.prototype;
59
+ if (target.hasOwnProperty(PHECDA_KEY))
60
+ return target;
51
61
  return Object.getPrototypeOf(target);
52
62
  }
53
- __name(getPhecdaFromTarget, "getPhecdaFromTarget");
54
63
  function setStateKey(proto, key) {
55
64
  if (!key) {
56
65
  key = SHARE_KEY;
@@ -60,7 +69,6 @@ function setStateKey(proto, key) {
60
69
  proto[PHECDA_KEY].__STATE_KEY.add(key);
61
70
  setExposeKey(proto, key);
62
71
  }
63
- __name(setStateKey, "setStateKey");
64
72
  function setExposeKey(proto, key) {
65
73
  if (!key) {
66
74
  key = SHARE_KEY;
@@ -69,7 +77,6 @@ function setExposeKey(proto, key) {
69
77
  init(proto);
70
78
  proto[PHECDA_KEY].__EXPOSE_KEY.add(key);
71
79
  }
72
- __name(setExposeKey, "setExposeKey");
73
80
  function setIgnoreKey(proto, key) {
74
81
  if (!key) {
75
82
  key = SHARE_KEY;
@@ -78,19 +85,17 @@ function setIgnoreKey(proto, key) {
78
85
  init(proto);
79
86
  proto[PHECDA_KEY].__IGNORE_KEY.add(key);
80
87
  }
81
- __name(setIgnoreKey, "setIgnoreKey");
82
88
  function setHandler(proto, key, handler) {
83
89
  if (!key) {
84
90
  key = SHARE_KEY;
85
91
  proto = proto.prototype;
86
92
  }
87
93
  init(proto);
88
- if (!proto[PHECDA_KEY].__STATE_HANDLER__.has(key)) proto[PHECDA_KEY].__STATE_HANDLER__.set(key, [
89
- handler
90
- ]);
91
- else proto[PHECDA_KEY].__STATE_HANDLER__.get(key).push(handler);
94
+ if (!proto[PHECDA_KEY].__STATE_HANDLER__.has(key))
95
+ proto[PHECDA_KEY].__STATE_HANDLER__.set(key, [handler]);
96
+ else
97
+ proto[PHECDA_KEY].__STATE_HANDLER__.get(key).push(handler);
92
98
  }
93
- __name(setHandler, "setHandler");
94
99
  function setState(proto, key, state) {
95
100
  if (!key) {
96
101
  key = SHARE_KEY;
@@ -100,114 +105,89 @@ function setState(proto, key, state) {
100
105
  const namespace = proto[PHECDA_KEY].__STATE_NAMESPACE__;
101
106
  namespace.set(key, state);
102
107
  }
103
- __name(setState, "setState");
104
108
  function getOwnStateKey(target) {
105
109
  const proto = getPhecdaFromTarget(target);
106
- return [
107
- ...proto[PHECDA_KEY].__STATE_KEY
108
- ];
110
+ return [...proto[PHECDA_KEY].__STATE_KEY];
109
111
  }
110
- __name(getOwnStateKey, "getOwnStateKey");
111
112
  function getStateKey(target) {
112
113
  let proto = getPhecdaFromTarget(target);
113
114
  const set2 = /* @__PURE__ */ new Set();
114
115
  while (proto?.[PHECDA_KEY]) {
115
- if (proto.hasOwnProperty(PHECDA_KEY)) proto[PHECDA_KEY].__STATE_KEY.forEach((item) => set2.add(item));
116
+ if (proto.hasOwnProperty(PHECDA_KEY))
117
+ proto[PHECDA_KEY].__STATE_KEY.forEach((item) => set2.add(item));
116
118
  proto = Object.getPrototypeOf(proto);
117
119
  }
118
- return [
119
- ...set2
120
- ];
120
+ return [...set2];
121
121
  }
122
- __name(getStateKey, "getStateKey");
123
122
  function getOwnExposeKey(target) {
124
123
  const proto = getPhecdaFromTarget(target);
125
- return [
126
- ...proto[PHECDA_KEY].__EXPOSE_KEY
127
- ].filter((item) => !proto[PHECDA_KEY].__IGNORE_KEY.has(item));
124
+ return [...proto[PHECDA_KEY].__EXPOSE_KEY].filter((item) => !proto[PHECDA_KEY].__IGNORE_KEY.has(item));
128
125
  }
129
- __name(getOwnExposeKey, "getOwnExposeKey");
130
126
  function getExposeKey(target) {
131
127
  let proto = getPhecdaFromTarget(target);
132
128
  const set2 = /* @__PURE__ */ new Set();
133
129
  const origin = proto;
134
130
  while (proto?.[PHECDA_KEY]) {
135
- if (proto.hasOwnProperty(PHECDA_KEY)) [
136
- ...proto[PHECDA_KEY].__EXPOSE_KEY
137
- ].forEach((item) => !origin[PHECDA_KEY].__IGNORE_KEY.has(item) && set2.add(item));
131
+ if (proto.hasOwnProperty(PHECDA_KEY))
132
+ [...proto[PHECDA_KEY].__EXPOSE_KEY].forEach((item) => !origin[PHECDA_KEY].__IGNORE_KEY.has(item) && set2.add(item));
138
133
  proto = Object.getPrototypeOf(proto);
139
134
  }
140
- return [
141
- ...set2
142
- ];
135
+ return [...set2];
143
136
  }
144
- __name(getExposeKey, "getExposeKey");
145
137
  function getOwnIgnoreKey(target) {
146
138
  const proto = getPhecdaFromTarget(target);
147
- return [
148
- ...proto[PHECDA_KEY]?.__IGNORE_KEY
149
- ];
139
+ return [...proto[PHECDA_KEY]?.__IGNORE_KEY];
150
140
  }
151
- __name(getOwnIgnoreKey, "getOwnIgnoreKey");
152
141
  function getOwnHandler(target, key) {
153
142
  const proto = getPhecdaFromTarget(target);
154
143
  return proto[PHECDA_KEY]?.__STATE_HANDLER__.get(key) || [];
155
144
  }
156
- __name(getOwnHandler, "getOwnHandler");
157
145
  function getHandler(target, key) {
158
146
  let proto = getPhecdaFromTarget(target);
159
147
  const set2 = /* @__PURE__ */ new Set();
160
148
  while (proto?.[PHECDA_KEY]) {
161
149
  if (proto.hasOwnProperty(PHECDA_KEY)) {
162
150
  proto[PHECDA_KEY].__STATE_HANDLER__.get(key)?.forEach((item) => set2.add(item));
163
- if (proto[PHECDA_KEY].__CLEAR_KEY.has(key)) break;
151
+ if (proto[PHECDA_KEY].__CLEAR_KEY.has(key))
152
+ break;
164
153
  }
165
154
  proto = Object.getPrototypeOf(proto);
166
155
  }
167
- return [
168
- ...set2
169
- ];
156
+ return [...set2];
170
157
  }
171
- __name(getHandler, "getHandler");
172
158
  function getState(target, key = SHARE_KEY) {
173
159
  let proto = getPhecdaFromTarget(target);
174
160
  let ret = {};
175
161
  while (proto?.[PHECDA_KEY]) {
176
162
  if (proto.hasOwnProperty(PHECDA_KEY)) {
177
163
  const state = proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key);
178
- if (state) ret = {
179
- ...state,
180
- ...ret
181
- };
182
- if (proto[PHECDA_KEY].__CLEAR_KEY.has(key)) break;
164
+ if (state)
165
+ ret = { ...state, ...ret };
166
+ if (proto[PHECDA_KEY].__CLEAR_KEY.has(key))
167
+ break;
183
168
  }
184
169
  proto = Object.getPrototypeOf(proto);
185
170
  }
186
171
  return ret;
187
172
  }
188
- __name(getState, "getState");
189
173
  function getOwnState(target, key = SHARE_KEY) {
190
174
  const proto = getPhecdaFromTarget(target);
191
175
  return proto[PHECDA_KEY].__STATE_NAMESPACE__.get(key) || {};
192
176
  }
193
- __name(getOwnState, "getOwnState");
194
177
  function invokeHandler(event, module) {
195
178
  const stateVars = getExposeKey(module);
196
179
  const initHandlers = stateVars.map((item) => {
197
180
  return getHandler(module, item).filter((h) => !!h[event]).map((h) => h[event](module));
198
181
  }).flat();
199
- return Promise.all(initHandlers);
182
+ return module.__PROMISE_SYMBOL__ = Promise.all(initHandlers);
200
183
  }
201
- __name(invokeHandler, "invokeHandler");
202
184
  function set(proto, key, value) {
203
185
  init(proto);
204
186
  proto[`__${key.toUpperCase()}__`] = value;
205
187
  }
206
- __name(set, "set");
207
188
  function get(proto, key) {
208
189
  return proto[`__${key.toUpperCase()}__`];
209
190
  }
210
- __name(get, "get");
211
191
 
212
192
  // src/decorators/core.ts
213
193
  function Init(proto, key) {
@@ -218,7 +198,6 @@ function Init(proto, key) {
218
198
  }
219
199
  });
220
200
  }
221
- __name(Init, "Init");
222
201
  function Unmount(proto, key) {
223
202
  setStateKey(proto, key);
224
203
  setHandler(proto, key, {
@@ -227,7 +206,6 @@ function Unmount(proto, key) {
227
206
  }
228
207
  });
229
208
  }
230
- __name(Unmount, "Unmount");
231
209
  function Bind(value) {
232
210
  return (proto, k) => {
233
211
  setStateKey(proto, k);
@@ -236,57 +214,57 @@ function Bind(value) {
236
214
  });
237
215
  };
238
216
  }
239
- __name(Bind, "Bind");
240
217
  function Ignore(proto, key) {
241
218
  if (!key) {
242
219
  proto = proto.prototype;
243
220
  key = SHARE_KEY;
244
221
  }
222
+ ;
245
223
  setIgnoreKey(proto, key);
246
224
  }
247
- __name(Ignore, "Ignore");
248
225
  function Clear(proto, key) {
249
226
  if (!key) {
250
227
  proto = proto.prototype;
251
228
  key = SHARE_KEY;
252
229
  }
230
+ ;
253
231
  init(proto);
254
232
  proto[PHECDA_KEY].__CLEAR_KEY.add(key);
255
233
  }
256
- __name(Clear, "Clear");
257
234
  function Expose(proto, key) {
258
235
  setExposeKey(proto, key);
259
236
  }
260
- __name(Expose, "Expose");
261
237
  function Empty(model) {
262
238
  init(model.prototype);
263
239
  }
264
- __name(Empty, "Empty");
240
+ function Injectable() {
241
+ return (target) => Empty(target);
242
+ }
265
243
 
266
244
  // src/helper.ts
267
245
  function getTag(moduleOrInstance) {
268
- if (typeof moduleOrInstance === "object") moduleOrInstance = moduleOrInstance.constructor;
246
+ if (typeof moduleOrInstance === "object")
247
+ moduleOrInstance = moduleOrInstance.constructor;
269
248
  return get(moduleOrInstance.prototype, "tag") || moduleOrInstance.name;
270
249
  }
271
- __name(getTag, "getTag");
272
250
  function getBind(model) {
273
251
  const instance = new model();
274
252
  const keys = getStateKey(instance);
275
253
  const ret = {};
276
254
  for (const item of keys) {
277
255
  const state = getState(instance, item);
278
- if (state.value) ret[item] = state.value;
256
+ if (state.value)
257
+ ret[item] = state.value;
279
258
  }
280
259
  return ret;
281
260
  }
282
- __name(getBind, "getBind");
283
261
  function plainToClass(model, input) {
284
262
  const instance = new model();
285
263
  const keys = getExposeKey(instance);
286
- for (const item of keys) instance[item] = input[item];
264
+ for (const item of keys)
265
+ instance[item] = input[item];
287
266
  return instance;
288
267
  }
289
- __name(plainToClass, "plainToClass");
290
268
  function transformInstance(instance, force = false) {
291
269
  const err = [];
292
270
  const keys = getExposeKey(instance);
@@ -296,15 +274,16 @@ function transformInstance(instance, force = false) {
296
274
  if (handlers) {
297
275
  for (const handler of handlers) {
298
276
  const pipe = handler.pipe;
299
- if (!pipe) continue;
277
+ if (!pipe)
278
+ continue;
300
279
  pipe(instance, addError);
301
- if (err.length && !force) return err;
280
+ if (err.length && !force)
281
+ return err;
302
282
  }
303
283
  }
304
284
  }
305
285
  return err;
306
286
  }
307
- __name(transformInstance, "transformInstance");
308
287
  async function transformInstanceAsync(instance, force = false) {
309
288
  const err = [];
310
289
  const keys = getExposeKey(instance);
@@ -314,15 +293,16 @@ async function transformInstanceAsync(instance, force = false) {
314
293
  if (handlers) {
315
294
  for (const handler of handlers) {
316
295
  const pipe = handler.pipe;
317
- if (!pipe) continue;
296
+ if (!pipe)
297
+ continue;
318
298
  await pipe(instance, addError);
319
- if (err.length && !force) return err;
299
+ if (err.length && !force)
300
+ return err;
320
301
  }
321
302
  }
322
303
  }
323
304
  return err;
324
305
  }
325
- __name(transformInstanceAsync, "transformInstanceAsync");
326
306
  function transformProperty(instance, property, force = false) {
327
307
  const err = [];
328
308
  const handlers = getHandler(instance, property);
@@ -330,14 +310,15 @@ function transformProperty(instance, property, force = false) {
330
310
  if (handlers) {
331
311
  for (const handler of handlers) {
332
312
  const pipe = handler.pipe;
333
- if (!pipe) continue;
313
+ if (!pipe)
314
+ continue;
334
315
  pipe(instance, addError);
335
- if (err.length && !force) return err;
316
+ if (err.length && !force)
317
+ return err;
336
318
  }
337
319
  }
338
320
  return err;
339
321
  }
340
- __name(transformProperty, "transformProperty");
341
322
  async function transformPropertyAsync(instance, property, force = false) {
342
323
  const err = [];
343
324
  const handlers = getHandler(instance, property);
@@ -345,125 +326,117 @@ async function transformPropertyAsync(instance, property, force = false) {
345
326
  if (handlers) {
346
327
  for (const handler of handlers) {
347
328
  const pipe = handler.pipe;
348
- if (!pipe) continue;
329
+ if (!pipe)
330
+ continue;
349
331
  await pipe(instance, addError);
350
- if (err.length && !force) return err;
332
+ if (err.length && !force)
333
+ return err;
351
334
  }
352
335
  }
353
336
  return err;
354
337
  }
355
- __name(transformPropertyAsync, "transformPropertyAsync");
356
338
  function classToPlain(instance) {
357
339
  const data = {};
358
340
  const exposeVars = getExposeKey(instance);
359
- for (const item of exposeVars) data[item] = instance[item];
341
+ for (const item of exposeVars)
342
+ data[item] = instance[item];
360
343
  return JSON.parse(JSON.stringify(data));
361
344
  }
362
- __name(classToPlain, "classToPlain");
363
345
  function snapShot(data) {
364
346
  const snap = {};
365
- for (const i in data) snap[i] = data[i];
347
+ for (const i in data)
348
+ snap[i] = data[i];
366
349
  return {
367
350
  data,
368
351
  clear() {
369
- for (const i in snap) delete data[i];
352
+ for (const i in snap)
353
+ delete data[i];
370
354
  },
371
355
  apply() {
372
- for (const i in snap) data[i] = snap[i];
356
+ for (const i in snap)
357
+ data[i] = snap[i];
373
358
  }
374
359
  };
375
360
  }
376
- __name(snapShot, "snapShot");
377
361
  function addDecoToClass(c, key, handler) {
378
362
  handler(key ? c.prototype : c, key);
379
363
  }
380
- __name(addDecoToClass, "addDecoToClass");
381
364
  function Pipeline(...decos) {
382
365
  return (...args) => {
383
- for (const d of decos) d(...args);
366
+ for (const d of decos)
367
+ d(...args);
384
368
  };
385
369
  }
386
- __name(Pipeline, "Pipeline");
387
370
  function isAsyncFunc(fn) {
388
371
  return fn[Symbol.toStringTag] === "AsyncFunction";
389
372
  }
390
- __name(isAsyncFunc, "isAsyncFunc");
391
373
  function setPropertyState(target, k, setter) {
392
374
  setStateKey(target, k);
393
375
  const state = getOwnState(target, k) || {};
394
376
  setter(state);
395
377
  setState(target, k, state);
396
378
  }
397
- __name(setPropertyState, "setPropertyState");
398
379
  function getShareState(target, getter) {
399
380
  const state = getOwnState(target, SHARE_KEY) || {};
400
381
  return getter(state);
401
382
  }
402
- __name(getShareState, "getShareState");
403
383
 
404
384
  // src/di.ts
405
385
  var DataMap = {};
406
386
  function Provide(key, value) {
407
387
  DataMap[key] = value;
408
388
  }
409
- __name(Provide, "Provide");
410
389
  function Inject(key) {
411
390
  return DataMap[key];
412
391
  }
413
- __name(Inject, "Inject");
414
392
  var activeInstance = {};
415
393
  function setInject(key, value) {
416
394
  activeInstance[key] = value;
417
395
  return activeInstance;
418
396
  }
419
- __name(setInject, "setInject");
420
397
  function getInject(key) {
421
398
  return activeInstance[key];
422
399
  }
423
- __name(getInject, "getInject");
424
400
 
425
401
  // src/decorators/function.ts
426
402
  function Isolate(model) {
427
403
  set(model.prototype, "isolate", true);
428
404
  }
429
- __name(Isolate, "Isolate");
430
405
  function Tag(tag) {
431
406
  return (model) => {
432
407
  set(model.prototype, "tag", tag);
433
408
  };
434
409
  }
435
- __name(Tag, "Tag");
436
410
  function Unique(desc) {
437
411
  return (model) => {
438
412
  set(model.prototype, "tag", Symbol(desc || model.name));
439
413
  };
440
414
  }
441
- __name(Unique, "Unique");
442
415
  function Assign(cb) {
443
416
  return (model) => {
444
417
  setStateKey(model);
445
418
  setHandler(model, void 0, {
446
- init: /* @__PURE__ */ __name(async (instance) => {
419
+ init: async (instance) => {
447
420
  const value = await cb(instance);
448
421
  if (value && typeof value === "object" && !Array.isArray(value)) {
449
- for (const i in value) instance[i] = value[i];
422
+ for (const i in value)
423
+ instance[i] = value[i];
450
424
  }
451
- }, "init")
425
+ }
452
426
  });
453
427
  };
454
428
  }
455
- __name(Assign, "Assign");
456
429
  function Global(model) {
457
430
  setStateKey(model);
458
431
  setHandler(model, void 0, {
459
- init: /* @__PURE__ */ __name(async (instance) => {
432
+ init: async (instance) => {
460
433
  const tag = getTag(instance);
461
- if (!globalThis.__PHECDA__) globalThis.__PHECDA__ = {};
434
+ if (!globalThis.__PHECDA__)
435
+ globalThis.__PHECDA__ = {};
462
436
  globalThis.__PHECDA__[tag] = instance.constructor;
463
- }, "init")
437
+ }
464
438
  });
465
439
  }
466
- __name(Global, "Global");
467
440
  function To(...callbacks) {
468
441
  return (proto, key) => {
469
442
  setStateKey(proto, key);
@@ -471,8 +444,10 @@ function To(...callbacks) {
471
444
  async pipe(instance, addError) {
472
445
  for (const cb of callbacks) {
473
446
  try {
474
- if (isAsyncFunc(cb)) instance[key] = await cb(instance[key], instance, key);
475
- else instance[key] = cb(instance[key], instance, key);
447
+ if (isAsyncFunc(cb))
448
+ instance[key] = await cb(instance[key], instance, key);
449
+ else
450
+ instance[key] = cb(instance[key], instance, key);
476
451
  } catch (e) {
477
452
  addError(e.message);
478
453
  }
@@ -481,29 +456,31 @@ function To(...callbacks) {
481
456
  });
482
457
  };
483
458
  }
484
- __name(To, "To");
485
459
  function Rule(cb, info) {
486
460
  return (proto, key) => {
487
461
  setStateKey(proto, key);
488
462
  setHandler(proto, key, {
489
463
  async pipe(instance, addError) {
490
464
  let ret;
491
- if (isAsyncFunc(cb)) ret = await cb(instance[key]);
492
- else ret = cb(instance[key]);
465
+ if (isAsyncFunc(cb))
466
+ ret = await cb(instance[key]);
467
+ else
468
+ ret = cb(instance[key]);
493
469
  if (!ret) {
494
- if (typeof info === "string") addError(info);
495
- else addError(info());
470
+ if (typeof info === "string")
471
+ addError(info);
472
+ else
473
+ addError(info());
496
474
  }
497
475
  }
498
476
  });
499
477
  };
500
478
  }
501
- __name(Rule, "Rule");
502
479
  function Err(cb, isCatch = false) {
503
480
  return (proto, key) => {
504
481
  setStateKey(proto, key);
505
482
  setHandler(proto, key, {
506
- init: /* @__PURE__ */ __name((instance) => {
483
+ init: (instance) => {
507
484
  if (typeof instance[key] === "function") {
508
485
  const oldFn = instance[key].bind(instance);
509
486
  if (isAsyncFunc(oldFn)) {
@@ -512,7 +489,8 @@ function Err(cb, isCatch = false) {
512
489
  await oldFn(...args);
513
490
  } catch (e) {
514
491
  cb(e, instance, key);
515
- if (!isCatch) throw e;
492
+ if (!isCatch)
493
+ throw e;
516
494
  }
517
495
  };
518
496
  } else {
@@ -521,28 +499,23 @@ function Err(cb, isCatch = false) {
521
499
  oldFn(...args);
522
500
  } catch (e) {
523
501
  cb(e, instance, key);
524
- if (!isCatch) throw e;
502
+ if (!isCatch)
503
+ throw e;
525
504
  }
526
505
  };
527
506
  }
528
507
  }
529
- }, "init")
508
+ }
530
509
  });
531
510
  };
532
511
  }
533
- __name(Err, "Err");
534
512
  function Watcher(eventName, options) {
535
513
  let cb;
536
514
  return (proto, key) => {
537
515
  setStateKey(proto, key);
538
516
  setHandler(proto, key, {
539
517
  init(instance) {
540
- return cb = getInject("watcher")?.({
541
- eventName,
542
- instance,
543
- key,
544
- options
545
- });
518
+ return cb = getInject("watcher")?.({ eventName, instance, key, options });
546
519
  },
547
520
  unmount() {
548
521
  return cb?.();
@@ -550,7 +523,6 @@ function Watcher(eventName, options) {
550
523
  });
551
524
  };
552
525
  }
553
- __name(Watcher, "Watcher");
554
526
  function Effect(cb) {
555
527
  return (proto, key) => {
556
528
  setStateKey(proto, key);
@@ -571,28 +543,22 @@ function Effect(cb) {
571
543
  });
572
544
  };
573
545
  }
574
- __name(Effect, "Effect");
575
546
  function Storage({ key: storeKey, json, stringify } = {}) {
576
- if (!json) json = /* @__PURE__ */ __name((v) => JSON.parse(v), "json");
577
- if (!stringify) stringify = /* @__PURE__ */ __name((v) => JSON.stringify(v), "stringify");
547
+ if (!json)
548
+ json = (v) => JSON.parse(v);
549
+ if (!stringify)
550
+ stringify = (v) => JSON.stringify(v);
578
551
  return (proto, key) => {
579
552
  const tag = storeKey || getTag(proto);
580
553
  init(proto);
581
554
  setStateKey(proto, key);
582
555
  setHandler(proto, key, {
583
- init: /* @__PURE__ */ __name((instance) => {
584
- return getInject("storage")?.({
585
- instance,
586
- key,
587
- tag,
588
- toJSON: json,
589
- toString: stringify
590
- });
591
- }, "init")
556
+ init: (instance) => {
557
+ return getInject("storage")?.({ instance, key, tag, toJSON: json, toString: stringify });
558
+ }
592
559
  });
593
560
  };
594
561
  }
595
- __name(Storage, "Storage");
596
562
  function If(value, ...decorators) {
597
563
  if (value) {
598
564
  return (...args) => {
@@ -602,27 +568,11 @@ function If(value, ...decorators) {
602
568
  return () => {
603
569
  };
604
570
  }
605
- __name(If, "If");
606
571
 
607
572
  // src/base.ts
608
- function _ts_decorate(decorators, target, key, desc) {
609
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
610
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
611
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
612
- return c > 3 && r && Object.defineProperty(target, key, r), r;
613
- }
614
- __name(_ts_decorate, "_ts_decorate");
615
- function _ts_metadata(k, v) {
616
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
617
- }
618
- __name(_ts_metadata, "_ts_metadata");
619
573
  var Base = class {
620
- static {
621
- __name(this, "Base");
622
- }
623
- __UNMOUNT_SYMBOL__ = [];
624
- __PROMISE_SYMBOL__;
625
574
  constructor() {
575
+ this.__UNMOUNT_SYMBOL__ = [];
626
576
  }
627
577
  get tag() {
628
578
  return getTag(this);
@@ -643,16 +593,17 @@ var Base = class {
643
593
  onUnmount(cb) {
644
594
  this.__UNMOUNT_SYMBOL__.push(cb);
645
595
  }
596
+ // @ts-expect-error for internal
646
597
  _unmount() {
647
598
  return Promise.all(this.__UNMOUNT_SYMBOL__.map((fn) => fn()));
648
599
  }
649
600
  };
650
- _ts_decorate([
651
- Unmount,
652
- _ts_metadata("design:type", Function),
653
- _ts_metadata("design:paramtypes", []),
654
- _ts_metadata("design:returntype", void 0)
655
- ], Base.prototype, "_unmount", null);
601
+ __decorateClass([
602
+ Unmount
603
+ ], Base.prototype, "_unmount", 1);
604
+ Base = __decorateClass([
605
+ Empty
606
+ ], Base);
656
607
  export {
657
608
  Assign,
658
609
  Base,
@@ -668,6 +619,7 @@ export {
668
619
  Ignore,
669
620
  Init,
670
621
  Inject,
622
+ Injectable,
671
623
  Isolate,
672
624
  PHECDA_KEY,
673
625
  Pipeline,