@cocojs/mvc 0.1.0-beta.14 → 0.1.0-beta.15

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.cjs.js CHANGED
@@ -58,27 +58,6 @@ function isDescendantOf(s, p) {
58
58
  }
59
59
  return false;
60
60
  }
61
- /**
62
- * 生成一个只能执行一次的函数
63
- * @param fn
64
- */
65
- function once(fn) {
66
- let runTimes = 0;
67
- const onceFn = THIS => {
68
- if (onceFn.fn) {
69
- if (runTimes === 0) {
70
- runTimes++;
71
- return onceFn.fn.call(THIS);
72
- }
73
- }
74
- };
75
- onceFn.fn = fn;
76
- return onceFn;
77
- }
78
- // 是否是普通类,因为class会转成function,所以不通过toString判断
79
- function isClass(v) {
80
- return typeof v === 'function' && v.prototype && v.prototype.constructor === v;
81
- }
82
61
  /**
83
62
  * 在coco/mvc中是否是一个合法的类
84
63
  * @param v
@@ -149,153 +128,72 @@ function instantiateMetadata(metadataCls, args) {
149
128
  return metadata;
150
129
  }
151
130
 
152
- function _applyDecs2311(e, t, n, r, o, i) {
153
- var a, c, u, s, f, l, p, d = Symbol.metadata || Symbol.for("Symbol.metadata"), m = Object.defineProperty, h = Object.create, y = [h(null), h(null)], v = t.length;
154
- function g(t, n, r) {
155
- return function (o, i) {
156
- n && (i = o, o = e);
157
- for (var a = 0; a < t.length; a++)
158
- i = t[a].apply(o, r ? [i] : []);
159
- return r ? i : o;
160
- };
161
- }
162
- function b(e, t, n, r) {
163
- if ("function" != typeof e && (r || void 0 !== e))
164
- throw new TypeError(t + " must " + (n || "be") + " a function" + (r ? "" : " or undefined"));
165
- return e;
166
- }
167
- function applyDec(e, t, n, r, o, i, u, s, f, l, p) {
168
- function d(e) {
169
- if (!p(e))
170
- throw new TypeError("Attempted to access private element on non-instance");
171
- }
172
- var h = [].concat(t[0]), v = t[3], w = !u, D = 1 === o, S = 3 === o, j = 4 === o, E = 2 === o;
173
- function I(t, n, r) {
174
- return function (o, i) {
175
- return n && (i = o, o = e), r && r(o), P[t].call(o, i);
176
- };
177
- }
178
- if (!w) {
179
- var P = {}, k = [], F = S ? "get" : j || D ? "set" : "value";
180
- if (f ? (l || D ? P = {
181
- get: _setFunctionName(function () {
182
- return v(this);
183
- }, r, "get"),
184
- set: function (e) {
185
- t[4](this, e);
186
- }
187
- } : P[F] = v, l || _setFunctionName(P[F], r, E ? "" : F)) : l || (P = Object.getOwnPropertyDescriptor(e, r)), !l && !f) {
188
- if ((c = y[+s][r]) && 7 !== (c ^ o))
189
- throw Error("Decorating two elements with the same name (" + P[F].name + ") is not supported yet");
190
- y[+s][r] = o < 3 ? 1 : o;
191
- }
192
- }
193
- for (var N = e, O = h.length - 1; O >= 0; O -= n ? 2 : 1) {
194
- var T = b(h[O], "A decorator", "be", true), z = n ? h[O - 1] : void 0, A = {}, H = {
195
- kind: ["field", "accessor", "method", "getter", "setter", "class"][o],
196
- name: r,
197
- metadata: a,
198
- addInitializer: function (e, t) {
199
- if (e.v)
200
- throw new TypeError("attempted to call addInitializer after decoration was finished");
201
- b(t, "An initializer", "be", true), i.push(t);
202
- }.bind(null, A)
203
- };
204
- if (w)
205
- c = T.call(z, N, H), A.v = 1, b(c, "class decorators", "return") && (N = c);
206
- else if (H.static = s, H.private = f, c = H.access = {
207
- has: f ? p.bind() : function (e) {
208
- return r in e;
209
- }
210
- }, j || (c.get = f ? E ? function (e) {
211
- return d(e), P.value;
212
- } : I("get", 0, d) : function (e) {
213
- return e[r];
214
- }), E || S || (c.set = f ? I("set", 0, d) : function (e, t) {
215
- e[r] = t;
216
- }), N = T.call(z, D ? {
217
- get: P.get,
218
- set: P.set
219
- } : P[F], H), A.v = 1, D) {
220
- if ("object" == typeof N && N)
221
- (c = b(N.get, "accessor.get")) && (P.get = c), (c = b(N.set, "accessor.set")) && (P.set = c), (c = b(N.init, "accessor.init")) && k.unshift(c);
222
- else if (void 0 !== N)
223
- throw new TypeError("accessor decorators must return an object with get, set, or init properties or undefined");
224
- }
225
- else
226
- b(N, (l ? "field" : "method") + " decorators", "return") && (l ? k.unshift(N) : P[F] = N);
227
- }
228
- return o < 2 && u.push(g(k, s, 1), g(i, s, 0)), l || w || (f ? D ? u.splice(-1, 0, I("get", s), I("set", s)) : u.push(E ? P[F] : b.call.bind(P[F])) : m(e, r, P)), N;
229
- }
230
- function w(e) {
231
- return m(e, d, {
232
- configurable: true,
233
- enumerable: true,
234
- value: a
235
- });
236
- }
237
- return void 0 !== i && (a = i[d]), a = h(null == a ? null : a), f = [], l = function (e) {
238
- e && f.push(g(e));
239
- }, p = function (t, r) {
240
- for (var i = 0; i < n.length; i++) {
241
- var a = n[i], c = a[1], l = 7 & c;
242
- if ((8 & c) == t && !l == r) {
243
- var p = a[2], d = !!a[3], m = 16 & c;
244
- applyDec(t ? e : e.prototype, a, m, d ? "#" + p : _toPropertyKey(p), l, l < 2 ? [] : t ? s = s || [] : u = u || [], f, !!t, d, r, t && d ? function (t) {
245
- return _checkInRHS(t) === e;
246
- } : o);
247
- }
248
- }
249
- }, p(8, 0), p(0, 0), p(8, 1), p(0, 1), l(u), l(s), c = f, v || w(e), {
250
- e: c,
251
- get c() {
252
- var n = [];
253
- return v && [w(e = applyDec(e, [t], r, e.name, 5, n)), g(n, 1)];
254
- }
255
- };
131
+ /**
132
+ * 声明被装饰类是某个装饰器表达式的元数据类。
133
+ * 由 AOT 编译器转换为 bindPlaceholderMetadataClass 调用,不应在运行时执行。
134
+ * @public
135
+ */
136
+ function metadataFor(_decoratorExp) {
137
+ return function (_beDecoratedCls, _context) {
138
+ // metadataFor 正常应由 AOT 编译期转换为 bindPlaceholderMetadataClass 调用,
139
+ // 运行到这里说明代码未经 @cocojs/compiler 编译。
140
+ throw new Error('metadataFor 不应在运行时执行,请先使用 @cocojs/compiler 编译后再运行。');
141
+ };
256
142
  }
257
- function _checkInRHS(e) {
258
- if (Object(e) !== e)
259
- throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null"));
260
- return e;
143
+
144
+ const KindClass = 'class';
145
+ const KindField = 'field';
146
+ const KindMethod = 'method';
147
+ const KindGetter = 'getter';
148
+
149
+ // 与 AOT 注册表一样跨运行时模块实例共享,确保绑定方能读取创建方记录的选项
150
+ const decoratorOptionsKey = Symbol.for('coco.decoratorOptions');
151
+ const globalObject$1 = globalThis;
152
+ if (!globalObject$1[decoratorOptionsKey]) {
153
+ globalObject$1[decoratorOptionsKey] = {
154
+ metadata: new Map(),
155
+ placeholder: new Map(),
156
+ placeholderClassMap2RealMetadataClass: new Map()
157
+ };
261
158
  }
262
- function _identity(t) {
263
- return t;
159
+ // 元数据类 <--> 装饰器选项
160
+ const metadataDecoratorOptions = globalObject$1[decoratorOptionsKey].metadata;
161
+ // 占位的元数据类 <--> 装饰器选项
162
+ const placeholderDecoratorOptions = globalObject$1[decoratorOptionsKey].placeholder;
163
+ // 占位的元数据类 -> 真实的元数据类
164
+ const placeholderClassMap2RealMetadataClass = globalObject$1[decoratorOptionsKey].placeholderClassMap2RealMetadataClass;
165
+ // 记录创建装饰器表达式的选项
166
+ function addCreateDecoratorOption(isPlaceholderExp, metadataClass, options = null) {
167
+ if (isPlaceholderExp) {
168
+ // 是占位的元数据表达式,那么先临时记录到placeholderDecoratorOptions中,后续知道占位元数据类和真正的元数据类的映射关系后再保存到metadataDecoratorOptions中
169
+ placeholderDecoratorOptions.set(metadataClass, options);
170
+ } else {
171
+ // 不是占位的元数据表达式,那么直接保存在metadataDecoratorOptions中
172
+ metadataDecoratorOptions.set(metadataClass, options);
173
+ }
264
174
  }
265
- function _setFunctionName(e, t, n) {
266
- "symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : "");
267
- try {
268
- Object.defineProperty(e, "name", {
269
- configurable: !0,
270
- value: n ? n + " " + t : t
271
- });
272
- }
273
- catch (e) { }
274
- return e;
175
+ // 记录占位的元数据类和真实的元数据类之间的映射
176
+ function addPlaceholderClassToRealMetadataClassRelation(placeholderClass, realMetadataClass) {
177
+ placeholderClassMap2RealMetadataClass.set(placeholderClass, realMetadataClass);
275
178
  }
276
- function _toPrimitive(t, r) {
277
- if ("object" != typeof t || !t)
278
- return t;
279
- var e = t[Symbol.toPrimitive];
280
- if (void 0 !== e) {
281
- var i = e.call(t, r);
282
- if ("object" != typeof i)
283
- return i;
284
- throw new TypeError("@@toPrimitive must return a primitive value.");
179
+ function mergePlaceholderClass2RealMetadataClassRelation() {
180
+ for (const [placeholderClass, decoratorOptions] of placeholderDecoratorOptions.entries()) {
181
+ const realMetadataClass = placeholderClassMap2RealMetadataClass.get(placeholderClass);
182
+ if (realMetadataClass) {
183
+ addCreateDecoratorOption(false, realMetadataClass, decoratorOptions);
285
184
  }
286
- return ("string" === r ? String : Number)(t);
185
+ }
287
186
  }
288
- function _toPropertyKey(t) {
289
- var i = _toPrimitive(t, "string");
290
- return "symbol" == typeof i ? i : i + "";
187
+ function getPlaceholderClassMap2RealMetadataClass() {
188
+ return placeholderClassMap2RealMetadataClass;
189
+ }
190
+ function getCreateDecoratorOption(metadataClass) {
191
+ return metadataDecoratorOptions.get(metadataClass);
192
+ }
193
+ function clear$1() {
194
+ metadataDecoratorOptions.clear();
195
+ placeholderDecoratorOptions.clear();
291
196
  }
292
-
293
- const KindClass = 'class';
294
- const KindField = 'field';
295
- const KindMethod = 'method';
296
- const KindGetter = 'getter';
297
- const KindSetter = 'setter';
298
- const KindAccessor = 'accessor';
299
197
 
300
198
  // TODO: 错误码按照类型划分不同的段位
301
199
  var DiagnoseCode;
@@ -343,15 +241,15 @@ const DiagnoseCodeMsg = {
343
241
  [DiagnoseCode.CO10010]: `实例化组件失败,%s 类存在多个子类 %s,@qualifier装饰器指定了一个不存在的子类id: %s`,
344
242
  [DiagnoseCode.CO10011]: `实例化组件失败,%s 类不是ioc组件`,
345
243
  [DiagnoseCode.CO10012]: `%s 类 %s 字段不能使用autowired注入自身,字段置为undefined`,
346
- [DiagnoseCode.CO10013]: `实例化组件失败,%s 类的构造函数的依赖 %s 类也没有完全初始化,可能是循环依赖了?`,
244
+ [DiagnoseCode.CO10013]: `实例化组件失败,存在循环依赖: %s`,
347
245
  [DiagnoseCode.CO10014]: `元数据类 %s 创建了不止一个装饰器,每个元数据类只能创建一个对应的装饰器。`,
348
246
  [DiagnoseCode.CO10015]: `元数据类 %s 本身存在id属性,且不能被修改。`,
349
247
  [DiagnoseCode.CO10016]: `元数据类 %s 没有id属性或者id属性不是字符串,忘记调用assignMetadataId方法?`,
350
248
  [DiagnoseCode.CO10017]: `元数据类 %s 和 %s 的id属性相同,id属性不能重复。`,
351
249
  [DiagnoseCode.CO10018]: `createDecoratorExp的第一个参数 %s 必须是Metadata的子类。`,
352
250
  [DiagnoseCode.CO10019]: `框架暂不支持为 %s 添加装饰器。`,
353
- [DiagnoseCode.CO10020]: `有一个占位装饰器没有使用decorateSelf关联具体的元数据类,如果不使用的话,直接删除这个装饰器。`,
354
- [DiagnoseCode.CO10021]: `%s 类存在一个占位装饰器,但是没有使用decorateSelf装饰器关联真正的元数据类。`,
251
+ [DiagnoseCode.CO10020]: `有一个占位装饰器没有使用metadataFor关联具体的元数据类,如果不使用的话,直接删除这个装饰器。`,
252
+ [DiagnoseCode.CO10021]: `%s 类存在一个占位装饰器,但是没有使用metadataFor装饰器关联真正的元数据类。`,
355
253
  [DiagnoseCode.CO10022]: `元数据类 %s 只能有 KindClass 类型的装饰器,字段 %s 上的装饰器是无效的,请删除。`,
356
254
  [DiagnoseCode.CO10023]: `元数据类 %s 只能有 KindClass 类型的装饰器,方法 %s 上的装饰器是无效的,请删除。`,
357
255
  [DiagnoseCode.CO10024]: `元数据类 %s 存在多个组件装饰器 %s,一个元数据类最多只能有一个组件装饰器。`,
@@ -415,113 +313,12 @@ function reactiveAssignField(reactiveField) {
415
313
  return `${reactiveField}Setter`;
416
314
  }
417
315
 
418
- const decoratorParamMap = new Map();
419
- // 占位的元数据类 <--> 被装饰的类
420
- const placeholderMataClassMap2BeDecoratedClass = new Map();
421
- /**
422
- * 保存装饰器参数
423
- * @param isPlaceholderMetaClass 是否是占位的元数据类
424
- * @param beDecoratedCls 被装饰的类
425
- * @param params
426
- */
427
- function addDecoratorParams(isPlaceholderMetaClass, beDecoratedCls, params) {
428
- if (!isClass(beDecoratedCls)) {
429
- return;
430
- }
431
- if (!decoratorParamMap.has(beDecoratedCls)) {
432
- decoratorParamMap.set(beDecoratedCls, []);
433
- }
434
- const paramsList = decoratorParamMap.get(beDecoratedCls);
435
- paramsList.push(params);
436
- if (isPlaceholderMetaClass) {
437
- const beDecoratedClassList = placeholderMataClassMap2BeDecoratedClass.get(params.metadataClass);
438
- if (beDecoratedClassList) {
439
- beDecoratedClassList.push(beDecoratedCls);
440
- } else {
441
- placeholderMataClassMap2BeDecoratedClass.set(params.metadataClass, [beDecoratedCls]);
442
- }
443
- }
316
+ const createdDecoratorSetKey = Symbol.for('coco.createdDecoratorMetadataSet');
317
+ const globalObject = globalThis;
318
+ if (!globalObject[createdDecoratorSetKey]) {
319
+ globalObject[createdDecoratorSetKey] = new Set();
444
320
  }
445
- // 收集到的装饰器参数,其中部分装饰器对应的类是*占位*元数据类,那么替换成真实的元数据类
446
- function replacePlaceholderMetaClassParams2RealMetadataClassParams({
447
- placeholderClassMap2RealMetadataClass,
448
- notCalledDecorateSelfPlaceholderClassList
449
- }) {
450
- for (const [placeholderMetaClass, beDecoratedClassList] of placeholderMataClassMap2BeDecoratedClass.entries()) {
451
- const realMetadataClass = placeholderClassMap2RealMetadataClass.get(placeholderMetaClass);
452
- for (const beDecoratedClass of beDecoratedClassList) {
453
- if (!realMetadataClass) {
454
- throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10021, beDecoratedClass.name)));
455
- }
456
- const paramsList = decoratorParamMap.get(beDecoratedClass);
457
- for (const p of paramsList) {
458
- if (p.metadataClass === placeholderMetaClass) {
459
- p.metadataClass = realMetadataClass;
460
- }
461
- }
462
- }
463
- }
464
- // 所有没有执行的decorateSelf函数的占位的装饰器表达式,如果也没有被使用,那么打印警告信息
465
- for (const placeholderMetaClass of notCalledDecorateSelfPlaceholderClassList) {
466
- }
467
- }
468
- function getDecoratorParam() {
469
- return decoratorParamMap;
470
- }
471
- function clear$2() {
472
- decoratorParamMap.clear();
473
- }
474
-
475
- // 元数据类 <--> 装饰器选项
476
- const metadataDecoratorOptions = new Map();
477
- // 占位的元数据类 <--> 装饰器选项
478
- const placeholderDecoratorOptions = new Map();
479
- // 占位的元数据类 <--> 真实的元数据类
480
- const placeholderClassMap2RealMetadataClass = new Map();
481
- // 没有调用decorateSelf函数的占位的元数据类
482
- const notCalledDecorateSelfPlaceholderClassList = [];
483
- // 记录创建装饰器表达式的选项
484
- function addCreateDecoratorOption(isPlaceholderExp, metadataClass, options = null) {
485
- if (isPlaceholderExp) {
486
- // 是占位的元数据表达式,那么先临时记录到placeholderDecoratorOptions中,后续知道占位元数据类和真正的元数据类的映射关系后再保存到metadataDecoratorOptions中
487
- placeholderDecoratorOptions.set(metadataClass, options);
488
- } else {
489
- // 不是占位的元数据表达式,那么直接保存在metadataDecoratorOptions中
490
- metadataDecoratorOptions.set(metadataClass, options);
491
- }
492
- }
493
- // 记录占位的元数据类和真实的元数据类之间的映射
494
- function addPlaceholderClassToRealMetadataClassRelation(placeholderClass, realMetadataClass) {
495
- placeholderClassMap2RealMetadataClass.set(placeholderClass, realMetadataClass);
496
- }
497
- // 添加占位的装饰器表达式的参数
498
- function mergePlaceholderClass2RealMetadataClassRelation() {
499
- for (const [placeholderClass, decoratorOptions] of placeholderDecoratorOptions.entries()) {
500
- const realMetadataClass = placeholderClassMap2RealMetadataClass.get(placeholderClass);
501
- if (realMetadataClass) {
502
- addCreateDecoratorOption(false, realMetadataClass, decoratorOptions);
503
- } else {
504
- notCalledDecorateSelfPlaceholderClassList.push(placeholderClass);
505
- }
506
- }
507
- }
508
- function getCreateDecoratorOption(metadataClass) {
509
- return metadataDecoratorOptions.get(metadataClass);
510
- }
511
- function getPlaceholderClassMap2RealMetadataClass() {
512
- return {
513
- placeholderClassMap2RealMetadataClass,
514
- notCalledDecorateSelfPlaceholderClassList
515
- };
516
- }
517
- function clear$1() {
518
- metadataDecoratorOptions.clear();
519
- placeholderDecoratorOptions.clear();
520
- placeholderClassMap2RealMetadataClass.clear();
521
- notCalledDecorateSelfPlaceholderClassList.length = 0;
522
- }
523
-
524
- let createdDecoratorMetadataSet = new Set();
321
+ const createdDecoratorMetadataSet = globalObject[createdDecoratorSetKey];
525
322
  function checkIfMetadataCreateMoreThenOneDecorator(metadataClass) {
526
323
  if (!createdDecoratorMetadataSet.has(metadataClass)) {
527
324
  createdDecoratorMetadataSet.add(metadataClass);
@@ -529,185 +326,143 @@ function checkIfMetadataCreateMoreThenOneDecorator(metadataClass) {
529
326
  throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10014, metadataClass.name)));
530
327
  }
531
328
  }
532
- function createDecoratorExpFactory(fn) {
329
+ function createDecoratorExpFactory() {
533
330
  return function (isPlaceholderExp, metadataClass, option) {
534
- const MetaClsOrPlaceholderMetaCls = metadataClass;
535
- addCreateDecoratorOption(isPlaceholderExp, MetaClsOrPlaceholderMetaCls, option);
331
+ addCreateDecoratorOption(isPlaceholderExp, metadataClass, option);
332
+ // TODO: 这里只校验直接创建装饰器的元数据类,可能遗漏占位装饰器绑定的元数据类;
333
+ // 应改为在计算出所有运行时装饰器表达式及其元数据类之后统一校验。
536
334
  if (!isPlaceholderExp) {
537
- checkIfMetadataCreateMoreThenOneDecorator(MetaClsOrPlaceholderMetaCls);
538
- }
539
- const placeholderDecoratorModifyPrototype = new Map();
540
- function decorateSelf(userParam) {
541
- return function (beDecoratedCls, context) {
542
- switch (context.kind) {
543
- case KindClass:
544
- {
545
- if (isPlaceholderExp) {
546
- addPlaceholderClassToRealMetadataClassRelation(MetaClsOrPlaceholderMetaCls, beDecoratedCls);
547
- checkIfMetadataCreateMoreThenOneDecorator(beDecoratedCls);
548
- } else {
549
- throw new Error('decorateSelf函数只能调用一次');
550
- }
551
- fn(isPlaceholderExp, beDecoratedCls, {
552
- metadataKind: KindClass,
553
- metadataClass: MetaClsOrPlaceholderMetaCls,
554
- metadataParam: userParam
555
- });
556
- const config = placeholderDecoratorModifyPrototype.get(MetaClsOrPlaceholderMetaCls);
557
- if (typeof beDecoratedCls?.classDecoratorModifyPrototype === 'function') {
558
- // 直接flush掉待修改的类,然后设置成修改函数即可。
559
- if (config && config.toUpdateClassSet.size) {
560
- for (const cls of Array.from(config.toUpdateClassSet)) {
561
- beDecoratedCls?.classDecoratorModifyPrototype(cls.prototype);
562
- }
563
- }
564
- placeholderDecoratorModifyPrototype.set(MetaClsOrPlaceholderMetaCls, {
565
- classDecoratorModifyPrototype: beDecoratedCls.classDecoratorModifyPrototype
566
- });
567
- } else {
568
- placeholderDecoratorModifyPrototype.set(MetaClsOrPlaceholderMetaCls, {
569
- classDecoratorModifyPrototype: null
570
- });
571
- }
572
- break;
573
- }
574
- default:
575
- throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10019, context.kind)));
576
- }
577
- return undefined;
578
- };
335
+ checkIfMetadataCreateMoreThenOneDecorator(metadataClass);
579
336
  }
580
337
  function doCreateDecoratorExp(userParam) {
581
- return function (beDecoratedCls, context) {
582
- switch (context.kind) {
583
- case KindClass:
584
- {
585
- fn(isPlaceholderExp, beDecoratedCls, {
586
- metadataKind: KindClass,
587
- metadataClass: MetaClsOrPlaceholderMetaCls,
588
- metadataParam: userParam
589
- });
590
- // 修改prototype
591
- if (isPlaceholderExp) {
592
- const config = placeholderDecoratorModifyPrototype.get(MetaClsOrPlaceholderMetaCls);
593
- if (!config) {
594
- // 第一次遇到,先收集
595
- const toUpdateClassSet = new Set();
596
- toUpdateClassSet.add(beDecoratedCls);
597
- placeholderDecoratorModifyPrototype.set(MetaClsOrPlaceholderMetaCls, {
598
- toUpdateClassSet
599
- });
600
- } else {
601
- if (config.classDecoratorModifyPrototype) {
602
- // 已经装饰过自己了,直接修改
603
- config.classDecoratorModifyPrototype(beDecoratedCls.prototype);
604
- } else {
605
- if (config.classDecoratorModifyPrototype === undefined) {
606
- // 又装饰器其他类,同样收集
607
- config.toUpdateClassSet.add(beDecoratedCls);
608
- } else if (config.classDecoratorModifyPrototype === null) {
609
- // 不需要更新了,清空即可
610
- config.toUpdateClassSet?.clear();
611
- }
612
- }
613
- }
614
- } else {
615
- // 不是占位装饰器,直接修改被装饰类的原型链
616
- if (typeof MetaClsOrPlaceholderMetaCls?.classDecoratorModifyPrototype === 'function') {
617
- MetaClsOrPlaceholderMetaCls?.classDecoratorModifyPrototype(beDecoratedCls.prototype);
618
- }
619
- }
620
- break;
621
- }
622
- case KindMethod:
623
- case KindField:
624
- case KindGetter:
625
- break;
626
- case KindSetter:
627
- case KindAccessor:
628
- default:
629
- throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10019, context.kind)));
630
- }
631
- const execOnce = once(function initializer() {
632
- switch (context.kind) {
633
- case KindField:
634
- case KindMethod:
635
- case KindGetter:
636
- fn(isPlaceholderExp, this.constructor, {
637
- metadataKind: context.kind,
638
- metadataClass: MetaClsOrPlaceholderMetaCls,
639
- metadataParam: userParam,
640
- field: context.name
641
- });
642
- break;
643
- }
644
- });
645
- context.addInitializer(function () {
646
- execOnce(this);
647
- });
648
- return undefined;
338
+ return function (_beDecoratedCls, _context) {
339
+ // 普通装饰器表达式正常应由 AOT 编译期转换为 registerComponent 注册代码,
340
+ // 运行到这里说明代码未经 @cocojs/compiler 编译。
341
+ throw new Error('装饰器不应在运行时执行,请先使用 @cocojs/compiler 编译后再运行。');
649
342
  };
650
343
  }
651
344
  if (isPlaceholderExp) {
652
- doCreateDecoratorExp.decorateSelf = decorateSelf;
345
+ const placeholderExp = doCreateDecoratorExp;
346
+ placeholderExp.$$metadataClass = metadataClass;
347
+ placeholderExp.$$isPlaceholderDecoratorExp = true;
348
+ placeholderExp.$$placeholderMetadataClass = metadataClass;
349
+ return placeholderExp;
350
+ } else {
351
+ const decoratorExp = doCreateDecoratorExp;
352
+ decoratorExp.$$metadataClass = metadataClass;
353
+ decoratorExp.$$isPlaceholderDecoratorExp = false;
354
+ return decoratorExp;
653
355
  }
654
- return doCreateDecoratorExp;
655
356
  };
656
357
  }
657
- const doCreateDecoratorExp = createDecoratorExpFactory(addDecoratorParams);
358
+ const doCreateDecoratorExp = createDecoratorExpFactory();
359
+ function createDecoratorExp(metadataClsOrOption, option) {
360
+ if (typeof metadataClsOrOption === 'function') {
361
+ const metadataCls = metadataClsOrOption;
362
+ if (!isSubClassOf(metadataCls, Metadata)) {
363
+ throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10018, metadataCls?.name)));
364
+ }
365
+ return doCreateDecoratorExp(false, metadataCls, option);
366
+ } else {
367
+ if (metadataClsOrOption !== undefined && !isPlainObject(metadataClsOrOption)) {
368
+ throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10018, metadataClsOrOption?.name)));
369
+ }
370
+ // 先提供一个默认的元数据类,再通过 @metadataFor(X) 替换为真实的元数据类
371
+ class PlaceholderMetadata extends Metadata {}
372
+ return doCreateDecoratorExp(true, PlaceholderMetadata, metadataClsOrOption);
373
+ }
374
+ }
658
375
  /**
659
- * 使用元数据类创建一个装饰器函数
660
- * 适用于装饰器不装饰自己元数据类的场景
376
+ * 建立占位元数据类与真实元数据类的关联。
377
+ * 由 `@metadataFor(X)` 经 AOT 编译后调用。
661
378
  * @public
662
379
  */
663
- function createDecoratorExp(metadataCls, option) {
664
- if (!isSubClassOf(metadataCls, Metadata)) {
665
- throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10018, metadataCls?.name)));
380
+ function bindPlaceholderMetadataClass(decoratorExp, metadataClass) {
381
+ addPlaceholderClassToRealMetadataClassRelation(decoratorExp.$$placeholderMetadataClass, metadataClass);
382
+ checkIfMetadataCreateMoreThenOneDecorator(metadataClass);
383
+ }
384
+
385
+ /**
386
+ * 注册表挂在 globalThis 上,保证同一个应用里多次加载运行时模块(例如 Jest 的 resetModules)
387
+ * 时注册方和 Application 读取到同一份数据。
388
+ * 每次调用时读取,避免框架 bundle 中生成的 registerComponent 调用先于模块级变量初始化执行。
389
+ */
390
+ function getGlobalRegistry() {
391
+ const registryKey = Symbol.for('coco.decoratorRegistry');
392
+ const globalObject = globalThis;
393
+ if (!globalObject[registryKey]) {
394
+ globalObject[registryKey] = new Map();
666
395
  }
667
- return doCreateDecoratorExp(false, metadataCls, option);
396
+ return globalObject[registryKey];
668
397
  }
669
398
  /**
670
- * 创建一个未绑定元数据的装饰器表达式
671
- * 需要在正式的元数据类上添加decorateSelf装饰器来关联真实的元数据类,装饰器到其他类的使用方式和createDecoratorExp是一致的。
672
- * 适用于装饰器装饰自己元数据类的场景
399
+ * 全局静态注册函数。编译期由 coco-compiler 注入到每个源文件末尾。
400
+ * 源码中类、字段、方法、getter 上的装饰器经 AOT 编译后统一转换为对它的调用,
401
+ * 用于保存原始装饰器参数。
402
+ * `@metadataFor(X)` 不产生注册参数,只额外生成 bindPlaceholderMetadataClass 调用。
673
403
  * @public
674
404
  */
675
- function createPlaceholderDecoratorExp(option) {
676
- // 先提供一个默认的元数据类,再替换为真实的元数据类
677
- class PlaceholderMetadata extends Metadata {}
678
- return doCreateDecoratorExp(true, PlaceholderMetadata, option);
405
+ function registerComponent(cls, params) {
406
+ getGlobalRegistry().set(cls, params);
407
+ }
408
+ /** 读取userDecoratorParams */
409
+ function getRegistry() {
410
+ return getGlobalRegistry();
411
+ }
412
+
413
+ function createRuntimeDecoratorParams(userDecoratorParams) {
414
+ const runtimeDecoratorParams = new Map();
415
+ const placeholderClassMap2RealMetadataClass = getPlaceholderClassMap2RealMetadataClass();
416
+ // 基于userDecoratorParams生成runtimeDecoratorParams,并将其中的占位元数据类替换为真实元数据类
417
+ for (const [cls, params] of userDecoratorParams) {
418
+ runtimeDecoratorParams.set(cls, params.map(p => {
419
+ if (p.isPlaceholderDecoratorExp) {
420
+ const realClass = placeholderClassMap2RealMetadataClass.get(p.metadataClass);
421
+ if (!realClass) {
422
+ throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10021, cls.name)));
423
+ }
424
+ return {
425
+ metadataKind: p.metadataKind,
426
+ metadataClass: realClass,
427
+ metadataParam: p.metadataParam,
428
+ field: p.field
429
+ };
430
+ }
431
+ return {
432
+ metadataKind: p.metadataKind,
433
+ metadataClass: p.metadataClass,
434
+ metadataParam: p.metadataParam,
435
+ field: p.field
436
+ };
437
+ }));
438
+ }
439
+ for (const [beDecoratedCls, params] of runtimeDecoratorParams.entries()) {
440
+ for (const p of params) {
441
+ if (!p.metadataClass) {
442
+ throw new Error(`组件 ${beDecoratedCls?.name} 的装饰器没有对应的元数据类,请确认装饰器由 createDecoratorExp 创建。`);
443
+ }
444
+ }
445
+ if (!isCocoClass(beDecoratedCls)) {
446
+ throw new Error(`所有被装饰器的对象${beDecoratedCls?.name}必须都是类或者类字段或类方法,且必须存在静态$$id字段。`);
447
+ }
448
+ }
449
+ return runtimeDecoratorParams;
679
450
  }
680
451
 
681
452
  /**
682
453
  * 装饰器表达式模块的工作流
683
454
  */
684
455
  function initDecoratorParamModule() {
685
- // 收集field和method装饰器参数
686
- for (const Cls of getDecoratorParam().keys()) {
687
- /**
688
- * TODO: 如果view组件的state需要用到props初始化的话,会导致报错,例如:
689
- * class {
690
- * constructor(props){
691
- * this.name = props.name // 这里会报错
692
- * }
693
- * }
694
- */
695
- new Cls();
696
- }
697
- // 创建的装饰器表达式的选项,将占位的元数据类替换成真实的元数据类
456
+ // start 时把userDecoratorParams解析为runtimeDecoratorParams并校验,覆盖 Application 构造后声明的局部类。
457
+ const userDecoratorParams = getRegistry();
698
458
  mergePlaceholderClass2RealMetadataClassRelation();
699
- // 收集到的所有的装饰器参数,占位的元数据类替换成真实的元数据类
700
- replacePlaceholderMetaClassParams2RealMetadataClassParams(getPlaceholderClassMap2RealMetadataClass());
701
- // 所有的被装饰类都要符合一定的要求
702
- for (const beDecoratedClass of getDecoratorParam().keys()) {
703
- if (!isCocoClass(beDecoratedClass)) {
704
- throw new Error(`所有被装饰器的对象${beDecoratedClass?.name}必须都是类或者类字段或类方法,且必须存在静态$$id字段。`);
705
- }
706
- }
459
+ const runtimeDecoratorParams = createRuntimeDecoratorParams(userDecoratorParams);
460
+ // 注册表的职责是“待启动消费的注册信息”,解析完成后清空,避免重复消费上一次的注册
461
+ userDecoratorParams.clear();
462
+ return runtimeDecoratorParams;
707
463
  }
708
464
  function clearDecoratorParamModule() {
709
465
  clear$1();
710
- clear$2();
711
466
  }
712
467
 
713
468
  /**
@@ -723,68 +478,54 @@ var Type;
723
478
  /**
724
479
  * @public
725
480
  */
726
- const target = createPlaceholderDecoratorExp();
481
+ const target = createDecoratorExp();
727
482
 
728
- let _initClass$z;
729
483
  /**
730
484
  * @public
731
485
  */
732
- let _Target;
733
- new class extends _identity {
734
- static [class Target extends Metadata {
735
- static {
736
- [_Target, _initClass$z] = _applyDecs2311(this, [target.decorateSelf([Type.Class])], [], 0, void 0, Metadata).c;
737
- }
738
- value;
739
- }];
740
- $$id = "Target";
741
- Type = Type;
742
- constructor() {
743
- super(_Target), _initClass$z();
744
- }
745
- }();
746
- var Target = _Target;
747
-
748
- let _initClass$y;
486
+ class Target extends Metadata {
487
+ static $$id = "Target";
488
+ static Type = Type;
489
+ value;
490
+ }
491
+ bindPlaceholderMetadataClass(target, Target);
492
+ registerComponent(Target, [{
493
+ metadataKind: "class",
494
+ metadataClass: target.$$metadataClass,
495
+ metadataParam: [Type.Class],
496
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
497
+ }]);
498
+
749
499
  /**
750
500
  * @public
751
501
  */
752
- let _Autowired;
753
- new class extends _identity {
754
- static [class Autowired extends Metadata {
755
- static {
756
- [_Autowired, _initClass$y] = _applyDecs2311(this, [target([Target.Type.Field])], [], 0, void 0, Metadata).c;
757
- }
758
- value;
759
- }];
760
- $$id = "Autowired";
761
- constructor() {
762
- super(_Autowired), _initClass$y();
763
- }
764
- }();
765
- var Autowired = _Autowired;
502
+ class Autowired extends Metadata {
503
+ static $$id = "Autowired";
504
+ value;
505
+ }
506
+ registerComponent(Autowired, [{
507
+ metadataKind: "class",
508
+ metadataClass: target.$$metadataClass,
509
+ metadataParam: [Target.Type.Field],
510
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
511
+ }]);
766
512
 
767
513
  // TODO: cls?: Class<any>如果去掉的话,在项目中会报错,应该是ts-server是拿到参数了,但是声明中确没有
768
514
  var autowired = createDecoratorExp(Autowired);
769
515
 
770
- let _initClass$x;
771
516
  /**
772
517
  * @public
773
518
  */
774
- let _Id;
775
- new class extends _identity {
776
- static [class Id extends Metadata {
777
- static {
778
- [_Id, _initClass$x] = _applyDecs2311(this, [target([Target.Type.Method])], [], 0, void 0, Metadata).c;
779
- }
780
- value;
781
- }];
782
- $$id = "Id";
783
- constructor() {
784
- super(_Id), _initClass$x();
785
- }
786
- }();
787
- var Id = _Id;
519
+ class Id extends Metadata {
520
+ static $$id = "Id";
521
+ value;
522
+ }
523
+ registerComponent(Id, [{
524
+ metadataKind: "class",
525
+ metadataClass: target.$$metadataClass,
526
+ metadataParam: [Target.Type.Method],
527
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
528
+ }]);
788
529
 
789
530
  /**
790
531
  * @id装饰器
@@ -792,7 +533,6 @@ var Id = _Id;
792
533
  */
793
534
  var id = createDecoratorExp(Id);
794
535
 
795
- let _initClass$w;
796
536
  /**
797
537
  * Component不添加@scope(SCOPE.Singleton)的原因:
798
538
  * 因为不设置默认就是singleton,还可以避免 scope <-> target 循环依赖的问题
@@ -800,20 +540,16 @@ let _initClass$w;
800
540
  /**
801
541
  * @public
802
542
  */
803
- let _Component;
804
- new class extends _identity {
805
- static [class Component extends Metadata {
806
- static {
807
- [_Component, _initClass$w] = _applyDecs2311(this, [target([Target.Type.Class, Target.Type.Method])], [], 0, void 0, Metadata).c;
808
- }
809
- value;
810
- }];
811
- $$id = "Component";
812
- constructor() {
813
- super(_Component), _initClass$w();
814
- }
815
- }();
816
- var Component = _Component;
543
+ class Component extends Metadata {
544
+ static $$id = "Component";
545
+ value;
546
+ }
547
+ registerComponent(Component, [{
548
+ metadataKind: "class",
549
+ metadataClass: target.$$metadataClass,
550
+ metadataParam: [Target.Type.Class, Target.Type.Method],
551
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
552
+ }]);
817
553
 
818
554
  /**
819
555
  * ioc组件,只有ioc组件才能实例化
@@ -821,48 +557,37 @@ var Component = _Component;
821
557
  */
822
558
  var component = createDecoratorExp(Component);
823
559
 
824
- let _initClass$v;
825
560
  /**
826
561
  * @public
827
562
  */
828
- let _Configuration;
829
- new class extends _identity {
830
- static [class Configuration extends Metadata {
831
- static {
832
- [_Configuration, _initClass$v] = _applyDecs2311(this, [target([Target.Type.Class])], [], 0, void 0, Metadata).c;
833
- }
834
- }];
835
- $$id = "Configuration";
836
- constructor() {
837
- super(_Configuration), _initClass$v();
838
- }
839
- }();
840
- var Configuration = _Configuration;
563
+ class Configuration extends Metadata {
564
+ static $$id = "Configuration";
565
+ }
566
+ registerComponent(Configuration, [{
567
+ metadataKind: "class",
568
+ metadataClass: target.$$metadataClass,
569
+ metadataParam: [Target.Type.Class],
570
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
571
+ }]);
841
572
 
842
573
  var configuration = createDecoratorExp(Configuration);
843
574
 
844
- let _initClass$u;
845
575
  /**
846
576
  * @public
847
577
  */
848
- let _ConstructorInject;
849
- new class extends _identity {
850
- static [class ConstructorInject extends Metadata {
851
- static {
852
- [_ConstructorInject, _initClass$u] = _applyDecs2311(this, [target([Target.Type.Class])], [], 0, void 0, Metadata).c;
853
- }
854
- value;
855
- }];
856
- $$id = "ConstructorInject";
857
- constructor() {
858
- super(_ConstructorInject), _initClass$u();
859
- }
860
- }();
861
- var ConstructorInject = _ConstructorInject;
578
+ class ConstructorInject extends Metadata {
579
+ static $$id = "ConstructorInject";
580
+ value;
581
+ }
582
+ registerComponent(ConstructorInject, [{
583
+ metadataKind: "class",
584
+ metadataClass: target.$$metadataClass,
585
+ metadataParam: [Target.Type.Class],
586
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
587
+ }]);
862
588
 
863
589
  var constructorInject = createDecoratorExp(ConstructorInject);
864
590
 
865
- let _initClass$t;
866
591
  /**
867
592
  * @public
868
593
  */
@@ -876,62 +601,48 @@ exports.SCOPE = void 0;
876
601
  /**
877
602
  * @public
878
603
  */
879
- let _Scope;
880
- new class extends _identity {
881
- static [class Scope extends Metadata {
882
- static {
883
- [_Scope, _initClass$t] = _applyDecs2311(this, [target([Target.Type.Class, Target.Type.Method])], [], 0, void 0, Metadata).c;
884
- }
885
- value = exports.SCOPE.Singleton;
886
- }];
887
- $$id = "Scope";
888
- constructor() {
889
- super(_Scope), _initClass$t();
890
- }
891
- }();
892
- var Scope = _Scope;
604
+ class Scope extends Metadata {
605
+ static $$id = "Scope";
606
+ value = exports.SCOPE.Singleton;
607
+ }
608
+ registerComponent(Scope, [{
609
+ metadataKind: "class",
610
+ metadataClass: target.$$metadataClass,
611
+ metadataParam: [Target.Type.Class, Target.Type.Method],
612
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
613
+ }]);
893
614
 
894
615
  var scope = createDecoratorExp(Scope);
895
616
 
896
- let _initClass$s;
897
617
  /**
898
618
  * @public
899
619
  */
900
- let _Qualifier;
901
- new class extends _identity {
902
- static [class Qualifier extends Metadata {
903
- static {
904
- [_Qualifier, _initClass$s] = _applyDecs2311(this, [target([Target.Type.Field])], [], 0, void 0, Metadata).c;
905
- }
906
- value;
907
- }];
908
- $$id = "Qualifier";
909
- constructor() {
910
- super(_Qualifier), _initClass$s();
911
- }
912
- }();
913
- var Qualifier = _Qualifier;
620
+ class Qualifier extends Metadata {
621
+ static $$id = "Qualifier";
622
+ value;
623
+ }
624
+ registerComponent(Qualifier, [{
625
+ metadataKind: "class",
626
+ metadataClass: target.$$metadataClass,
627
+ metadataParam: [Target.Type.Field],
628
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
629
+ }]);
914
630
 
915
631
  var qualifier = createDecoratorExp(Qualifier);
916
632
 
917
- let _initClass$r;
918
633
  /**
919
634
  * @public
920
635
  */
921
- let _Value;
922
- new class extends _identity {
923
- static [class Value extends Metadata {
924
- static {
925
- [_Value, _initClass$r] = _applyDecs2311(this, [target([Target.Type.Field])], [], 0, void 0, Metadata).c;
926
- }
927
- value;
928
- }];
929
- $$id = "Value";
930
- constructor() {
931
- super(_Value), _initClass$r();
932
- }
933
- }();
934
- var Value = _Value;
636
+ class Value extends Metadata {
637
+ static $$id = "Value";
638
+ value;
639
+ }
640
+ registerComponent(Value, [{
641
+ metadataKind: "class",
642
+ metadataClass: target.$$metadataClass,
643
+ metadataParam: [Target.Type.Field],
644
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
645
+ }]);
935
646
 
936
647
  var value = createDecoratorExp(Value, {
937
648
  componentPostConstruct: function (metadata, application, target) {
@@ -1230,7 +941,7 @@ class ComponentMetadataClass {
1230
941
  // 遍历所有被装饰器的元数据类,将自己添加为被装饰器类的组件装饰器
1231
942
  const beDecoratedClasses = decorateTree.get(current) || new Set();
1232
943
  for (const beDecoratedClass of beDecoratedClasses) {
1233
- // 忽略自己装饰自己的情况(decorateSelf),因为这不算是组件装饰器
944
+ // 忽略自己装饰自己的情况(bind),因为这不算是组件装饰器
1234
945
  if (beDecoratedClass === current) {
1235
946
  // 避免自引用导致的无限循环
1236
947
  if (!visited.has(beDecoratedClass)) {
@@ -1430,137 +1141,6 @@ class ComponentMetadataClass {
1430
1141
  }
1431
1142
  }
1432
1143
 
1433
- /**
1434
- * component
1435
- * 1. 只能用在class或者method上,且只能装饰一次
1436
- * 2. 不能和其他component复合装饰器同时使用
1437
- */
1438
- /**
1439
- * view
1440
- * 1. 只能用在class,且只能装饰一次
1441
- * 2. 不能和其他component复合装饰器同时使用
1442
- */
1443
- /**
1444
- * page
1445
- * 1. 只能用在class,且只能装饰一次
1446
- * 2. 不能和其他component复合装饰器同时使用
1447
- */
1448
- /**
1449
- * layout
1450
- * 1. 只能用在class,且只能使用一次
1451
- * 2. 不能和其他component复合装饰器同时使用
1452
- */
1453
- /**
1454
- * qualifier
1455
- * 1. 只能用在field上,且只能装饰一次
1456
- * 2. 依赖component配合使用
1457
- */
1458
- /**
1459
- * autowired
1460
- * 1. 只能用在field上,且只能装饰一次
1461
- * 2. TODO: 只能在view及其复合装饰器组件内部、controller及其复合装饰器组件内部、api装饰器组件内部
1462
- * 3. 自动注入收到分层概念的约束,具体如下:
1463
- * 3.1 view及其复合装饰器内部:controller及其复合装饰器组件, global-data, store, route, router,util及其复合装饰器组件
1464
- * 3.2 controller及其复合装饰器内部:util及其复合装饰器组件
1465
- * 3.3 util及其复合装饰器内部:util以及复合装饰器组件
1466
- */
1467
- /**
1468
- * configuration
1469
- * 1. 只能用在class上,且只能装饰一次
1470
- * 2. 不能和其他component复合装饰器同时使用
1471
- */
1472
- /**
1473
- * constructor-inject
1474
- * 1. 只能用在class上,且只能装饰一次
1475
- */
1476
- /**
1477
- * init
1478
- * 1. 只能用在method上,且只能装饰一次
1479
- * 2. 不能和其他component复合装饰器同时使用
1480
- */
1481
- /**
1482
- * start
1483
- * 1. 只能用在field上,且只能装饰一次
1484
- * 2. 不能和其他component复合装饰器同时使用
1485
- */
1486
- /**
1487
- * target
1488
- * 1. 只能用在field上,且只能装饰一次
1489
- * 2. 不能和其他component复合装饰器同时使用
1490
- */
1491
- /**
1492
- * value
1493
- * 1. 只能用在field上,且只能装饰一次
1494
- */
1495
- /**
1496
- * reactive
1497
- * 1. 只能用在field上,且只能装饰一次
1498
- */
1499
- /**
1500
- * memoized
1501
- * 1. 只能用在method上,且只能装饰一次
1502
- * 2. 不能和其他component复合装饰器同时使用
1503
- */
1504
- /**
1505
- * store
1506
- * 1. 只能用在class上,且只能装饰一次
1507
- * 2. 不能和其他component复合装饰器同时使用
1508
- */
1509
- /**
1510
- * render
1511
- * 1. 只能用在class上,且只能装饰一次
1512
- * 2. 不能和其他component复合装饰器同时使用
1513
- */
1514
- /**
1515
- * route
1516
- * 1. 只能用在class上,且只能装饰一次
1517
- * 2. 在class上使用时,依赖page同时使用
1518
- */
1519
- /**
1520
- * router
1521
- * 1. 只能用在class上,且只能装饰一次
1522
- * 2. 不能和其他component复合装饰器同时使用
1523
- */
1524
- /**
1525
- * util
1526
- * 1. 只能用在class上,且只能装饰一次
1527
- * 2. 不能和其他component复合装饰器同时使用
1528
- */
1529
- /**
1530
- * api
1531
- * 1. 只能用在class上,且只能装饰一次
1532
- * 2. 不能和其他component复合装饰器同时使用
1533
- */
1534
- /**
1535
- * bind
1536
- * 1. 只能用在method上,且只能装饰一次
1537
- * 2. 只能在有view装饰器或者view复合装饰器组件上使用
1538
- */
1539
- /**
1540
- * flow
1541
- * 1. 只能用在class上,且只能装饰一次
1542
- * 2. 不能和其他component复合装饰器同时使用
1543
- */
1544
- /**
1545
- * global-data
1546
- * 1. 只能用在class上,且只能装饰一次
1547
- * 2. 不能和component复合装饰器同时使用
1548
- */
1549
- /**
1550
- * ref
1551
- * 1. 只能用在field上,且只能装饰一次
1552
- * 2. 宿主组件必须是view组件或者是view复合组件
1553
- */
1554
- /**
1555
- * refs
1556
- * 1. 只能用在field上,且只能装饰一次
1557
- * 2. 宿主组件必须是view组件或者是view复合组件
1558
- */
1559
- /**
1560
- * web-application
1561
- * 1. 只能用在class上,且只能装饰一次
1562
- * 2.
1563
- */
1564
1144
  function deleteMetadatas(metadatas, idxs) {
1565
1145
  idxs.sort((a, b) => b - a);
1566
1146
  idxs.forEach(idx => metadatas.splice(idx, 1));
@@ -2025,12 +1605,13 @@ class IocComponentDefinition {
2025
1605
  this.clsDefinitionMap.set(cls, componentDefinition);
2026
1606
  }
2027
1607
  /**
2028
- * 获取真正会实例化的类定义
1608
+ * 解析组件实际需要实例化的类。
1609
+ * 没有子类时返回自身,只有一个子类时返回该子类,多个子类时抛出异常。
2029
1610
  * @param ClsOrId 想要实例化的类或类id
2030
1611
  * @param qualifier 如果存在多个后端类,需要通过qualifier指定具体的类id
2031
1612
  * @returns 真正会实例化的类定义
2032
1613
  */
2033
- getInstantiateDefinition(ClsOrId, qualifier) {
1614
+ resolve(ClsOrId, qualifier) {
2034
1615
  const definition = this.getDefinition(ClsOrId);
2035
1616
  if (!definition) {
2036
1617
  const diagnose = createDiagnose(DiagnoseCode.CO10011, typeof ClsOrId === 'string' ? ClsOrId : ClsOrId.name);
@@ -2082,10 +1663,72 @@ class IocComponentDefinition {
2082
1663
  }
2083
1664
  }
2084
1665
 
1666
+ var InjectType;
1667
+ (function (InjectType) {
1668
+ InjectType["constructor"] = "c";
1669
+ InjectType["autowired"] = "a";
1670
+ })(InjectType || (InjectType = {}));
1671
+ class DependencyGraph {
1672
+ // 创建中的ioc组件定义
1673
+ creating = new Set();
1674
+ // 已经完成newComponent的ioc组件
1675
+ earlyCreate = new Set();
1676
+ // 当前实例化路径
1677
+ stack = [];
1678
+ injectStr(type) {
1679
+ const s = type === InjectType.constructor ? '-c->' : type === InjectType.autowired ? '-a->' : '';
1680
+ return s ? `${s} ` : s;
1681
+ }
1682
+ addDependency(targetDefinition, instantiateDefinition, injectType) {
1683
+ // console.info('addDep', instantiateDefinition.cls.name);
1684
+ if (this.creating.has(instantiateDefinition) && (!instantiateDefinition.isSingleton || !this.earlyCreate.has(instantiateDefinition))) {
1685
+ const fullStack = [...this.stack, {
1686
+ targetDef: targetDefinition,
1687
+ instantiateDef: instantiateDefinition,
1688
+ injectType
1689
+ }];
1690
+ const loopDependencyInfo = fullStack.map(i => `${this.injectStr(i.injectType)}${i.instantiateDef.cls.name}${i.targetDef !== i.instantiateDef ? `{${i.targetDef.cls.name}}` : ''}`).join(' ');
1691
+ const diagnose = createDiagnose(DiagnoseCode.CO10013, loopDependencyInfo);
1692
+ throw new Error(stringifyDiagnose(diagnose));
1693
+ }
1694
+ this.creating.add(instantiateDefinition);
1695
+ this.stack.push({
1696
+ instantiateDef: instantiateDefinition,
1697
+ targetDef: targetDefinition,
1698
+ injectType
1699
+ });
1700
+ }
1701
+ removeDependency(targetDefinition, instantiateDefinition) {
1702
+ // console.info('rmDep', instantiateDefinition.cls.name);
1703
+ const now = this.stack.pop();
1704
+ if (now.targetDef !== targetDefinition || now.instantiateDef !== instantiateDefinition) {
1705
+ throw new Error();
1706
+ }
1707
+ this.earlyCreate.delete(instantiateDefinition);
1708
+ this.creating.delete(instantiateDefinition);
1709
+ }
1710
+ makeEarlyCreated(instantiateDefinition) {
1711
+ // console.info('mkEarly', instantiateDefinition.cls.name);
1712
+ if (!this.creating.has(instantiateDefinition)) {
1713
+ throw new Error('没有创建就调用了makeEarlyCreated,是一个bug');
1714
+ }
1715
+ this.earlyCreate.add(instantiateDefinition);
1716
+ }
1717
+ }
1718
+
1719
+ var InstantiateStage;
1720
+ (function (InstantiateStage) {
1721
+ // 在等待构造函数创建中
1722
+ InstantiateStage["WAITING_CTOR_ARGS"] = "waitCtorArgs";
1723
+ // 刚new出来,componentPostConstruct已执行,autowired未注入
1724
+ InstantiateStage["UNINITIALIZED"] = "uninitialized";
1725
+ // 初始化完毕:属性全部注入,init已执行,start未执行
1726
+ InstantiateStage["INITIALIZED"] = "initialized";
1727
+ })(InstantiateStage || (InstantiateStage = {}));
2085
1728
  class IocComponentFactory {
2086
1729
  // 单例构造函数和单例的映射关系
2087
1730
  singletonInstances = new Map();
2088
- createComponent(application, definition, constructorArgs) {
1731
+ newComponent(application, definition, constructorArgs) {
2089
1732
  const {
2090
1733
  cls,
2091
1734
  instantiateType
@@ -2152,18 +1795,18 @@ class IocComponentFactory {
2152
1795
  return component;
2153
1796
  }
2154
1797
  getComponents(application, userOption) {
2155
- const targetClsInstanceMap = new Map(); // 想要实例化的类和对应的实例
2156
- const instanceInstantiateClsMap = new Map(); // 新建实例和对应的实例化类
1798
+ /**
1799
+ * TODO: dependencyGraph 在 getComponents 内部创建,getComponents 一旦重入(如 init 内再次 getComponent),
1800
+ * 就会拿到另一张图、丢失外层创建链路,循环依赖检查因此失效。
1801
+ * 解决方向二选一:
1802
+ * 1. 约束 getComponents 只能顺序调用;
1803
+ * 2. 把 dependencyGraph 提升为唯一实例供重入共享。
1804
+ */
1805
+ const dependencyGraph = new DependencyGraph();
1806
+ const newCreateInstance = []; // 新建实例和对应的实例化类
2157
1807
  const newSingletonInstances = new Map(); // 新增的单例,最后要合并到singletonInstances
2158
- const instantiatingStage = new Set(); // 实例化中
2159
- const assignningStage = new Set(); // field赋值中
2160
- const finishedStage = new Set(); // 已完成
2161
- // 已经有的单例填充到finishedStage和instances
2162
- for (const [cls, instance] of this.singletonInstances.entries()) {
2163
- targetClsInstanceMap.set(cls, instance);
2164
- }
2165
1808
  // 完整的初始化一个组件
2166
- const instantiateComponent = opt => {
1809
+ const instantiateComponent = (opt, injectType) => {
2167
1810
  const {
2168
1811
  classOrId
2169
1812
  } = opt;
@@ -2179,7 +1822,8 @@ class IocComponentFactory {
2179
1822
  qualifier = application.propertiesConfig.getValue(`${targetDefinition.id}.qualifier`);
2180
1823
  }
2181
1824
  // 真正实例化的类定义
2182
- const instantiateDefinition = application.iocComponentDefinition.getInstantiateDefinition(classOrId, qualifier);
1825
+ const instantiateDefinition = application.iocComponentDefinition.resolve(classOrId, qualifier);
1826
+ // 尝试走缓存
2183
1827
  if (instantiateDefinition.isSingleton) {
2184
1828
  if (this.singletonInstances.has(instantiateDefinition.cls)) {
2185
1829
  return this.singletonInstances.get(instantiateDefinition.cls);
@@ -2187,76 +1831,94 @@ class IocComponentFactory {
2187
1831
  return newSingletonInstances.get(instantiateDefinition.cls);
2188
1832
  }
2189
1833
  }
2190
- if (instantiatingStage.has(targetDefinition.cls)) {
2191
- // 理论上不可能走到这里
2192
- throw new Error(`循环依赖: ${targetDefinition.cls.name}`);
2193
- }
2194
- // 在实例化中或者已实例化,返回实例
2195
- if (assignningStage.has(targetDefinition.cls) || finishedStage.has(targetDefinition.cls)) {
2196
- return targetClsInstanceMap.get(targetDefinition.cls);
2197
- }
2198
- instantiatingStage.add(targetDefinition.cls);
1834
+ dependencyGraph.addDependency(targetDefinition, instantiateDefinition, injectType);
1835
+ // newAddStage(targetDefinition.cls, InstantiateStage.WAITING_CTOR_ARGS);
1836
+ // 没有缓存,只能真的创建了
2199
1837
  const constructorArgs = [];
2200
1838
  const constructorInject = application.metadataRepository.listClassKindMetadata(instantiateDefinition.cls, ConstructorInject);
2201
- if (constructorInject.length > 0) {
2202
- // 因为元数据不能重复,所以只有一个
1839
+ if (constructorInject.length === 1) {
2203
1840
  const constructorInjectParams = constructorInject[0].value;
2204
- for (const dependency of constructorInjectParams) {
2205
- if (dependency === undefined) {
1841
+ for (const dependencyCls of constructorInjectParams) {
1842
+ if (dependencyCls === undefined) {
2206
1843
  constructorArgs.push(undefined);
2207
1844
  } else {
2208
1845
  const depInstance = instantiateComponent({
2209
- classOrId: dependency
2210
- });
2211
- // 确保依赖已完全注入
2212
- if (!finishedStage.has(dependency) && !this.singletonInstances.has(dependency)) {
2213
- const diagnose = createDiagnose(DiagnoseCode.CO10013, targetDefinition.cls.name, dependency.name);
2214
- throw new Error(stringifyDiagnose(diagnose));
2215
- }
1846
+ classOrId: dependencyCls
1847
+ }, InjectType.constructor);
2216
1848
  constructorArgs.push(depInstance);
2217
1849
  }
2218
1850
  }
1851
+ } else if (constructorInject.length > 1) {
1852
+ throw new Error(`${targetDefinition.cls.name}存在不止一个@constructorInject装饰器`);
2219
1853
  }
2220
1854
  // 2. 实例化,同时执行componentPostConstruct
2221
- const instance = this.createComponent(application, instantiateDefinition, constructorArgs);
1855
+ const instance = this.newComponent(application, instantiateDefinition, constructorArgs);
1856
+ dependencyGraph.makeEarlyCreated(instantiateDefinition);
1857
+ newCreateInstance.push(instance);
1858
+ // updateStage(targetDefinition.cls, InstantiateStage.UNINITIALIZED);
2222
1859
  if (instantiateDefinition.isSingleton) {
2223
1860
  newSingletonInstances.set(instantiateDefinition.cls, instance);
2224
1861
  }
2225
- targetClsInstanceMap.set(targetDefinition.cls, instance);
2226
- instanceInstantiateClsMap.set(instance, instantiateDefinition.cls);
2227
- instantiatingStage.delete(targetDefinition.cls);
2228
- assignningStage.add(targetDefinition.cls);
2229
1862
  // 3. 递归实例化field注入
2230
- const autowiredFields = application.metadataRepository.listFieldByMetadataCls(instantiateDefinition.cls, Autowired);
2231
- for (const field of autowiredFields) {
2232
- const autowiredMetadatas = application.metadataRepository.listFieldKindMetadata(instantiateDefinition.cls, field, Autowired);
2233
- if (autowiredMetadatas.length > 0) {
2234
- const autowiredCls = autowiredMetadatas[0].value;
2235
- if (autowiredCls === undefined) {
2236
- instance[field] = undefined;
2237
- } else if (autowiredCls === instantiateDefinition.cls) {
2238
- // 检查自依赖:不能注入自己
2239
- // TODO: 如果autowiredCls是instantiateDefinition.cls的祖先类或者子孙类怎么办?
2240
- const diagnose = createDiagnose(DiagnoseCode.CO10012, instantiateDefinition.cls.name, field);
2241
- printDiagnose(diagnose);
2242
- instance[field] = undefined;
2243
- } else {
2244
- const qualifierMetadatas = application.metadataRepository.listFieldKindMetadata(instantiateDefinition.cls, field, Qualifier);
2245
- let qualifier;
2246
- if (qualifierMetadatas.length > 0) {
2247
- qualifier = qualifierMetadatas[0].value;
2248
- }
2249
- const autowiredInstance = instantiateComponent({
2250
- classOrId: autowiredCls,
2251
- qualifier
2252
- });
2253
- instance[field] = autowiredInstance;
2254
- }
1863
+ const componentClasses = [instantiateDefinition.cls];
1864
+ let parentCls = Object.getPrototypeOf(instantiateDefinition.cls);
1865
+ while (application.iocComponentDefinition.existDefinition(parentCls)) {
1866
+ componentClasses.unshift(parentCls);
1867
+ parentCls = Object.getPrototypeOf(parentCls);
1868
+ }
1869
+ const autowiredFields = new Map();
1870
+ for (const declaringClass of componentClasses) {
1871
+ const fields = application.metadataRepository.listFieldByMetadataCls(declaringClass, Autowired);
1872
+ for (const field of fields) {
1873
+ const autowired = application.metadataRepository.listFieldKindMetadata(declaringClass, field, Autowired)[0];
1874
+ const qualifier = application.metadataRepository.listFieldKindMetadata(declaringClass, field, Qualifier)[0];
1875
+ // 子类同名字段覆盖父类,并按子类字段的位置注入。
1876
+ autowiredFields.delete(field);
1877
+ autowiredFields.set(field, {
1878
+ declaringClass,
1879
+ field,
1880
+ autowired,
1881
+ qualifier
1882
+ });
1883
+ }
1884
+ }
1885
+ for (const {
1886
+ field,
1887
+ autowired,
1888
+ qualifier
1889
+ } of autowiredFields.values()) {
1890
+ const autowiredCls = autowired.value;
1891
+ if (autowiredCls === undefined) {
1892
+ instance[field] = undefined;
1893
+ continue;
1894
+ }
1895
+ if (instantiateDefinition.isSingleton && autowiredCls === instantiateDefinition.cls) {
1896
+ // 检查自依赖:不能注入自己
1897
+ // TODO: 如果autowiredCls是instantiateDefinition.cls的祖先类或者子孙类怎么办?
1898
+ const diagnose = createDiagnose(DiagnoseCode.CO10012, instantiateDefinition.cls.name, field);
1899
+ printDiagnose(diagnose);
1900
+ instance[field] = undefined;
1901
+ continue;
1902
+ }
1903
+ const realAutowiredDef = application.iocComponentDefinition.resolve(autowiredCls, qualifier?.value);
1904
+ if (instantiateDefinition.isSingleton && realAutowiredDef.cls !== autowiredCls && realAutowiredDef.cls === instantiateDefinition.cls) {
1905
+ // 自身更好是注入类的唯一子类
1906
+ const diagnose = createDiagnose(DiagnoseCode.CO10012, instantiateDefinition.cls.name, field);
1907
+ printDiagnose(diagnose);
1908
+ instance[field] = undefined;
1909
+ continue;
2255
1910
  }
1911
+ instance[field] = instantiateComponent({
1912
+ classOrId: autowiredCls,
1913
+ qualifier: qualifier?.value
1914
+ }, InjectType.autowired);
2256
1915
  }
2257
- // 4. 标记为完全注入
2258
- assignningStage.delete(targetDefinition.cls);
2259
- finishedStage.add(targetDefinition.cls);
1916
+ // 4. autowired也注入完毕
1917
+ if (typeof instance['init'] === 'function') {
1918
+ instance['init']?.call(instance, application);
1919
+ }
1920
+ dependencyGraph.removeDependency(targetDefinition, instantiateDefinition);
1921
+ // updateStage(targetDefinition.cls, InstantiateStage.INITIALIZED);
2260
1922
  return instance;
2261
1923
  };
2262
1924
  // TODO: 如果初始化多个,有没有先后顺序问题?
@@ -2265,22 +1927,12 @@ class IocComponentFactory {
2265
1927
  if (newSingletonInstances.size > 0) {
2266
1928
  for (const [cls, instance] of newSingletonInstances.entries()) {
2267
1929
  this.singletonInstances.set(cls, instance);
2268
- // 现在默认子类的singleton和父类都是保持一致的。TODO: 如果子类的singleton不是单例了,应该如何处理
2269
- }
2270
- }
2271
- // 5. 所有新增的单例执行init方法
2272
- for (const cls of finishedStage.keys()) {
2273
- // 这里应该是根据instance来判断是否已经存在的
2274
- const instance = targetClsInstanceMap.get(cls);
2275
- if (typeof instance['init'] === 'function') {
2276
- instance['init']?.call(instance, application);
2277
1930
  }
2278
1931
  }
2279
1932
  // 执行start方法
2280
- for (const cls of finishedStage.keys()) {
2281
- const instance = targetClsInstanceMap.get(cls);
2282
- if (typeof instance['start'] === 'function') {
2283
- instance['start']?.call(instance, application);
1933
+ for (const ins of newCreateInstance) {
1934
+ if (typeof ins['start'] === 'function') {
1935
+ ins['start']?.call(ins, application);
2284
1936
  }
2285
1937
  }
2286
1938
  return instance;
@@ -2291,8 +1943,8 @@ class IocComponentFactory {
2291
1943
  const diagnose = createDiagnose(DiagnoseCode.CO10011, typeof viewClass === 'string' ? viewClass : viewClass.name);
2292
1944
  throw new Error(stringifyDiagnose(diagnose));
2293
1945
  }
2294
- // 视图组件目前简单的认为全是prototype,且不支持实例化子组件
2295
- const instance = this.createComponent(application, targetDefinition, [props]);
1946
+ // 视图组件目前简单的认为全是prototype,且不支持实例化子组件,TODO:补充不支持继承的限制和测试用例
1947
+ const instance = this.newComponent(application, targetDefinition, [props]);
2296
1948
  const autowiredFields = application.metadataRepository.listFieldByMetadataCls(targetDefinition.cls, Autowired);
2297
1949
  for (const field of autowiredFields) {
2298
1950
  const autowiredMetadatas = application.metadataRepository.listFieldKindMetadata(targetDefinition.cls, field, Autowired);
@@ -2436,17 +2088,17 @@ class Application {
2436
2088
  this.propertiesConfig = new PropertiesConfig(jsonConfig);
2437
2089
  }
2438
2090
  /**
2439
- * 在项目中,所以的组件都已经收集到coco/index里面了,所以不需要进行组件收集;
2440
- * 在测试时,组件是在执行到对应的行装饰器才会执行,所以需要先收集在启动。
2091
+ * 应用模块在 start 前完成 AOT 注册;测试中的局部类可能在 Application 构造后才注册,
2092
+ * 因此 start 时统一解析注册表。
2441
2093
  */
2442
2094
  start() {
2443
- initDecoratorParamModule();
2444
- // 用装饰器参数初始化元数据数据
2095
+ const runtimeDecoratorParams = initDecoratorParamModule();
2096
+ // 使用 AOT 解析完成的装饰器参数(runtimeDecoratorParams)初始化元数据仓库
2445
2097
  const {
2446
2098
  metadataRepository,
2447
2099
  idClassMap,
2448
2100
  componentMetadataClass
2449
- } = initMetadataModule(getDecoratorParam());
2101
+ } = initMetadataModule(runtimeDecoratorParams);
2450
2102
  this.metadataRepository = metadataRepository;
2451
2103
  this.idClassMap = idClassMap;
2452
2104
  this.componentMetadataClass = componentMetadataClass;
@@ -2509,23 +2161,18 @@ class Application {
2509
2161
  }
2510
2162
  }
2511
2163
 
2512
- let _initClass$q;
2513
2164
  /**
2514
2165
  * @public
2515
2166
  */
2516
- let _Bind;
2517
- new class extends _identity {
2518
- static [class Bind extends Metadata {
2519
- static {
2520
- [_Bind, _initClass$q] = _applyDecs2311(this, [target([Target.Type.Method])], [], 0, void 0, Metadata).c;
2521
- }
2522
- }];
2523
- $$id = "Bind";
2524
- constructor() {
2525
- super(_Bind), _initClass$q();
2526
- }
2527
- }();
2528
- var Bind = _Bind;
2167
+ class Bind extends Metadata {
2168
+ static $$id = "Bind";
2169
+ }
2170
+ registerComponent(Bind, [{
2171
+ metadataKind: "class",
2172
+ metadataClass: target.$$metadataClass,
2173
+ metadataParam: [Target.Type.Method],
2174
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2175
+ }]);
2529
2176
 
2530
2177
  var bind = createDecoratorExp(Bind, {
2531
2178
  componentPostConstruct: function (metadata, application, target) {
@@ -2536,23 +2183,23 @@ var bind = createDecoratorExp(Bind, {
2536
2183
  }
2537
2184
  });
2538
2185
 
2539
- let _initClass$p;
2540
2186
  /**
2541
2187
  * @public
2542
2188
  */
2543
- let _Cookie;
2544
- new class extends _identity {
2545
- static [class Cookie extends Metadata {
2546
- static {
2547
- [_Cookie, _initClass$p] = _applyDecs2311(this, [target([Target.Type.Class]), component()], [], 0, void 0, Metadata).c;
2548
- }
2549
- }];
2550
- $$id = "Cookie";
2551
- constructor() {
2552
- super(_Cookie), _initClass$p();
2553
- }
2554
- }();
2555
- var Cookie = _Cookie;
2189
+ class Cookie extends Metadata {
2190
+ static $$id = "Cookie";
2191
+ }
2192
+ registerComponent(Cookie, [{
2193
+ metadataKind: "class",
2194
+ metadataClass: component.$$metadataClass,
2195
+ metadataParam: undefined,
2196
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
2197
+ }, {
2198
+ metadataKind: "class",
2199
+ metadataClass: target.$$metadataClass,
2200
+ metadataParam: [Target.Type.Class],
2201
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2202
+ }]);
2556
2203
 
2557
2204
  var cookie = createDecoratorExp(Cookie);
2558
2205
 
@@ -2743,7 +2390,6 @@ function mapChildren(children, func, context) {
2743
2390
  function forEachChildren(children, forEachFunc, forEachContext) {
2744
2391
  mapChildren(children, function () {
2745
2392
  forEachFunc.apply(this, arguments);
2746
- // Don't return anything.
2747
2393
  }, forEachContext);
2748
2394
  }
2749
2395
 
@@ -2791,117 +2437,113 @@ const Children = {
2791
2437
  forEach: forEachChildren,
2792
2438
  };
2793
2439
 
2794
- let _initClass$o;
2795
2440
  /**
2796
2441
  * @public
2797
2442
  */
2798
- let _View;
2799
- new class extends _identity {
2800
- static [class View extends Metadata {
2801
- static {
2802
- [_View, _initClass$o] = _applyDecs2311(this, [target([Target.Type.Class]), scope(exports.SCOPE.Prototype), component()], [], 0, void 0, Metadata).c;
2803
- }
2804
- // 当@view作为类装饰时,下面的函数将修改被装饰器的prototype
2805
- // TODO: View的复合装饰器也要支持的吧
2806
- static classDecoratorModifyPrototype(prototype) {
2807
- if (!prototype) {
2808
- prototype.updater = ReactNoopUpdateQueue;
2809
- }
2443
+ class View extends Metadata {
2444
+ static $$id = "View";
2445
+ }
2446
+ registerComponent(View, [{
2447
+ metadataKind: "class",
2448
+ metadataClass: component.$$metadataClass,
2449
+ metadataParam: undefined,
2450
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
2451
+ }, {
2452
+ metadataKind: "class",
2453
+ metadataClass: scope.$$metadataClass,
2454
+ metadataParam: exports.SCOPE.Prototype,
2455
+ isPlaceholderDecoratorExp: scope.$$isPlaceholderDecoratorExp
2456
+ }, {
2457
+ metadataKind: "class",
2458
+ metadataClass: target.$$metadataClass,
2459
+ metadataParam: [Target.Type.Class],
2460
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2461
+ }]);
2462
+
2463
+ var view = createDecoratorExp(View, {
2464
+ // 当@view作为类装饰时,实例化后给组件实例挂载updater,用于触发调度器
2465
+ // TODO: View的复合装饰器也要支持的吧
2466
+ componentPostConstruct() {
2467
+ if (!this.updater) {
2468
+ this.updater = ReactNoopUpdateQueue;
2810
2469
  }
2811
- }];
2812
- $$id = "View";
2813
- constructor() {
2814
- super(_View), _initClass$o();
2815
2470
  }
2816
- }();
2817
- var View = _View;
2818
-
2819
- var view = createDecoratorExp(View);
2471
+ });
2820
2472
 
2821
- let _initClass$n;
2822
2473
  /**
2823
2474
  * @public
2824
2475
  */
2825
- let _Layout;
2826
- new class extends _identity {
2827
- static [class Layout extends Metadata {
2828
- static {
2829
- [_Layout, _initClass$n] = _applyDecs2311(this, [target([Target.Type.Class]), view()], [], 0, void 0, Metadata).c;
2830
- }
2831
- }];
2832
- $$id = "Layout";
2833
- constructor() {
2834
- super(_Layout), _initClass$n();
2835
- }
2836
- }();
2837
- var Layout = _Layout;
2476
+ class Layout extends Metadata {
2477
+ static $$id = "Layout";
2478
+ }
2479
+ registerComponent(Layout, [{
2480
+ metadataKind: "class",
2481
+ metadataClass: view.$$metadataClass,
2482
+ metadataParam: undefined,
2483
+ isPlaceholderDecoratorExp: view.$$isPlaceholderDecoratorExp
2484
+ }, {
2485
+ metadataKind: "class",
2486
+ metadataClass: target.$$metadataClass,
2487
+ metadataParam: [Target.Type.Class],
2488
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2489
+ }]);
2838
2490
 
2839
2491
  var layout = createDecoratorExp(Layout);
2840
2492
 
2841
- let _initClass$m;
2842
2493
  /**
2843
2494
  * @public
2844
2495
  */
2845
- let _LocalStorage$1;
2846
- new class extends _identity {
2847
- static [class LocalStorage extends Metadata {
2848
- static {
2849
- [_LocalStorage$1, _initClass$m] = _applyDecs2311(this, [target([Target.Type.Class]), component()], [], 0, void 0, Metadata).c;
2850
- }
2851
- }];
2852
- $$id = "LocalStorage";
2853
- constructor() {
2854
- super(_LocalStorage$1), _initClass$m();
2855
- }
2856
- }();
2857
- var LocalStorage = _LocalStorage$1;
2496
+ let LocalStorage$1 = class LocalStorage extends Metadata {
2497
+ static $$id = "LocalStorage";
2498
+ };
2499
+ registerComponent(LocalStorage$1, [{
2500
+ metadataKind: "class",
2501
+ metadataClass: component.$$metadataClass,
2502
+ metadataParam: undefined,
2503
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
2504
+ }, {
2505
+ metadataKind: "class",
2506
+ metadataClass: target.$$metadataClass,
2507
+ metadataParam: [Target.Type.Class],
2508
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2509
+ }]);
2858
2510
 
2859
- var localStorageDecorator = createDecoratorExp(LocalStorage);
2511
+ var localStorageDecorator = createDecoratorExp(LocalStorage$1);
2860
2512
 
2861
- let _initClass$l;
2862
- let _LocalStorage;
2863
- new class extends _identity {
2864
- static [class LocalStorage {
2865
- static {
2866
- [_LocalStorage, _initClass$l] = _applyDecs2311(this, [localStorageDecorator()], []).c;
2867
- }
2868
- setItem(key, value) {
2869
- return localStorage.setItem(key, value);
2870
- }
2871
- getItem(key) {
2872
- return localStorage.getItem(key);
2873
- }
2874
- removeItem(key) {
2875
- return localStorage.removeItem(key);
2876
- }
2877
- key(index) {
2878
- return localStorage.key(index);
2879
- }
2880
- }];
2881
- $$id = "LocalStorage";
2882
- constructor() {
2883
- super(_LocalStorage), _initClass$l();
2513
+ class LocalStorage {
2514
+ static $$id = "LocalStorage";
2515
+ setItem(key, value) {
2516
+ return localStorage.setItem(key, value);
2884
2517
  }
2885
- }();
2886
- var _LocalStorage_default = _LocalStorage;
2518
+ getItem(key) {
2519
+ return localStorage.getItem(key);
2520
+ }
2521
+ removeItem(key) {
2522
+ return localStorage.removeItem(key);
2523
+ }
2524
+ key(index) {
2525
+ return localStorage.key(index);
2526
+ }
2527
+ }
2528
+ registerComponent(LocalStorage, [{
2529
+ metadataKind: "class",
2530
+ metadataClass: localStorageDecorator.$$metadataClass,
2531
+ metadataParam: undefined,
2532
+ isPlaceholderDecoratorExp: localStorageDecorator.$$isPlaceholderDecoratorExp
2533
+ }]);
2887
2534
 
2888
- let _initClass$k;
2889
2535
  /**
2890
2536
  * @public
2891
2537
  */
2892
- let _Memoized;
2893
- new class extends _identity {
2894
- static [class Memoized extends Metadata {
2895
- static {
2896
- [_Memoized, _initClass$k] = _applyDecs2311(this, [target([Target.Type.Method, Target.Type.Field, Target.Type.Getter])], [], 0, void 0, Metadata).c;
2897
- }
2898
- }];
2899
- $$id = "Memoized";
2900
- constructor() {
2901
- super(_Memoized), _initClass$k();
2902
- }
2903
- }();
2904
- var Memoized = _Memoized;
2538
+ class Memoized extends Metadata {
2539
+ static $$id = "Memoized";
2540
+ }
2541
+ registerComponent(Memoized, [{
2542
+ metadataKind: "class",
2543
+ metadataClass: target.$$metadataClass,
2544
+ metadataParam: [Target.Type.Method, Target.Type.Field, Target.Type.Getter],
2545
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2546
+ }]);
2905
2547
 
2906
2548
  class Subscriber {
2907
2549
  static Executing;
@@ -2975,7 +2617,7 @@ var memoized = createDecoratorExp(Memoized, {
2975
2617
  const descriptor = Object.getOwnPropertyDescriptor(this.constructor.prototype, name);
2976
2618
  const getter = descriptor?.get;
2977
2619
  if (typeof getter !== 'function') {
2978
- console.error("不应该拿不到getter函数");
2620
+ console.error('不应该拿不到getter函数');
2979
2621
  return;
2980
2622
  }
2981
2623
  const subscriber = new Subscriber(getter.bind(this));
@@ -2988,45 +2630,40 @@ var memoized = createDecoratorExp(Memoized, {
2988
2630
  }
2989
2631
  });
2990
2632
 
2991
- let _initClass$j;
2992
2633
  /**
2993
2634
  * @public
2994
2635
  */
2995
- let _Page;
2996
- new class extends _identity {
2997
- static [class Page extends Metadata {
2998
- static {
2999
- [_Page, _initClass$j] = _applyDecs2311(this, [target([Target.Type.Class]), view()], [], 0, void 0, Metadata).c;
3000
- }
3001
- }];
3002
- $$id = "Page";
3003
- constructor() {
3004
- super(_Page), _initClass$j();
3005
- }
3006
- }();
3007
- var Page = _Page;
2636
+ class Page extends Metadata {
2637
+ static $$id = "Page";
2638
+ }
2639
+ registerComponent(Page, [{
2640
+ metadataKind: "class",
2641
+ metadataClass: view.$$metadataClass,
2642
+ metadataParam: undefined,
2643
+ isPlaceholderDecoratorExp: view.$$isPlaceholderDecoratorExp
2644
+ }, {
2645
+ metadataKind: "class",
2646
+ metadataClass: target.$$metadataClass,
2647
+ metadataParam: [Target.Type.Class],
2648
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2649
+ }]);
3008
2650
 
3009
2651
  var page = createDecoratorExp(Page);
3010
2652
 
3011
- let _initClass$i;
3012
2653
  /**
3013
2654
  * 加在field表明是响应式
3014
2655
  * 加在metadata上用于自定义reactive元数据
3015
2656
  * @public
3016
2657
  */
3017
- let _Reactive;
3018
- new class extends _identity {
3019
- static [class Reactive extends Metadata {
3020
- static {
3021
- [_Reactive, _initClass$i] = _applyDecs2311(this, [target([Target.Type.Field])], [], 0, void 0, Metadata).c;
3022
- }
3023
- }];
3024
- $$id = "Reactive";
3025
- constructor() {
3026
- super(_Reactive), _initClass$i();
3027
- }
3028
- }();
3029
- var Reactive = _Reactive;
2658
+ class Reactive extends Metadata {
2659
+ static $$id = "Reactive";
2660
+ }
2661
+ registerComponent(Reactive, [{
2662
+ metadataKind: "class",
2663
+ metadataClass: target.$$metadataClass,
2664
+ metadataParam: [Target.Type.Field],
2665
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2666
+ }]);
3030
2667
 
3031
2668
  class Publisher {
3032
2669
  name;
@@ -3103,23 +2740,18 @@ var reactive = createDecoratorExp(Reactive, {
3103
2740
  }
3104
2741
  });
3105
2742
 
3106
- let _initClass$h;
3107
2743
  /**
3108
2744
  * @public
3109
2745
  */
3110
- let _Ref;
3111
- new class extends _identity {
3112
- static [class Ref extends Metadata {
3113
- static {
3114
- [_Ref, _initClass$h] = _applyDecs2311(this, [target([Target.Type.Field])], [], 0, void 0, Metadata).c;
3115
- }
3116
- }];
3117
- $$id = "Ref";
3118
- constructor() {
3119
- super(_Ref), _initClass$h();
3120
- }
3121
- }();
3122
- var Ref$1 = _Ref;
2746
+ let Ref$1 = class Ref extends Metadata {
2747
+ static $$id = "Ref";
2748
+ };
2749
+ registerComponent(Ref$1, [{
2750
+ metadataKind: "class",
2751
+ metadataClass: target.$$metadataClass,
2752
+ metadataParam: [Target.Type.Field],
2753
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2754
+ }]);
3123
2755
 
3124
2756
  var ref = createDecoratorExp(Ref$1, {
3125
2757
  componentPostConstruct: function (metadata, application, target) {
@@ -3132,23 +2764,18 @@ var ref = createDecoratorExp(Ref$1, {
3132
2764
  }
3133
2765
  });
3134
2766
 
3135
- let _initClass$g;
3136
2767
  /**
3137
2768
  * @public
3138
2769
  */
3139
- let _Refs;
3140
- new class extends _identity {
3141
- static [class Refs extends Metadata {
3142
- static {
3143
- [_Refs, _initClass$g] = _applyDecs2311(this, [target([Target.Type.Field])], [], 0, void 0, Metadata).c;
3144
- }
3145
- }];
3146
- $$id = "Refs";
3147
- constructor() {
3148
- super(_Refs), _initClass$g();
3149
- }
3150
- }();
3151
- var Refs = _Refs;
2770
+ class Refs extends Metadata {
2771
+ static $$id = "Refs";
2772
+ }
2773
+ registerComponent(Refs, [{
2774
+ metadataKind: "class",
2775
+ metadataClass: target.$$metadataClass,
2776
+ metadataParam: [Target.Type.Field],
2777
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2778
+ }]);
3152
2779
 
3153
2780
  var refs = createDecoratorExp(Refs, {
3154
2781
  componentPostConstruct: function (metadata, application, target) {
@@ -3156,166 +2783,146 @@ var refs = createDecoratorExp(Refs, {
3156
2783
  }
3157
2784
  });
3158
2785
 
3159
- let _initClass$f;
3160
2786
  /**
3161
2787
  * @public
3162
2788
  */
3163
- let _SessionStorage$1;
3164
- new class extends _identity {
3165
- static [class SessionStorage extends Metadata {
3166
- static {
3167
- [_SessionStorage$1, _initClass$f] = _applyDecs2311(this, [target([Target.Type.Class]), component()], [], 0, void 0, Metadata).c;
3168
- }
3169
- }];
3170
- $$id = "SessionStorage";
3171
- constructor() {
3172
- super(_SessionStorage$1), _initClass$f();
3173
- }
3174
- }();
3175
- var SessionStorage = _SessionStorage$1;
2789
+ let SessionStorage$1 = class SessionStorage extends Metadata {
2790
+ static $$id = "SessionStorage";
2791
+ };
2792
+ registerComponent(SessionStorage$1, [{
2793
+ metadataKind: "class",
2794
+ metadataClass: component.$$metadataClass,
2795
+ metadataParam: undefined,
2796
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
2797
+ }, {
2798
+ metadataKind: "class",
2799
+ metadataClass: target.$$metadataClass,
2800
+ metadataParam: [Target.Type.Class],
2801
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2802
+ }]);
3176
2803
 
3177
- var sessionStorageDecorator = createDecoratorExp(SessionStorage);
2804
+ var sessionStorageDecorator = createDecoratorExp(SessionStorage$1);
3178
2805
 
3179
- let _initClass$e;
3180
- let _SessionStorage;
3181
- new class extends _identity {
3182
- static [class SessionStorage {
3183
- static {
3184
- [_SessionStorage, _initClass$e] = _applyDecs2311(this, [sessionStorageDecorator()], []).c;
3185
- }
3186
- setItem(key, value) {
3187
- return sessionStorage.setItem(key, value);
3188
- }
3189
- getItem(key) {
3190
- return sessionStorage.getItem(key);
3191
- }
3192
- removeItem(key) {
3193
- return sessionStorage.removeItem(key);
3194
- }
3195
- key(index) {
3196
- return sessionStorage.key(index);
3197
- }
3198
- }];
3199
- $$id = "SessionStorage";
3200
- constructor() {
3201
- super(_SessionStorage), _initClass$e();
2806
+ class SessionStorage {
2807
+ static $$id = "SessionStorage";
2808
+ setItem(key, value) {
2809
+ return sessionStorage.setItem(key, value);
2810
+ }
2811
+ getItem(key) {
2812
+ return sessionStorage.getItem(key);
3202
2813
  }
3203
- }();
3204
- var _SessionStorage_default = _SessionStorage;
2814
+ removeItem(key) {
2815
+ return sessionStorage.removeItem(key);
2816
+ }
2817
+ key(index) {
2818
+ return sessionStorage.key(index);
2819
+ }
2820
+ }
2821
+ registerComponent(SessionStorage, [{
2822
+ metadataKind: "class",
2823
+ metadataClass: sessionStorageDecorator.$$metadataClass,
2824
+ metadataParam: undefined,
2825
+ isPlaceholderDecoratorExp: sessionStorageDecorator.$$isPlaceholderDecoratorExp
2826
+ }]);
3205
2827
 
3206
- let _initClass$d;
3207
2828
  /**
3208
2829
  * @public
3209
2830
  */
3210
- let _Store;
3211
- new class extends _identity {
3212
- static [class Store extends Metadata {
3213
- static {
3214
- [_Store, _initClass$d] = _applyDecs2311(this, [target([Target.Type.Class]), component()], [], 0, void 0, Metadata).c;
3215
- }
3216
- }];
3217
- $$id = "Store";
3218
- constructor() {
3219
- super(_Store), _initClass$d();
3220
- }
3221
- }();
3222
- var Store = _Store;
2831
+ class Store extends Metadata {
2832
+ static $$id = "Store";
2833
+ }
2834
+ registerComponent(Store, [{
2835
+ metadataKind: "class",
2836
+ metadataClass: component.$$metadataClass,
2837
+ metadataParam: undefined,
2838
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
2839
+ }, {
2840
+ metadataKind: "class",
2841
+ metadataClass: target.$$metadataClass,
2842
+ metadataParam: [Target.Type.Class],
2843
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2844
+ }]);
3223
2845
 
3224
2846
  var store = createDecoratorExp(Store);
3225
2847
 
3226
- let _initClass$c;
3227
- let _Router$1;
3228
- new class extends _identity {
3229
- static [class Router extends Metadata {
3230
- static {
3231
- [_Router$1, _initClass$c] = _applyDecs2311(this, [target([Target.Type.Class]), component()], [], 0, void 0, Metadata).c;
3232
- }
3233
- }];
3234
- $$id = "Router";
3235
- constructor() {
3236
- super(_Router$1), _initClass$c();
3237
- }
3238
- }();
3239
- var Router$1 = _Router$1;
2848
+ let Router$1 = class Router extends Metadata {
2849
+ static $$id = "Router";
2850
+ };
2851
+ registerComponent(Router$1, [{
2852
+ metadataKind: "class",
2853
+ metadataClass: component.$$metadataClass,
2854
+ metadataParam: undefined,
2855
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
2856
+ }, {
2857
+ metadataKind: "class",
2858
+ metadataClass: target.$$metadataClass,
2859
+ metadataParam: [Target.Type.Class],
2860
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2861
+ }]);
3240
2862
 
3241
- let _initClass$b;
3242
2863
  /**
3243
2864
  * @public
3244
2865
  */
3245
- let _Route$1;
3246
- new class extends _identity {
3247
- static [class Route extends Metadata {
3248
- static {
3249
- [_Route$1, _initClass$b] = _applyDecs2311(this, [target([Target.Type.Class])], [], 0, void 0, Metadata).c;
3250
- }
3251
- value;
3252
- }];
3253
- $$id = "Route";
3254
- constructor() {
3255
- super(_Route$1), _initClass$b();
3256
- }
3257
- }();
3258
- var RouteMeta = _Route$1;
2866
+ let Route$1 = class Route extends Metadata {
2867
+ static $$id = "Route";
2868
+ value;
2869
+ };
2870
+ registerComponent(Route$1, [{
2871
+ metadataKind: "class",
2872
+ metadataClass: target.$$metadataClass,
2873
+ metadataParam: [Target.Type.Class],
2874
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2875
+ }]);
3259
2876
 
3260
- var route = createDecoratorExp(RouteMeta);
2877
+ var route = createDecoratorExp(Route$1);
3261
2878
 
3262
2879
  var router = createDecoratorExp(Router$1);
3263
2880
 
3264
- let _initClass$a;
3265
2881
  /**
3266
2882
  * @public
3267
2883
  */
3268
- let _Router;
3269
- new class extends _identity {
3270
- static [class Router {
3271
- static {
3272
- [_Router, _initClass$a] = _applyDecs2311(this, [router()], []).c;
3273
- }
3274
- route;
3275
- render;
3276
- routeComponentMapper;
3277
- }];
3278
- $$id = "Router";
3279
- constructor() {
3280
- super(_Router), _initClass$a();
3281
- }
3282
- }();
3283
- var Router = _Router;
3284
-
3285
- let _initClass$9;
3286
- let _Render$1;
3287
- new class extends _identity {
3288
- static [class Render extends Metadata {
3289
- static {
3290
- [_Render$1, _initClass$9] = _applyDecs2311(this, [target([Target.Type.Class]), component()], [], 0, void 0, Metadata).c;
3291
- }
3292
- }];
3293
- $$id = "Render";
3294
- constructor() {
3295
- super(_Render$1), _initClass$9();
3296
- }
3297
- }();
3298
- var Render$1 = _Render$1;
2884
+ class Router {
2885
+ static $$id = "Router";
2886
+ route;
2887
+ render;
2888
+ routeComponentMapper;
2889
+ }
2890
+ registerComponent(Router, [{
2891
+ metadataKind: "class",
2892
+ metadataClass: router.$$metadataClass,
2893
+ metadataParam: undefined,
2894
+ isPlaceholderDecoratorExp: router.$$isPlaceholderDecoratorExp
2895
+ }]);
2896
+
2897
+ let Render$1 = class Render extends Metadata {
2898
+ static $$id = "Render";
2899
+ };
2900
+ registerComponent(Render$1, [{
2901
+ metadataKind: "class",
2902
+ metadataClass: component.$$metadataClass,
2903
+ metadataParam: undefined,
2904
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
2905
+ }, {
2906
+ metadataKind: "class",
2907
+ metadataClass: target.$$metadataClass,
2908
+ metadataParam: [Target.Type.Class],
2909
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
2910
+ }]);
3299
2911
 
3300
2912
  var render$1 = createDecoratorExp(Render$1);
3301
2913
 
3302
- let _initClass$8;
3303
2914
  /**
3304
2915
  * @public
3305
2916
  */
3306
- let _Render;
3307
- new class extends _identity {
3308
- static [class Render {
3309
- static {
3310
- [_Render, _initClass$8] = _applyDecs2311(this, [render$1()], []).c;
3311
- }
3312
- }];
3313
- $$id = "Render";
3314
- constructor() {
3315
- super(_Render), _initClass$8();
3316
- }
3317
- }();
3318
- var Render = _Render;
2917
+ class Render {
2918
+ static $$id = "Render";
2919
+ }
2920
+ registerComponent(Render, [{
2921
+ metadataKind: "class",
2922
+ metadataClass: render$1.$$metadataClass,
2923
+ metadataParam: undefined,
2924
+ isPlaceholderDecoratorExp: render$1.$$isPlaceholderDecoratorExp
2925
+ }]);
3319
2926
 
3320
2927
  /**
3321
2928
  * Mapping from registration name to event name
@@ -3324,7 +2931,6 @@ const registrationNameDependencies = {};
3324
2931
  const allNativeEvents = new Set();
3325
2932
  function registerTwoPhaseEvent(registrationName, dependencies) {
3326
2933
  registerDirectEvent(registrationName, dependencies);
3327
- // registerDirectEvent(registrationName + 'Capture', dependencies);
3328
2934
  }
3329
2935
  function registerDirectEvent(registrationName, dependencies) {
3330
2936
  registrationNameDependencies[registrationName] = dependencies;
@@ -4784,7 +4390,6 @@ function executeDispatch(domEvent, listener, currentTarget, reactEventType) {
4784
4390
  domEvent.stopPropagation();
4785
4391
  },
4786
4392
  });
4787
- // domEvent.currentTarget = null;
4788
4393
  }
4789
4394
  function processDispatchQueueItemsInOrder(domEvent, dispatchListeners, inCapturePhase, reactEventType) {
4790
4395
  if (inCapturePhase) {
@@ -6349,7 +5954,9 @@ function initProps(instance, newProps) {
6349
5954
  continue;
6350
5955
  }
6351
5956
  _values[field] = newProps[field];
6352
- definePublisher(instance.props, field, function getter() { return _values[field]; }, function setter(object, key, newValue) {
5957
+ definePublisher(instance.props, field, function getter() {
5958
+ return _values[field];
5959
+ }, function setter(object, key, newValue) {
6353
5960
  _values[field] = newValue;
6354
5961
  });
6355
5962
  }
@@ -6401,7 +6008,7 @@ const storeComponentUpdater = {
6401
6008
  scheduleUpdateOnFiber(root, viewComponentFiber, viewInstance);
6402
6009
  }
6403
6010
  }
6404
- }
6011
+ },
6405
6012
  };
6406
6013
  function reactiveStoreField(ctor, viewComponent) {
6407
6014
  const { application } = getCommonApi();
@@ -6420,7 +6027,7 @@ function reactiveStoreField(ctor, viewComponent) {
6420
6027
  },
6421
6028
  set() {
6422
6029
  console.error('store实例在初始化之后不允许修改');
6423
- }
6030
+ },
6424
6031
  });
6425
6032
  }
6426
6033
  });
@@ -6974,7 +6581,6 @@ function insertOrAppendPlacementNodeIntoContainer(node, before, parent) {
6974
6581
  sibling = sibling.sibling;
6975
6582
  }
6976
6583
  }
6977
- // throw new Error('todo')
6978
6584
  }
6979
6585
  }
6980
6586
  function detachFiberMutation(fiber) {
@@ -7145,7 +6751,6 @@ function commitMutationEffectsOnFiber(finishedWork, root) {
7145
6751
  resetTextContent(instance);
7146
6752
  }
7147
6753
  catch (error) {
7148
- // todo captureCommitPhaseError(finishedWork, finishedWork.return, error);
7149
6754
  }
7150
6755
  }
7151
6756
  if (flags & Update) {
@@ -7833,34 +7438,29 @@ function render(element, container) {
7833
7438
  return legacyRenderSubtreeIntoContainer(null, element, container);
7834
7439
  }
7835
7440
 
7836
- let _initClass$7;
7837
7441
  /**
7838
7442
  * @public
7839
7443
  */
7840
- let _WebRender;
7841
- new class extends _identity {
7842
- static [class WebRender extends Render {
7843
- static {
7844
- [_WebRender, _initClass$7] = _applyDecs2311(this, [render$1()], [], 0, void 0, Render).c;
7845
- }
7846
- container;
7847
- init(application) {
7848
- registerCommonApi(application);
7849
- this.container = document.getElementById('root');
7850
- if (!this.container) {
7851
- console.error('未找到根节点');
7852
- }
7853
- }
7854
- render(component) {
7855
- return render(jsx(component, undefined), this.container);
7444
+ class WebRender extends Render {
7445
+ static $$id = "WebRender";
7446
+ container;
7447
+ init(application) {
7448
+ registerCommonApi(application);
7449
+ this.container = document.getElementById('root');
7450
+ if (!this.container) {
7451
+ console.error('未找到根节点');
7856
7452
  }
7857
- }];
7858
- $$id = "WebRender";
7859
- constructor() {
7860
- super(_WebRender), _initClass$7();
7861
7453
  }
7862
- }();
7863
- var _WebRender_default = _WebRender;
7454
+ render(component) {
7455
+ return render(jsx(component, undefined), this.container);
7456
+ }
7457
+ }
7458
+ registerComponent(WebRender, [{
7459
+ metadataKind: "class",
7460
+ metadataClass: render$1.$$metadataClass,
7461
+ metadataParam: undefined,
7462
+ isPlaceholderDecoratorExp: render$1.$$isPlaceholderDecoratorExp
7463
+ }]);
7864
7464
 
7865
7465
  class DynamicRoute {
7866
7466
  regExp;
@@ -7943,175 +7543,175 @@ class RouteComponentMapper {
7943
7543
  }
7944
7544
  }
7945
7545
 
7946
- let _initClass$6;
7947
- let _Route;
7948
- new class extends _identity {
7949
- static [class Route {
7950
- static {
7951
- [_Route, _initClass$6] = _applyDecs2311(this, [component()], []).c;
7952
- }
7953
- // window.location.pathname
7954
- pathname;
7955
- // 动态路由参数
7956
- params = {};
7957
- }];
7958
- $$id = "Route";
7959
- constructor() {
7960
- super(_Route), _initClass$6();
7961
- }
7962
- }();
7963
- var Route = _Route;
7546
+ class Route {
7547
+ static $$id = "Route";
7548
+ // window.location.pathname
7549
+ pathname;
7550
+ // 动态路由参数
7551
+ params = {};
7552
+ }
7553
+ registerComponent(Route, [{
7554
+ metadataKind: "class",
7555
+ metadataClass: component.$$metadataClass,
7556
+ metadataParam: undefined,
7557
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
7558
+ }]);
7964
7559
 
7965
- let _initClass$5;
7966
7560
  /**
7967
7561
  * @public
7968
7562
  */
7969
- let _HistoryRouter;
7970
- new class extends _identity {
7971
- static [class HistoryRouter extends Router {
7972
- static {
7973
- [_HistoryRouter, _initClass$5] = _applyDecs2311(this, [router(), constructorInject([Render])], [], 0, void 0, Router).c;
7974
- }
7975
- constructor(render) {
7976
- super();
7977
- this.render = render;
7978
- }
7979
- handleRouteChange = () => {
7980
- const pathname = window.location.pathname;
7981
- const {
7982
- pageComponent,
7983
- params
7984
- } = this.routeComponentMapper.match(pathname);
7985
- this.route.pathname = pathname;
7986
- this.route.params = params || {};
7987
- if (pageComponent) {
7988
- this.render.render(pageComponent);
7989
- }
7990
- };
7991
- init(application) {
7992
- const routeComponentMap = application.listBeDecoratedClsByClassKindMetadata(RouteMeta);
7993
- this.routeComponentMapper = new RouteComponentMapper();
7994
- this.routeComponentMapper.init(routeComponentMap);
7995
- this.route = application.getComponent(Route);
7996
- }
7997
- start() {
7998
- window.addEventListener('popstate', this.handleRouteChange);
7999
- // 初始化渲染
8000
- this.handleRouteChange();
8001
- }
8002
- removeListener() {
8003
- window.removeEventListener('popstate', this.handleRouteChange);
8004
- }
8005
- navigateTo(url) {
8006
- window.history.pushState({}, '', url);
8007
- this.handleRouteChange();
7563
+ class HistoryRouter extends Router {
7564
+ static $$id = "HistoryRouter";
7565
+ constructor(render) {
7566
+ super();
7567
+ this.render = render;
7568
+ }
7569
+ handleRouteChange = () => {
7570
+ const pathname = window.location.pathname;
7571
+ const {
7572
+ pageComponent,
7573
+ params
7574
+ } = this.routeComponentMapper.match(pathname);
7575
+ this.route.pathname = pathname;
7576
+ this.route.params = params || {};
7577
+ if (pageComponent) {
7578
+ this.render.render(pageComponent);
8008
7579
  }
8009
- }];
8010
- $$id = "HistoryRouter";
8011
- constructor() {
8012
- super(_HistoryRouter), _initClass$5();
7580
+ };
7581
+ init(application) {
7582
+ const routeComponentMap = application.listBeDecoratedClsByClassKindMetadata(Route$1);
7583
+ this.routeComponentMapper = new RouteComponentMapper();
7584
+ this.routeComponentMapper.init(routeComponentMap);
7585
+ this.route = application.getComponent(Route);
7586
+ }
7587
+ start() {
7588
+ window.addEventListener('popstate', this.handleRouteChange);
7589
+ // 初始化渲染
7590
+ this.handleRouteChange();
7591
+ }
7592
+ removeListener() {
7593
+ window.removeEventListener('popstate', this.handleRouteChange);
7594
+ }
7595
+ navigateTo(url) {
7596
+ window.history.pushState({}, '', url);
7597
+ this.handleRouteChange();
8013
7598
  }
8014
- }();
8015
- var _HistoryRouter_default = _HistoryRouter;
7599
+ }
7600
+ registerComponent(HistoryRouter, [{
7601
+ metadataKind: "class",
7602
+ metadataClass: constructorInject.$$metadataClass,
7603
+ metadataParam: [Render],
7604
+ isPlaceholderDecoratorExp: constructorInject.$$isPlaceholderDecoratorExp
7605
+ }, {
7606
+ metadataKind: "class",
7607
+ metadataClass: router.$$metadataClass,
7608
+ metadataParam: undefined,
7609
+ isPlaceholderDecoratorExp: router.$$isPlaceholderDecoratorExp
7610
+ }]);
8016
7611
 
8017
- let _initClass$4;
8018
7612
  /**
8019
7613
  * @public
8020
7614
  */
8021
- let _Util;
8022
- new class extends _identity {
8023
- static [class Util extends Metadata {
8024
- static {
8025
- [_Util, _initClass$4] = _applyDecs2311(this, [target([Target.Type.Class]), component()], [], 0, void 0, Metadata).c;
8026
- }
8027
- }];
8028
- $$id = "Util";
8029
- constructor() {
8030
- super(_Util), _initClass$4();
8031
- }
8032
- }();
8033
- var Util = _Util;
7615
+ class Util extends Metadata {
7616
+ static $$id = "Util";
7617
+ }
7618
+ registerComponent(Util, [{
7619
+ metadataKind: "class",
7620
+ metadataClass: component.$$metadataClass,
7621
+ metadataParam: undefined,
7622
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
7623
+ }, {
7624
+ metadataKind: "class",
7625
+ metadataClass: target.$$metadataClass,
7626
+ metadataParam: [Target.Type.Class],
7627
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
7628
+ }]);
8034
7629
 
8035
7630
  var util = createDecoratorExp(Util);
8036
7631
 
8037
- let _initClass$3;
8038
7632
  /**
8039
7633
  * @public
8040
7634
  */
8041
- let _Api;
8042
- new class extends _identity {
8043
- static [class Api extends Metadata {
8044
- static {
8045
- [_Api, _initClass$3] = _applyDecs2311(this, [target([Target.Type.Class]), util()], [], 0, void 0, Metadata).c;
8046
- }
8047
- }];
8048
- $$id = "Api";
8049
- constructor() {
8050
- super(_Api), _initClass$3();
8051
- }
8052
- }();
8053
- var Api = _Api;
7635
+ class Api extends Metadata {
7636
+ static $$id = "Api";
7637
+ }
7638
+ registerComponent(Api, [{
7639
+ metadataKind: "class",
7640
+ metadataClass: util.$$metadataClass,
7641
+ metadataParam: undefined,
7642
+ isPlaceholderDecoratorExp: util.$$isPlaceholderDecoratorExp
7643
+ }, {
7644
+ metadataKind: "class",
7645
+ metadataClass: target.$$metadataClass,
7646
+ metadataParam: [Target.Type.Class],
7647
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
7648
+ }]);
8054
7649
 
8055
7650
  var api = createDecoratorExp(Api);
8056
7651
 
8057
- let _initClass$2;
8058
7652
  /**
8059
7653
  * @public
8060
7654
  */
8061
- let _Flow;
8062
- new class extends _identity {
8063
- static [class Flow extends Metadata {
8064
- static {
8065
- [_Flow, _initClass$2] = _applyDecs2311(this, [target([Target.Type.Class]), component(), scope(exports.SCOPE.Prototype)], [], 0, void 0, Metadata).c;
8066
- }
8067
- }];
8068
- $$id = "Flow";
8069
- constructor() {
8070
- super(_Flow), _initClass$2();
8071
- }
8072
- }();
8073
- var Flow = _Flow;
8074
-
8075
- var flow = createDecoratorExp(Flow);
7655
+ class Service extends Metadata {
7656
+ static $$id = "Service";
7657
+ }
7658
+ registerComponent(Service, [{
7659
+ metadataKind: "class",
7660
+ metadataClass: scope.$$metadataClass,
7661
+ metadataParam: exports.SCOPE.Prototype,
7662
+ isPlaceholderDecoratorExp: scope.$$isPlaceholderDecoratorExp
7663
+ }, {
7664
+ metadataKind: "class",
7665
+ metadataClass: component.$$metadataClass,
7666
+ metadataParam: undefined,
7667
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
7668
+ }, {
7669
+ metadataKind: "class",
7670
+ metadataClass: target.$$metadataClass,
7671
+ metadataParam: [Target.Type.Class],
7672
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
7673
+ }]);
7674
+
7675
+ var service = createDecoratorExp(Service);
8076
7676
 
8077
- let _initClass$1;
8078
7677
  // TODO: view 包添加 viewData装饰器
8079
7678
  /**
8080
7679
  * @public
8081
7680
  */
8082
- let _GlobalData;
8083
- new class extends _identity {
8084
- static [class GlobalData extends Metadata {
8085
- static {
8086
- [_GlobalData, _initClass$1] = _applyDecs2311(this, [target([Target.Type.Class]), component()], [], 0, void 0, Metadata).c;
8087
- }
8088
- }];
8089
- $$id = "GlobalData";
8090
- constructor() {
8091
- super(_GlobalData), _initClass$1();
8092
- }
8093
- }();
8094
- var GlobalData = _GlobalData;
7681
+ class GlobalData extends Metadata {
7682
+ static $$id = "GlobalData";
7683
+ }
7684
+ registerComponent(GlobalData, [{
7685
+ metadataKind: "class",
7686
+ metadataClass: component.$$metadataClass,
7687
+ metadataParam: undefined,
7688
+ isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
7689
+ }, {
7690
+ metadataKind: "class",
7691
+ metadataClass: target.$$metadataClass,
7692
+ metadataParam: [Target.Type.Class],
7693
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
7694
+ }]);
8095
7695
 
8096
7696
  var globalData = createDecoratorExp(GlobalData);
8097
7697
 
8098
- let _initClass;
8099
7698
  /**
8100
7699
  * @public
8101
7700
  */
8102
- let _WebApplication;
8103
- new class extends _identity {
8104
- static [class WebApplication extends Metadata {
8105
- static {
8106
- [_WebApplication, _initClass] = _applyDecs2311(this, [target([Target.Type.Class]), configuration()], [], 0, void 0, Metadata).c;
8107
- }
8108
- }];
8109
- $$id = "WebApplication";
8110
- constructor() {
8111
- super(_WebApplication), _initClass();
8112
- }
8113
- }();
8114
- var WebApplication = _WebApplication;
7701
+ class WebApplication extends Metadata {
7702
+ static $$id = "WebApplication";
7703
+ }
7704
+ registerComponent(WebApplication, [{
7705
+ metadataKind: "class",
7706
+ metadataClass: configuration.$$metadataClass,
7707
+ metadataParam: undefined,
7708
+ isPlaceholderDecoratorExp: configuration.$$isPlaceholderDecoratorExp
7709
+ }, {
7710
+ metadataKind: "class",
7711
+ metadataClass: target.$$metadataClass,
7712
+ metadataParam: [Target.Type.Class],
7713
+ isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
7714
+ }]);
8115
7715
 
8116
7716
  var webApplication = createDecoratorExp(WebApplication);
8117
7717
 
@@ -8124,16 +7724,15 @@ exports.Component = Component;
8124
7724
  exports.Configuration = Configuration;
8125
7725
  exports.ConstructorInject = ConstructorInject;
8126
7726
  exports.Cookie = Cookie;
8127
- exports.Flow = Flow;
8128
7727
  exports.GlobalData = GlobalData;
8129
- exports.HistoryRouter = _HistoryRouter_default;
7728
+ exports.HistoryRouter = HistoryRouter;
8130
7729
  exports.Id = Id;
8131
7730
  exports.KindClass = KindClass;
8132
7731
  exports.KindField = KindField;
8133
7732
  exports.KindMethod = KindMethod;
8134
7733
  exports.Layout = Layout;
8135
- exports.LocalStorage = _LocalStorage_default;
8136
- exports.LocalStorageMeta = LocalStorage;
7734
+ exports.LocalStorage = LocalStorage;
7735
+ exports.LocalStorageMeta = LocalStorage$1;
8137
7736
  exports.Memoized = Memoized;
8138
7737
  exports.Metadata = Metadata;
8139
7738
  exports.Page = Page;
@@ -8145,30 +7744,31 @@ exports.Ref = Ref$1;
8145
7744
  exports.Refs = Refs;
8146
7745
  exports.Render = Render;
8147
7746
  exports.Route = Route;
8148
- exports.RouteMeta = RouteMeta;
7747
+ exports.RouteMeta = Route$1;
8149
7748
  exports.Router = Router;
8150
7749
  exports.RouterMeta = Router$1;
8151
7750
  exports.Scope = Scope;
8152
- exports.SessionStorage = _SessionStorage_default;
8153
- exports.SessionStorageMeta = SessionStorage;
7751
+ exports.Service = Service;
7752
+ exports.SessionStorage = SessionStorage;
7753
+ exports.SessionStorageMeta = SessionStorage$1;
8154
7754
  exports.Store = Store;
8155
7755
  exports.Target = Target;
8156
7756
  exports.Util = Util;
8157
7757
  exports.Value = Value;
8158
7758
  exports.View = View;
8159
7759
  exports.WebApplication = WebApplication;
8160
- exports.WebRender = _WebRender_default;
7760
+ exports.WebRender = WebRender;
8161
7761
  exports.api = api;
8162
7762
  exports.autowired = autowired;
8163
7763
  exports.bind = bind;
7764
+ exports.bindPlaceholderMetadataClass = bindPlaceholderMetadataClass;
8164
7765
  exports.component = component;
8165
7766
  exports.configuration = configuration;
8166
7767
  exports.constructorInject = constructorInject;
8167
7768
  exports.cookie = cookie;
8168
7769
  exports.createDecoratorExp = createDecoratorExp;
8169
- exports.createPlaceholderDecoratorExp = createPlaceholderDecoratorExp;
8170
7770
  exports.definePublisher = definePublisher;
8171
- exports.flow = flow;
7771
+ exports.getRegistry = getRegistry;
8172
7772
  exports.globalData = globalData;
8173
7773
  exports.id = id;
8174
7774
  exports.jsx = jsx;
@@ -8176,13 +7776,16 @@ exports.jsxs = jsx;
8176
7776
  exports.layout = layout;
8177
7777
  exports.localStorage = localStorageDecorator;
8178
7778
  exports.memoized = memoized;
7779
+ exports.metadataFor = metadataFor;
8179
7780
  exports.page = page;
8180
7781
  exports.qualifier = qualifier;
8181
7782
  exports.reactive = reactive;
8182
7783
  exports.ref = ref;
8183
7784
  exports.refs = refs;
7785
+ exports.registerComponent = registerComponent;
8184
7786
  exports.route = route;
8185
7787
  exports.scope = scope;
7788
+ exports.service = service;
8186
7789
  exports.sessionStorage = sessionStorageDecorator;
8187
7790
  exports.store = store;
8188
7791
  exports.target = target;