@cocojs/mvc 0.1.0-beta.13 → 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/README.md +2 -2
- package/dist/index.cjs.js +908 -1258
- package/dist/index.d.ts +171 -90
- package/dist/index.esm.js +896 -1249
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -56,27 +56,6 @@ function isDescendantOf(s, p) {
|
|
|
56
56
|
}
|
|
57
57
|
return false;
|
|
58
58
|
}
|
|
59
|
-
/**
|
|
60
|
-
* 生成一个只能执行一次的函数
|
|
61
|
-
* @param fn
|
|
62
|
-
*/
|
|
63
|
-
function once(fn) {
|
|
64
|
-
let runTimes = 0;
|
|
65
|
-
const onceFn = THIS => {
|
|
66
|
-
if (onceFn.fn) {
|
|
67
|
-
if (runTimes === 0) {
|
|
68
|
-
runTimes++;
|
|
69
|
-
return onceFn.fn.call(THIS);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
onceFn.fn = fn;
|
|
74
|
-
return onceFn;
|
|
75
|
-
}
|
|
76
|
-
// 是否是普通类,因为class会转成function,所以不通过toString判断
|
|
77
|
-
function isClass(v) {
|
|
78
|
-
return typeof v === 'function' && v.prototype && v.prototype.constructor === v;
|
|
79
|
-
}
|
|
80
59
|
/**
|
|
81
60
|
* 在coco/mvc中是否是一个合法的类
|
|
82
61
|
* @param v
|
|
@@ -147,153 +126,72 @@ function instantiateMetadata(metadataCls, args) {
|
|
|
147
126
|
return metadata;
|
|
148
127
|
}
|
|
149
128
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if ("function" != typeof e && (r || void 0 !== e))
|
|
162
|
-
throw new TypeError(t + " must " + (n || "be") + " a function" + (r ? "" : " or undefined"));
|
|
163
|
-
return e;
|
|
164
|
-
}
|
|
165
|
-
function applyDec(e, t, n, r, o, i, u, s, f, l, p) {
|
|
166
|
-
function d(e) {
|
|
167
|
-
if (!p(e))
|
|
168
|
-
throw new TypeError("Attempted to access private element on non-instance");
|
|
169
|
-
}
|
|
170
|
-
var h = [].concat(t[0]), v = t[3], w = !u, D = 1 === o, S = 3 === o, j = 4 === o, E = 2 === o;
|
|
171
|
-
function I(t, n, r) {
|
|
172
|
-
return function (o, i) {
|
|
173
|
-
return n && (i = o, o = e), r && r(o), P[t].call(o, i);
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
if (!w) {
|
|
177
|
-
var P = {}, k = [], F = S ? "get" : j || D ? "set" : "value";
|
|
178
|
-
if (f ? (l || D ? P = {
|
|
179
|
-
get: _setFunctionName(function () {
|
|
180
|
-
return v(this);
|
|
181
|
-
}, r, "get"),
|
|
182
|
-
set: function (e) {
|
|
183
|
-
t[4](this, e);
|
|
184
|
-
}
|
|
185
|
-
} : P[F] = v, l || _setFunctionName(P[F], r, E ? "" : F)) : l || (P = Object.getOwnPropertyDescriptor(e, r)), !l && !f) {
|
|
186
|
-
if ((c = y[+s][r]) && 7 !== (c ^ o))
|
|
187
|
-
throw Error("Decorating two elements with the same name (" + P[F].name + ") is not supported yet");
|
|
188
|
-
y[+s][r] = o < 3 ? 1 : o;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
for (var N = e, O = h.length - 1; O >= 0; O -= n ? 2 : 1) {
|
|
192
|
-
var T = b(h[O], "A decorator", "be", true), z = n ? h[O - 1] : void 0, A = {}, H = {
|
|
193
|
-
kind: ["field", "accessor", "method", "getter", "setter", "class"][o],
|
|
194
|
-
name: r,
|
|
195
|
-
metadata: a,
|
|
196
|
-
addInitializer: function (e, t) {
|
|
197
|
-
if (e.v)
|
|
198
|
-
throw new TypeError("attempted to call addInitializer after decoration was finished");
|
|
199
|
-
b(t, "An initializer", "be", true), i.push(t);
|
|
200
|
-
}.bind(null, A)
|
|
201
|
-
};
|
|
202
|
-
if (w)
|
|
203
|
-
c = T.call(z, N, H), A.v = 1, b(c, "class decorators", "return") && (N = c);
|
|
204
|
-
else if (H.static = s, H.private = f, c = H.access = {
|
|
205
|
-
has: f ? p.bind() : function (e) {
|
|
206
|
-
return r in e;
|
|
207
|
-
}
|
|
208
|
-
}, j || (c.get = f ? E ? function (e) {
|
|
209
|
-
return d(e), P.value;
|
|
210
|
-
} : I("get", 0, d) : function (e) {
|
|
211
|
-
return e[r];
|
|
212
|
-
}), E || S || (c.set = f ? I("set", 0, d) : function (e, t) {
|
|
213
|
-
e[r] = t;
|
|
214
|
-
}), N = T.call(z, D ? {
|
|
215
|
-
get: P.get,
|
|
216
|
-
set: P.set
|
|
217
|
-
} : P[F], H), A.v = 1, D) {
|
|
218
|
-
if ("object" == typeof N && N)
|
|
219
|
-
(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);
|
|
220
|
-
else if (void 0 !== N)
|
|
221
|
-
throw new TypeError("accessor decorators must return an object with get, set, or init properties or undefined");
|
|
222
|
-
}
|
|
223
|
-
else
|
|
224
|
-
b(N, (l ? "field" : "method") + " decorators", "return") && (l ? k.unshift(N) : P[F] = N);
|
|
225
|
-
}
|
|
226
|
-
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;
|
|
227
|
-
}
|
|
228
|
-
function w(e) {
|
|
229
|
-
return m(e, d, {
|
|
230
|
-
configurable: true,
|
|
231
|
-
enumerable: true,
|
|
232
|
-
value: a
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
return void 0 !== i && (a = i[d]), a = h(null == a ? null : a), f = [], l = function (e) {
|
|
236
|
-
e && f.push(g(e));
|
|
237
|
-
}, p = function (t, r) {
|
|
238
|
-
for (var i = 0; i < n.length; i++) {
|
|
239
|
-
var a = n[i], c = a[1], l = 7 & c;
|
|
240
|
-
if ((8 & c) == t && !l == r) {
|
|
241
|
-
var p = a[2], d = !!a[3], m = 16 & c;
|
|
242
|
-
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) {
|
|
243
|
-
return _checkInRHS(t) === e;
|
|
244
|
-
} : o);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}, p(8, 0), p(0, 0), p(8, 1), p(0, 1), l(u), l(s), c = f, v || w(e), {
|
|
248
|
-
e: c,
|
|
249
|
-
get c() {
|
|
250
|
-
var n = [];
|
|
251
|
-
return v && [w(e = applyDec(e, [t], r, e.name, 5, n)), g(n, 1)];
|
|
252
|
-
}
|
|
253
|
-
};
|
|
129
|
+
/**
|
|
130
|
+
* 声明被装饰类是某个装饰器表达式的元数据类。
|
|
131
|
+
* 由 AOT 编译器转换为 bindPlaceholderMetadataClass 调用,不应在运行时执行。
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
function metadataFor(_decoratorExp) {
|
|
135
|
+
return function (_beDecoratedCls, _context) {
|
|
136
|
+
// metadataFor 正常应由 AOT 编译期转换为 bindPlaceholderMetadataClass 调用,
|
|
137
|
+
// 运行到这里说明代码未经 @cocojs/compiler 编译。
|
|
138
|
+
throw new Error('metadataFor 不应在运行时执行,请先使用 @cocojs/compiler 编译后再运行。');
|
|
139
|
+
};
|
|
254
140
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
141
|
+
|
|
142
|
+
const KindClass = 'class';
|
|
143
|
+
const KindField = 'field';
|
|
144
|
+
const KindMethod = 'method';
|
|
145
|
+
const KindGetter = 'getter';
|
|
146
|
+
|
|
147
|
+
// 与 AOT 注册表一样跨运行时模块实例共享,确保绑定方能读取创建方记录的选项
|
|
148
|
+
const decoratorOptionsKey = Symbol.for('coco.decoratorOptions');
|
|
149
|
+
const globalObject$1 = globalThis;
|
|
150
|
+
if (!globalObject$1[decoratorOptionsKey]) {
|
|
151
|
+
globalObject$1[decoratorOptionsKey] = {
|
|
152
|
+
metadata: new Map(),
|
|
153
|
+
placeholder: new Map(),
|
|
154
|
+
placeholderClassMap2RealMetadataClass: new Map()
|
|
155
|
+
};
|
|
259
156
|
}
|
|
260
|
-
|
|
261
|
-
|
|
157
|
+
// 元数据类 <--> 装饰器选项
|
|
158
|
+
const metadataDecoratorOptions = globalObject$1[decoratorOptionsKey].metadata;
|
|
159
|
+
// 占位的元数据类 <--> 装饰器选项
|
|
160
|
+
const placeholderDecoratorOptions = globalObject$1[decoratorOptionsKey].placeholder;
|
|
161
|
+
// 占位的元数据类 -> 真实的元数据类
|
|
162
|
+
const placeholderClassMap2RealMetadataClass = globalObject$1[decoratorOptionsKey].placeholderClassMap2RealMetadataClass;
|
|
163
|
+
// 记录创建装饰器表达式的选项
|
|
164
|
+
function addCreateDecoratorOption(isPlaceholderExp, metadataClass, options = null) {
|
|
165
|
+
if (isPlaceholderExp) {
|
|
166
|
+
// 是占位的元数据表达式,那么先临时记录到placeholderDecoratorOptions中,后续知道占位元数据类和真正的元数据类的映射关系后再保存到metadataDecoratorOptions中
|
|
167
|
+
placeholderDecoratorOptions.set(metadataClass, options);
|
|
168
|
+
} else {
|
|
169
|
+
// 不是占位的元数据表达式,那么直接保存在metadataDecoratorOptions中
|
|
170
|
+
metadataDecoratorOptions.set(metadataClass, options);
|
|
171
|
+
}
|
|
262
172
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
Object.defineProperty(e, "name", {
|
|
267
|
-
configurable: !0,
|
|
268
|
-
value: n ? n + " " + t : t
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
catch (e) { }
|
|
272
|
-
return e;
|
|
173
|
+
// 记录占位的元数据类和真实的元数据类之间的映射
|
|
174
|
+
function addPlaceholderClassToRealMetadataClassRelation(placeholderClass, realMetadataClass) {
|
|
175
|
+
placeholderClassMap2RealMetadataClass.set(placeholderClass, realMetadataClass);
|
|
273
176
|
}
|
|
274
|
-
function
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
var i = e.call(t, r);
|
|
280
|
-
if ("object" != typeof i)
|
|
281
|
-
return i;
|
|
282
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
177
|
+
function mergePlaceholderClass2RealMetadataClassRelation() {
|
|
178
|
+
for (const [placeholderClass, decoratorOptions] of placeholderDecoratorOptions.entries()) {
|
|
179
|
+
const realMetadataClass = placeholderClassMap2RealMetadataClass.get(placeholderClass);
|
|
180
|
+
if (realMetadataClass) {
|
|
181
|
+
addCreateDecoratorOption(false, realMetadataClass, decoratorOptions);
|
|
283
182
|
}
|
|
284
|
-
|
|
183
|
+
}
|
|
285
184
|
}
|
|
286
|
-
function
|
|
287
|
-
|
|
288
|
-
|
|
185
|
+
function getPlaceholderClassMap2RealMetadataClass() {
|
|
186
|
+
return placeholderClassMap2RealMetadataClass;
|
|
187
|
+
}
|
|
188
|
+
function getCreateDecoratorOption(metadataClass) {
|
|
189
|
+
return metadataDecoratorOptions.get(metadataClass);
|
|
190
|
+
}
|
|
191
|
+
function clear$1() {
|
|
192
|
+
metadataDecoratorOptions.clear();
|
|
193
|
+
placeholderDecoratorOptions.clear();
|
|
289
194
|
}
|
|
290
|
-
|
|
291
|
-
const KindClass = 'class';
|
|
292
|
-
const KindField = 'field';
|
|
293
|
-
const KindMethod = 'method';
|
|
294
|
-
const KindGetter = 'getter';
|
|
295
|
-
const KindSetter = 'setter';
|
|
296
|
-
const KindAccessor = 'accessor';
|
|
297
195
|
|
|
298
196
|
// TODO: 错误码按照类型划分不同的段位
|
|
299
197
|
var DiagnoseCode;
|
|
@@ -341,15 +239,15 @@ const DiagnoseCodeMsg = {
|
|
|
341
239
|
[DiagnoseCode.CO10010]: `实例化组件失败,%s 类存在多个子类 %s,@qualifier装饰器指定了一个不存在的子类id: %s`,
|
|
342
240
|
[DiagnoseCode.CO10011]: `实例化组件失败,%s 类不是ioc组件`,
|
|
343
241
|
[DiagnoseCode.CO10012]: `%s 类 %s 字段不能使用autowired注入自身,字段置为undefined`,
|
|
344
|
-
[DiagnoseCode.CO10013]:
|
|
242
|
+
[DiagnoseCode.CO10013]: `实例化组件失败,存在循环依赖: %s`,
|
|
345
243
|
[DiagnoseCode.CO10014]: `元数据类 %s 创建了不止一个装饰器,每个元数据类只能创建一个对应的装饰器。`,
|
|
346
244
|
[DiagnoseCode.CO10015]: `元数据类 %s 本身存在id属性,且不能被修改。`,
|
|
347
245
|
[DiagnoseCode.CO10016]: `元数据类 %s 没有id属性或者id属性不是字符串,忘记调用assignMetadataId方法?`,
|
|
348
246
|
[DiagnoseCode.CO10017]: `元数据类 %s 和 %s 的id属性相同,id属性不能重复。`,
|
|
349
247
|
[DiagnoseCode.CO10018]: `createDecoratorExp的第一个参数 %s 必须是Metadata的子类。`,
|
|
350
248
|
[DiagnoseCode.CO10019]: `框架暂不支持为 %s 添加装饰器。`,
|
|
351
|
-
[DiagnoseCode.CO10020]: `有一个占位装饰器没有使用
|
|
352
|
-
[DiagnoseCode.CO10021]: `%s 类存在一个占位装饰器,但是没有使用
|
|
249
|
+
[DiagnoseCode.CO10020]: `有一个占位装饰器没有使用metadataFor关联具体的元数据类,如果不使用的话,直接删除这个装饰器。`,
|
|
250
|
+
[DiagnoseCode.CO10021]: `%s 类存在一个占位装饰器,但是没有使用metadataFor装饰器关联真正的元数据类。`,
|
|
353
251
|
[DiagnoseCode.CO10022]: `元数据类 %s 只能有 KindClass 类型的装饰器,字段 %s 上的装饰器是无效的,请删除。`,
|
|
354
252
|
[DiagnoseCode.CO10023]: `元数据类 %s 只能有 KindClass 类型的装饰器,方法 %s 上的装饰器是无效的,请删除。`,
|
|
355
253
|
[DiagnoseCode.CO10024]: `元数据类 %s 存在多个组件装饰器 %s,一个元数据类最多只能有一个组件装饰器。`,
|
|
@@ -413,113 +311,12 @@ function reactiveAssignField(reactiveField) {
|
|
|
413
311
|
return `${reactiveField}Setter`;
|
|
414
312
|
}
|
|
415
313
|
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
* 保存装饰器参数
|
|
421
|
-
* @param isPlaceholderMetaClass 是否是占位的元数据类
|
|
422
|
-
* @param beDecoratedCls 被装饰的类
|
|
423
|
-
* @param params
|
|
424
|
-
*/
|
|
425
|
-
function addDecoratorParams(isPlaceholderMetaClass, beDecoratedCls, params) {
|
|
426
|
-
if (!isClass(beDecoratedCls)) {
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
if (!decoratorParamMap.has(beDecoratedCls)) {
|
|
430
|
-
decoratorParamMap.set(beDecoratedCls, []);
|
|
431
|
-
}
|
|
432
|
-
const paramsList = decoratorParamMap.get(beDecoratedCls);
|
|
433
|
-
paramsList.push(params);
|
|
434
|
-
if (isPlaceholderMetaClass) {
|
|
435
|
-
const beDecoratedClassList = placeholderMataClassMap2BeDecoratedClass.get(params.metadataClass);
|
|
436
|
-
if (beDecoratedClassList) {
|
|
437
|
-
beDecoratedClassList.push(beDecoratedCls);
|
|
438
|
-
} else {
|
|
439
|
-
placeholderMataClassMap2BeDecoratedClass.set(params.metadataClass, [beDecoratedCls]);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
// 收集到的装饰器参数,其中部分装饰器对应的类是*占位*元数据类,那么替换成真实的元数据类
|
|
444
|
-
function replacePlaceholderMetaClassParams2RealMetadataClassParams({
|
|
445
|
-
placeholderClassMap2RealMetadataClass,
|
|
446
|
-
notCalledDecorateSelfPlaceholderClassList
|
|
447
|
-
}) {
|
|
448
|
-
for (const [placeholderMetaClass, beDecoratedClassList] of placeholderMataClassMap2BeDecoratedClass.entries()) {
|
|
449
|
-
const realMetadataClass = placeholderClassMap2RealMetadataClass.get(placeholderMetaClass);
|
|
450
|
-
for (const beDecoratedClass of beDecoratedClassList) {
|
|
451
|
-
if (!realMetadataClass) {
|
|
452
|
-
throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10021, beDecoratedClass.name)));
|
|
453
|
-
}
|
|
454
|
-
const paramsList = decoratorParamMap.get(beDecoratedClass);
|
|
455
|
-
for (const p of paramsList) {
|
|
456
|
-
if (p.metadataClass === placeholderMetaClass) {
|
|
457
|
-
p.metadataClass = realMetadataClass;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
// 所有没有执行的decorateSelf函数的占位的装饰器表达式,如果也没有被使用,那么打印警告信息
|
|
463
|
-
for (const placeholderMetaClass of notCalledDecorateSelfPlaceholderClassList) {
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
function getDecoratorParam() {
|
|
467
|
-
return decoratorParamMap;
|
|
468
|
-
}
|
|
469
|
-
function clear$2() {
|
|
470
|
-
decoratorParamMap.clear();
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
// 元数据类 <--> 装饰器选项
|
|
474
|
-
const metadataDecoratorOptions = new Map();
|
|
475
|
-
// 占位的元数据类 <--> 装饰器选项
|
|
476
|
-
const placeholderDecoratorOptions = new Map();
|
|
477
|
-
// 占位的元数据类 <--> 真实的元数据类
|
|
478
|
-
const placeholderClassMap2RealMetadataClass = new Map();
|
|
479
|
-
// 没有调用decorateSelf函数的占位的元数据类
|
|
480
|
-
const notCalledDecorateSelfPlaceholderClassList = [];
|
|
481
|
-
// 记录创建装饰器表达式的选项
|
|
482
|
-
function addCreateDecoratorOption(isPlaceholderExp, metadataClass, options = null) {
|
|
483
|
-
if (isPlaceholderExp) {
|
|
484
|
-
// 是占位的元数据表达式,那么先临时记录到placeholderDecoratorOptions中,后续知道占位元数据类和真正的元数据类的映射关系后再保存到metadataDecoratorOptions中
|
|
485
|
-
placeholderDecoratorOptions.set(metadataClass, options);
|
|
486
|
-
} else {
|
|
487
|
-
// 不是占位的元数据表达式,那么直接保存在metadataDecoratorOptions中
|
|
488
|
-
metadataDecoratorOptions.set(metadataClass, options);
|
|
489
|
-
}
|
|
314
|
+
const createdDecoratorSetKey = Symbol.for('coco.createdDecoratorMetadataSet');
|
|
315
|
+
const globalObject = globalThis;
|
|
316
|
+
if (!globalObject[createdDecoratorSetKey]) {
|
|
317
|
+
globalObject[createdDecoratorSetKey] = new Set();
|
|
490
318
|
}
|
|
491
|
-
|
|
492
|
-
function addPlaceholderClassToRealMetadataClassRelation(placeholderClass, realMetadataClass) {
|
|
493
|
-
placeholderClassMap2RealMetadataClass.set(placeholderClass, realMetadataClass);
|
|
494
|
-
}
|
|
495
|
-
// 添加占位的装饰器表达式的参数
|
|
496
|
-
function mergePlaceholderClass2RealMetadataClassRelation() {
|
|
497
|
-
for (const [placeholderClass, decoratorOptions] of placeholderDecoratorOptions.entries()) {
|
|
498
|
-
const realMetadataClass = placeholderClassMap2RealMetadataClass.get(placeholderClass);
|
|
499
|
-
if (realMetadataClass) {
|
|
500
|
-
addCreateDecoratorOption(false, realMetadataClass, decoratorOptions);
|
|
501
|
-
} else {
|
|
502
|
-
notCalledDecorateSelfPlaceholderClassList.push(placeholderClass);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
function getCreateDecoratorOption(metadataClass) {
|
|
507
|
-
return metadataDecoratorOptions.get(metadataClass);
|
|
508
|
-
}
|
|
509
|
-
function getPlaceholderClassMap2RealMetadataClass() {
|
|
510
|
-
return {
|
|
511
|
-
placeholderClassMap2RealMetadataClass,
|
|
512
|
-
notCalledDecorateSelfPlaceholderClassList
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
function clear$1() {
|
|
516
|
-
metadataDecoratorOptions.clear();
|
|
517
|
-
placeholderDecoratorOptions.clear();
|
|
518
|
-
placeholderClassMap2RealMetadataClass.clear();
|
|
519
|
-
notCalledDecorateSelfPlaceholderClassList.length = 0;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
let createdDecoratorMetadataSet = new Set();
|
|
319
|
+
const createdDecoratorMetadataSet = globalObject[createdDecoratorSetKey];
|
|
523
320
|
function checkIfMetadataCreateMoreThenOneDecorator(metadataClass) {
|
|
524
321
|
if (!createdDecoratorMetadataSet.has(metadataClass)) {
|
|
525
322
|
createdDecoratorMetadataSet.add(metadataClass);
|
|
@@ -527,184 +324,143 @@ function checkIfMetadataCreateMoreThenOneDecorator(metadataClass) {
|
|
|
527
324
|
throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10014, metadataClass.name)));
|
|
528
325
|
}
|
|
529
326
|
}
|
|
530
|
-
function createDecoratorExpFactory(
|
|
327
|
+
function createDecoratorExpFactory() {
|
|
531
328
|
return function (isPlaceholderExp, metadataClass, option) {
|
|
532
|
-
|
|
533
|
-
|
|
329
|
+
addCreateDecoratorOption(isPlaceholderExp, metadataClass, option);
|
|
330
|
+
// TODO: 这里只校验直接创建装饰器的元数据类,可能遗漏占位装饰器绑定的元数据类;
|
|
331
|
+
// 应改为在计算出所有运行时装饰器表达式及其元数据类之后统一校验。
|
|
534
332
|
if (!isPlaceholderExp) {
|
|
535
|
-
checkIfMetadataCreateMoreThenOneDecorator(
|
|
536
|
-
}
|
|
537
|
-
const placeholderDecoratorModifyPrototype = new Map();
|
|
538
|
-
function decorateSelf(userParam) {
|
|
539
|
-
return function (beDecoratedCls, context) {
|
|
540
|
-
switch (context.kind) {
|
|
541
|
-
case KindClass:
|
|
542
|
-
{
|
|
543
|
-
if (isPlaceholderExp) {
|
|
544
|
-
addPlaceholderClassToRealMetadataClassRelation(MetaClsOrPlaceholderMetaCls, beDecoratedCls);
|
|
545
|
-
checkIfMetadataCreateMoreThenOneDecorator(beDecoratedCls);
|
|
546
|
-
} else {
|
|
547
|
-
throw new Error('decorateSelf函数只能调用一次');
|
|
548
|
-
}
|
|
549
|
-
fn(isPlaceholderExp, beDecoratedCls, {
|
|
550
|
-
metadataKind: KindClass,
|
|
551
|
-
metadataClass: MetaClsOrPlaceholderMetaCls,
|
|
552
|
-
metadataParam: userParam
|
|
553
|
-
});
|
|
554
|
-
const config = placeholderDecoratorModifyPrototype.get(MetaClsOrPlaceholderMetaCls);
|
|
555
|
-
if (typeof beDecoratedCls?.classDecoratorModifyPrototype === 'function') {
|
|
556
|
-
// 直接flush掉待修改的类,然后设置成修改函数即可。
|
|
557
|
-
if (config && config.toUpdateClassSet.size) {
|
|
558
|
-
for (const cls of Array.from(config.toUpdateClassSet)) {
|
|
559
|
-
beDecoratedCls?.classDecoratorModifyPrototype(cls.prototype);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
placeholderDecoratorModifyPrototype.set(MetaClsOrPlaceholderMetaCls, {
|
|
563
|
-
classDecoratorModifyPrototype: beDecoratedCls.classDecoratorModifyPrototype
|
|
564
|
-
});
|
|
565
|
-
} else {
|
|
566
|
-
placeholderDecoratorModifyPrototype.set(MetaClsOrPlaceholderMetaCls, {
|
|
567
|
-
classDecoratorModifyPrototype: null
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
break;
|
|
571
|
-
}
|
|
572
|
-
default:
|
|
573
|
-
throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10019, context.kind)));
|
|
574
|
-
}
|
|
575
|
-
return undefined;
|
|
576
|
-
};
|
|
333
|
+
checkIfMetadataCreateMoreThenOneDecorator(metadataClass);
|
|
577
334
|
}
|
|
578
335
|
function doCreateDecoratorExp(userParam) {
|
|
579
|
-
return function (
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
fn(isPlaceholderExp, beDecoratedCls, {
|
|
584
|
-
metadataKind: KindClass,
|
|
585
|
-
metadataClass: MetaClsOrPlaceholderMetaCls,
|
|
586
|
-
metadataParam: userParam
|
|
587
|
-
});
|
|
588
|
-
// 修改prototype
|
|
589
|
-
if (isPlaceholderExp) {
|
|
590
|
-
const config = placeholderDecoratorModifyPrototype.get(MetaClsOrPlaceholderMetaCls);
|
|
591
|
-
if (!config) {
|
|
592
|
-
// 第一次遇到,先收集
|
|
593
|
-
const toUpdateClassSet = new Set();
|
|
594
|
-
toUpdateClassSet.add(beDecoratedCls);
|
|
595
|
-
placeholderDecoratorModifyPrototype.set(MetaClsOrPlaceholderMetaCls, {
|
|
596
|
-
toUpdateClassSet
|
|
597
|
-
});
|
|
598
|
-
} else {
|
|
599
|
-
if (config.classDecoratorModifyPrototype) {
|
|
600
|
-
// 已经装饰过自己了,直接修改
|
|
601
|
-
config.classDecoratorModifyPrototype(beDecoratedCls.prototype);
|
|
602
|
-
} else {
|
|
603
|
-
if (config.classDecoratorModifyPrototype === undefined) {
|
|
604
|
-
// 又装饰器其他类,同样收集
|
|
605
|
-
config.toUpdateClassSet.add(beDecoratedCls);
|
|
606
|
-
} else if (config.classDecoratorModifyPrototype === null) {
|
|
607
|
-
// 不需要更新了,清空即可
|
|
608
|
-
config.toUpdateClassSet?.clear();
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
} else {
|
|
613
|
-
// 不是占位装饰器,直接修改被装饰类的原型链
|
|
614
|
-
if (typeof MetaClsOrPlaceholderMetaCls?.classDecoratorModifyPrototype === 'function') {
|
|
615
|
-
MetaClsOrPlaceholderMetaCls?.classDecoratorModifyPrototype(beDecoratedCls.prototype);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
break;
|
|
619
|
-
}
|
|
620
|
-
case KindMethod:
|
|
621
|
-
case KindField:
|
|
622
|
-
break;
|
|
623
|
-
case KindGetter:
|
|
624
|
-
case KindSetter:
|
|
625
|
-
case KindAccessor:
|
|
626
|
-
default:
|
|
627
|
-
throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10019, context.kind)));
|
|
628
|
-
}
|
|
629
|
-
const execOnce = once(function initializer() {
|
|
630
|
-
switch (context.kind) {
|
|
631
|
-
case KindField:
|
|
632
|
-
case KindMethod:
|
|
633
|
-
fn(isPlaceholderExp, this.constructor, {
|
|
634
|
-
metadataKind: context.kind,
|
|
635
|
-
metadataClass: MetaClsOrPlaceholderMetaCls,
|
|
636
|
-
metadataParam: userParam,
|
|
637
|
-
field: context.name
|
|
638
|
-
});
|
|
639
|
-
break;
|
|
640
|
-
}
|
|
641
|
-
});
|
|
642
|
-
context.addInitializer(function () {
|
|
643
|
-
execOnce(this);
|
|
644
|
-
});
|
|
645
|
-
return undefined;
|
|
336
|
+
return function (_beDecoratedCls, _context) {
|
|
337
|
+
// 普通装饰器表达式正常应由 AOT 编译期转换为 registerComponent 注册代码,
|
|
338
|
+
// 运行到这里说明代码未经 @cocojs/compiler 编译。
|
|
339
|
+
throw new Error('装饰器不应在运行时执行,请先使用 @cocojs/compiler 编译后再运行。');
|
|
646
340
|
};
|
|
647
341
|
}
|
|
648
342
|
if (isPlaceholderExp) {
|
|
649
|
-
|
|
343
|
+
const placeholderExp = doCreateDecoratorExp;
|
|
344
|
+
placeholderExp.$$metadataClass = metadataClass;
|
|
345
|
+
placeholderExp.$$isPlaceholderDecoratorExp = true;
|
|
346
|
+
placeholderExp.$$placeholderMetadataClass = metadataClass;
|
|
347
|
+
return placeholderExp;
|
|
348
|
+
} else {
|
|
349
|
+
const decoratorExp = doCreateDecoratorExp;
|
|
350
|
+
decoratorExp.$$metadataClass = metadataClass;
|
|
351
|
+
decoratorExp.$$isPlaceholderDecoratorExp = false;
|
|
352
|
+
return decoratorExp;
|
|
650
353
|
}
|
|
651
|
-
return doCreateDecoratorExp;
|
|
652
354
|
};
|
|
653
355
|
}
|
|
654
|
-
const doCreateDecoratorExp = createDecoratorExpFactory(
|
|
356
|
+
const doCreateDecoratorExp = createDecoratorExpFactory();
|
|
357
|
+
function createDecoratorExp(metadataClsOrOption, option) {
|
|
358
|
+
if (typeof metadataClsOrOption === 'function') {
|
|
359
|
+
const metadataCls = metadataClsOrOption;
|
|
360
|
+
if (!isSubClassOf(metadataCls, Metadata)) {
|
|
361
|
+
throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10018, metadataCls?.name)));
|
|
362
|
+
}
|
|
363
|
+
return doCreateDecoratorExp(false, metadataCls, option);
|
|
364
|
+
} else {
|
|
365
|
+
if (metadataClsOrOption !== undefined && !isPlainObject(metadataClsOrOption)) {
|
|
366
|
+
throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10018, metadataClsOrOption?.name)));
|
|
367
|
+
}
|
|
368
|
+
// 先提供一个默认的元数据类,再通过 @metadataFor(X) 替换为真实的元数据类
|
|
369
|
+
class PlaceholderMetadata extends Metadata {}
|
|
370
|
+
return doCreateDecoratorExp(true, PlaceholderMetadata, metadataClsOrOption);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
655
373
|
/**
|
|
656
|
-
*
|
|
657
|
-
*
|
|
374
|
+
* 建立占位元数据类与真实元数据类的关联。
|
|
375
|
+
* 由 `@metadataFor(X)` 经 AOT 编译后调用。
|
|
658
376
|
* @public
|
|
659
377
|
*/
|
|
660
|
-
function
|
|
661
|
-
|
|
662
|
-
|
|
378
|
+
function bindPlaceholderMetadataClass(decoratorExp, metadataClass) {
|
|
379
|
+
addPlaceholderClassToRealMetadataClassRelation(decoratorExp.$$placeholderMetadataClass, metadataClass);
|
|
380
|
+
checkIfMetadataCreateMoreThenOneDecorator(metadataClass);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* 注册表挂在 globalThis 上,保证同一个应用里多次加载运行时模块(例如 Jest 的 resetModules)
|
|
385
|
+
* 时注册方和 Application 读取到同一份数据。
|
|
386
|
+
* 每次调用时读取,避免框架 bundle 中生成的 registerComponent 调用先于模块级变量初始化执行。
|
|
387
|
+
*/
|
|
388
|
+
function getGlobalRegistry() {
|
|
389
|
+
const registryKey = Symbol.for('coco.decoratorRegistry');
|
|
390
|
+
const globalObject = globalThis;
|
|
391
|
+
if (!globalObject[registryKey]) {
|
|
392
|
+
globalObject[registryKey] = new Map();
|
|
663
393
|
}
|
|
664
|
-
return
|
|
394
|
+
return globalObject[registryKey];
|
|
665
395
|
}
|
|
666
396
|
/**
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
397
|
+
* 全局静态注册函数。编译期由 coco-compiler 注入到每个源文件末尾。
|
|
398
|
+
* 源码中类、字段、方法、getter 上的装饰器经 AOT 编译后统一转换为对它的调用,
|
|
399
|
+
* 用于保存原始装饰器参数。
|
|
400
|
+
* `@metadataFor(X)` 不产生注册参数,只额外生成 bindPlaceholderMetadataClass 调用。
|
|
670
401
|
* @public
|
|
671
402
|
*/
|
|
672
|
-
function
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
403
|
+
function registerComponent(cls, params) {
|
|
404
|
+
getGlobalRegistry().set(cls, params);
|
|
405
|
+
}
|
|
406
|
+
/** 读取userDecoratorParams */
|
|
407
|
+
function getRegistry() {
|
|
408
|
+
return getGlobalRegistry();
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function createRuntimeDecoratorParams(userDecoratorParams) {
|
|
412
|
+
const runtimeDecoratorParams = new Map();
|
|
413
|
+
const placeholderClassMap2RealMetadataClass = getPlaceholderClassMap2RealMetadataClass();
|
|
414
|
+
// 基于userDecoratorParams生成runtimeDecoratorParams,并将其中的占位元数据类替换为真实元数据类
|
|
415
|
+
for (const [cls, params] of userDecoratorParams) {
|
|
416
|
+
runtimeDecoratorParams.set(cls, params.map(p => {
|
|
417
|
+
if (p.isPlaceholderDecoratorExp) {
|
|
418
|
+
const realClass = placeholderClassMap2RealMetadataClass.get(p.metadataClass);
|
|
419
|
+
if (!realClass) {
|
|
420
|
+
throw new Error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10021, cls.name)));
|
|
421
|
+
}
|
|
422
|
+
return {
|
|
423
|
+
metadataKind: p.metadataKind,
|
|
424
|
+
metadataClass: realClass,
|
|
425
|
+
metadataParam: p.metadataParam,
|
|
426
|
+
field: p.field
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
return {
|
|
430
|
+
metadataKind: p.metadataKind,
|
|
431
|
+
metadataClass: p.metadataClass,
|
|
432
|
+
metadataParam: p.metadataParam,
|
|
433
|
+
field: p.field
|
|
434
|
+
};
|
|
435
|
+
}));
|
|
436
|
+
}
|
|
437
|
+
for (const [beDecoratedCls, params] of runtimeDecoratorParams.entries()) {
|
|
438
|
+
for (const p of params) {
|
|
439
|
+
if (!p.metadataClass) {
|
|
440
|
+
throw new Error(`组件 ${beDecoratedCls?.name} 的装饰器没有对应的元数据类,请确认装饰器由 createDecoratorExp 创建。`);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
if (!isCocoClass(beDecoratedCls)) {
|
|
444
|
+
throw new Error(`所有被装饰器的对象${beDecoratedCls?.name}必须都是类或者类字段或类方法,且必须存在静态$$id字段。`);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return runtimeDecoratorParams;
|
|
676
448
|
}
|
|
677
449
|
|
|
678
450
|
/**
|
|
679
451
|
* 装饰器表达式模块的工作流
|
|
680
452
|
*/
|
|
681
453
|
function initDecoratorParamModule() {
|
|
682
|
-
//
|
|
683
|
-
|
|
684
|
-
/**
|
|
685
|
-
* TODO: 如果view组件的state需要用到props初始化的话,会导致报错,例如:
|
|
686
|
-
* class {
|
|
687
|
-
* constructor(props){
|
|
688
|
-
* this.name = props.name // 这里会报错
|
|
689
|
-
* }
|
|
690
|
-
* }
|
|
691
|
-
*/
|
|
692
|
-
new Cls();
|
|
693
|
-
}
|
|
694
|
-
// 创建的装饰器表达式的选项,将占位的元数据类替换成真实的元数据类
|
|
454
|
+
// start 时把userDecoratorParams解析为runtimeDecoratorParams并校验,覆盖 Application 构造后声明的局部类。
|
|
455
|
+
const userDecoratorParams = getRegistry();
|
|
695
456
|
mergePlaceholderClass2RealMetadataClassRelation();
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
if (!isCocoClass(beDecoratedClass)) {
|
|
701
|
-
throw new Error(`所有被装饰器的对象${beDecoratedClass?.name}必须都是类或者类字段或类方法,且必须存在静态$$id字段。`);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
457
|
+
const runtimeDecoratorParams = createRuntimeDecoratorParams(userDecoratorParams);
|
|
458
|
+
// 注册表的职责是“待启动消费的注册信息”,解析完成后清空,避免重复消费上一次的注册
|
|
459
|
+
userDecoratorParams.clear();
|
|
460
|
+
return runtimeDecoratorParams;
|
|
704
461
|
}
|
|
705
462
|
function clearDecoratorParamModule() {
|
|
706
463
|
clear$1();
|
|
707
|
-
clear$2();
|
|
708
464
|
}
|
|
709
465
|
|
|
710
466
|
/**
|
|
@@ -715,72 +471,59 @@ var Type;
|
|
|
715
471
|
Type[Type["Class"] = KindClass] = "Class";
|
|
716
472
|
Type[Type["Field"] = KindField] = "Field";
|
|
717
473
|
Type[Type["Method"] = KindMethod] = "Method";
|
|
474
|
+
Type[Type["Getter"] = KindGetter] = "Getter";
|
|
718
475
|
})(Type || (Type = {}));
|
|
719
476
|
/**
|
|
720
477
|
* @public
|
|
721
478
|
*/
|
|
722
|
-
const target =
|
|
479
|
+
const target = createDecoratorExp();
|
|
723
480
|
|
|
724
|
-
let _initClass$z;
|
|
725
481
|
/**
|
|
726
482
|
* @public
|
|
727
483
|
*/
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
static
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
}();
|
|
742
|
-
var Target = _Target;
|
|
743
|
-
|
|
744
|
-
let _initClass$y;
|
|
484
|
+
class Target extends Metadata {
|
|
485
|
+
static $$id = "Target";
|
|
486
|
+
static Type = Type;
|
|
487
|
+
value;
|
|
488
|
+
}
|
|
489
|
+
bindPlaceholderMetadataClass(target, Target);
|
|
490
|
+
registerComponent(Target, [{
|
|
491
|
+
metadataKind: "class",
|
|
492
|
+
metadataClass: target.$$metadataClass,
|
|
493
|
+
metadataParam: [Type.Class],
|
|
494
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
495
|
+
}]);
|
|
496
|
+
|
|
745
497
|
/**
|
|
746
498
|
* @public
|
|
747
499
|
*/
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
super(_Autowired), _initClass$y();
|
|
759
|
-
}
|
|
760
|
-
}();
|
|
761
|
-
var Autowired = _Autowired;
|
|
500
|
+
class Autowired extends Metadata {
|
|
501
|
+
static $$id = "Autowired";
|
|
502
|
+
value;
|
|
503
|
+
}
|
|
504
|
+
registerComponent(Autowired, [{
|
|
505
|
+
metadataKind: "class",
|
|
506
|
+
metadataClass: target.$$metadataClass,
|
|
507
|
+
metadataParam: [Target.Type.Field],
|
|
508
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
509
|
+
}]);
|
|
762
510
|
|
|
763
511
|
// TODO: cls?: Class<any>如果去掉的话,在项目中会报错,应该是ts-server是拿到参数了,但是声明中确没有
|
|
764
512
|
var autowired = createDecoratorExp(Autowired);
|
|
765
513
|
|
|
766
|
-
let _initClass$x;
|
|
767
514
|
/**
|
|
768
515
|
* @public
|
|
769
516
|
*/
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
super(_Id), _initClass$x();
|
|
781
|
-
}
|
|
782
|
-
}();
|
|
783
|
-
var Id = _Id;
|
|
517
|
+
class Id extends Metadata {
|
|
518
|
+
static $$id = "Id";
|
|
519
|
+
value;
|
|
520
|
+
}
|
|
521
|
+
registerComponent(Id, [{
|
|
522
|
+
metadataKind: "class",
|
|
523
|
+
metadataClass: target.$$metadataClass,
|
|
524
|
+
metadataParam: [Target.Type.Method],
|
|
525
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
526
|
+
}]);
|
|
784
527
|
|
|
785
528
|
/**
|
|
786
529
|
* @id装饰器
|
|
@@ -788,7 +531,6 @@ var Id = _Id;
|
|
|
788
531
|
*/
|
|
789
532
|
var id = createDecoratorExp(Id);
|
|
790
533
|
|
|
791
|
-
let _initClass$w;
|
|
792
534
|
/**
|
|
793
535
|
* Component不添加@scope(SCOPE.Singleton)的原因:
|
|
794
536
|
* 因为不设置默认就是singleton,还可以避免 scope <-> target 循环依赖的问题
|
|
@@ -796,20 +538,16 @@ let _initClass$w;
|
|
|
796
538
|
/**
|
|
797
539
|
* @public
|
|
798
540
|
*/
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
super(_Component), _initClass$w();
|
|
810
|
-
}
|
|
811
|
-
}();
|
|
812
|
-
var Component = _Component;
|
|
541
|
+
class Component extends Metadata {
|
|
542
|
+
static $$id = "Component";
|
|
543
|
+
value;
|
|
544
|
+
}
|
|
545
|
+
registerComponent(Component, [{
|
|
546
|
+
metadataKind: "class",
|
|
547
|
+
metadataClass: target.$$metadataClass,
|
|
548
|
+
metadataParam: [Target.Type.Class, Target.Type.Method],
|
|
549
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
550
|
+
}]);
|
|
813
551
|
|
|
814
552
|
/**
|
|
815
553
|
* ioc组件,只有ioc组件才能实例化
|
|
@@ -817,48 +555,37 @@ var Component = _Component;
|
|
|
817
555
|
*/
|
|
818
556
|
var component = createDecoratorExp(Component);
|
|
819
557
|
|
|
820
|
-
let _initClass$v;
|
|
821
558
|
/**
|
|
822
559
|
* @public
|
|
823
560
|
*/
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
super(_Configuration), _initClass$v();
|
|
834
|
-
}
|
|
835
|
-
}();
|
|
836
|
-
var Configuration = _Configuration;
|
|
561
|
+
class Configuration extends Metadata {
|
|
562
|
+
static $$id = "Configuration";
|
|
563
|
+
}
|
|
564
|
+
registerComponent(Configuration, [{
|
|
565
|
+
metadataKind: "class",
|
|
566
|
+
metadataClass: target.$$metadataClass,
|
|
567
|
+
metadataParam: [Target.Type.Class],
|
|
568
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
569
|
+
}]);
|
|
837
570
|
|
|
838
571
|
var configuration = createDecoratorExp(Configuration);
|
|
839
572
|
|
|
840
|
-
let _initClass$u;
|
|
841
573
|
/**
|
|
842
574
|
* @public
|
|
843
575
|
*/
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
super(_ConstructorInject), _initClass$u();
|
|
855
|
-
}
|
|
856
|
-
}();
|
|
857
|
-
var ConstructorInject = _ConstructorInject;
|
|
576
|
+
class ConstructorInject extends Metadata {
|
|
577
|
+
static $$id = "ConstructorInject";
|
|
578
|
+
value;
|
|
579
|
+
}
|
|
580
|
+
registerComponent(ConstructorInject, [{
|
|
581
|
+
metadataKind: "class",
|
|
582
|
+
metadataClass: target.$$metadataClass,
|
|
583
|
+
metadataParam: [Target.Type.Class],
|
|
584
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
585
|
+
}]);
|
|
858
586
|
|
|
859
587
|
var constructorInject = createDecoratorExp(ConstructorInject);
|
|
860
588
|
|
|
861
|
-
let _initClass$t;
|
|
862
589
|
/**
|
|
863
590
|
* @public
|
|
864
591
|
*/
|
|
@@ -872,62 +599,48 @@ var SCOPE;
|
|
|
872
599
|
/**
|
|
873
600
|
* @public
|
|
874
601
|
*/
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
super(_Scope), _initClass$t();
|
|
886
|
-
}
|
|
887
|
-
}();
|
|
888
|
-
var Scope = _Scope;
|
|
602
|
+
class Scope extends Metadata {
|
|
603
|
+
static $$id = "Scope";
|
|
604
|
+
value = SCOPE.Singleton;
|
|
605
|
+
}
|
|
606
|
+
registerComponent(Scope, [{
|
|
607
|
+
metadataKind: "class",
|
|
608
|
+
metadataClass: target.$$metadataClass,
|
|
609
|
+
metadataParam: [Target.Type.Class, Target.Type.Method],
|
|
610
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
611
|
+
}]);
|
|
889
612
|
|
|
890
613
|
var scope = createDecoratorExp(Scope);
|
|
891
614
|
|
|
892
|
-
let _initClass$s;
|
|
893
615
|
/**
|
|
894
616
|
* @public
|
|
895
617
|
*/
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
super(_Qualifier), _initClass$s();
|
|
907
|
-
}
|
|
908
|
-
}();
|
|
909
|
-
var Qualifier = _Qualifier;
|
|
618
|
+
class Qualifier extends Metadata {
|
|
619
|
+
static $$id = "Qualifier";
|
|
620
|
+
value;
|
|
621
|
+
}
|
|
622
|
+
registerComponent(Qualifier, [{
|
|
623
|
+
metadataKind: "class",
|
|
624
|
+
metadataClass: target.$$metadataClass,
|
|
625
|
+
metadataParam: [Target.Type.Field],
|
|
626
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
627
|
+
}]);
|
|
910
628
|
|
|
911
629
|
var qualifier = createDecoratorExp(Qualifier);
|
|
912
630
|
|
|
913
|
-
let _initClass$r;
|
|
914
631
|
/**
|
|
915
632
|
* @public
|
|
916
633
|
*/
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
super(_Value), _initClass$r();
|
|
928
|
-
}
|
|
929
|
-
}();
|
|
930
|
-
var Value = _Value;
|
|
634
|
+
class Value extends Metadata {
|
|
635
|
+
static $$id = "Value";
|
|
636
|
+
value;
|
|
637
|
+
}
|
|
638
|
+
registerComponent(Value, [{
|
|
639
|
+
metadataKind: "class",
|
|
640
|
+
metadataClass: target.$$metadataClass,
|
|
641
|
+
metadataParam: [Target.Type.Field],
|
|
642
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
643
|
+
}]);
|
|
931
644
|
|
|
932
645
|
var value = createDecoratorExp(Value, {
|
|
933
646
|
componentPostConstruct: function (metadata, application, target) {
|
|
@@ -969,6 +682,9 @@ class MetadataRepository {
|
|
|
969
682
|
case KindMethod:
|
|
970
683
|
this.addMethodKindMetadata(beDecoratedCls, field, metadataClass, metadataParam);
|
|
971
684
|
break;
|
|
685
|
+
case KindGetter:
|
|
686
|
+
this.addGetterKindMetadata(beDecoratedCls, field, metadataClass, metadataParam);
|
|
687
|
+
break;
|
|
972
688
|
}
|
|
973
689
|
}
|
|
974
690
|
}
|
|
@@ -992,7 +708,8 @@ class MetadataRepository {
|
|
|
992
708
|
config = {
|
|
993
709
|
classMetadata: [],
|
|
994
710
|
fieldMetadata: new Map(),
|
|
995
|
-
methodMetadata: new Map()
|
|
711
|
+
methodMetadata: new Map(),
|
|
712
|
+
getterMetadata: new Map()
|
|
996
713
|
};
|
|
997
714
|
map.set(cls, config);
|
|
998
715
|
}
|
|
@@ -1042,6 +759,22 @@ class MetadataRepository {
|
|
|
1042
759
|
const metadata = instantiateMetadata(MetadataCls, args);
|
|
1043
760
|
methodMetas.push(metadata);
|
|
1044
761
|
}
|
|
762
|
+
addGetterKindMetadata(Cls, fieldName, MetadataCls, args) {
|
|
763
|
+
let config = this.getMetadataByClass(Cls);
|
|
764
|
+
if (!config) {
|
|
765
|
+
config = this.addToMap(Cls);
|
|
766
|
+
}
|
|
767
|
+
const {
|
|
768
|
+
getterMetadata
|
|
769
|
+
} = config;
|
|
770
|
+
let methodMetas = getterMetadata.get(fieldName);
|
|
771
|
+
if (!methodMetas) {
|
|
772
|
+
methodMetas = [];
|
|
773
|
+
getterMetadata.set(fieldName, methodMetas);
|
|
774
|
+
}
|
|
775
|
+
const metadata = instantiateMetadata(MetadataCls, args);
|
|
776
|
+
methodMetas.push(metadata);
|
|
777
|
+
}
|
|
1045
778
|
/**
|
|
1046
779
|
* 获取指定类的类类型的元数据
|
|
1047
780
|
* @param beDecoratedCls 指定类
|
|
@@ -1206,7 +939,7 @@ class ComponentMetadataClass {
|
|
|
1206
939
|
// 遍历所有被装饰器的元数据类,将自己添加为被装饰器类的组件装饰器
|
|
1207
940
|
const beDecoratedClasses = decorateTree.get(current) || new Set();
|
|
1208
941
|
for (const beDecoratedClass of beDecoratedClasses) {
|
|
1209
|
-
// 忽略自己装饰自己的情况(
|
|
942
|
+
// 忽略自己装饰自己的情况(bind),因为这不算是组件装饰器
|
|
1210
943
|
if (beDecoratedClass === current) {
|
|
1211
944
|
// 避免自引用导致的无限循环
|
|
1212
945
|
if (!visited.has(beDecoratedClass)) {
|
|
@@ -1406,137 +1139,6 @@ class ComponentMetadataClass {
|
|
|
1406
1139
|
}
|
|
1407
1140
|
}
|
|
1408
1141
|
|
|
1409
|
-
/**
|
|
1410
|
-
* component
|
|
1411
|
-
* 1. 只能用在class或者method上,且只能装饰一次
|
|
1412
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1413
|
-
*/
|
|
1414
|
-
/**
|
|
1415
|
-
* view
|
|
1416
|
-
* 1. 只能用在class,且只能装饰一次
|
|
1417
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1418
|
-
*/
|
|
1419
|
-
/**
|
|
1420
|
-
* page
|
|
1421
|
-
* 1. 只能用在class,且只能装饰一次
|
|
1422
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1423
|
-
*/
|
|
1424
|
-
/**
|
|
1425
|
-
* layout
|
|
1426
|
-
* 1. 只能用在class,且只能使用一次
|
|
1427
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1428
|
-
*/
|
|
1429
|
-
/**
|
|
1430
|
-
* qualifier
|
|
1431
|
-
* 1. 只能用在field上,且只能装饰一次
|
|
1432
|
-
* 2. 依赖component配合使用
|
|
1433
|
-
*/
|
|
1434
|
-
/**
|
|
1435
|
-
* autowired
|
|
1436
|
-
* 1. 只能用在field上,且只能装饰一次
|
|
1437
|
-
* 2. TODO: 只能在view及其复合装饰器组件内部、controller及其复合装饰器组件内部、api装饰器组件内部
|
|
1438
|
-
* 3. 自动注入收到分层概念的约束,具体如下:
|
|
1439
|
-
* 3.1 view及其复合装饰器内部:controller及其复合装饰器组件, global-data, store, route, router,util及其复合装饰器组件
|
|
1440
|
-
* 3.2 controller及其复合装饰器内部:util及其复合装饰器组件
|
|
1441
|
-
* 3.3 util及其复合装饰器内部:util以及复合装饰器组件
|
|
1442
|
-
*/
|
|
1443
|
-
/**
|
|
1444
|
-
* configuration
|
|
1445
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1446
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1447
|
-
*/
|
|
1448
|
-
/**
|
|
1449
|
-
* constructor-inject
|
|
1450
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1451
|
-
*/
|
|
1452
|
-
/**
|
|
1453
|
-
* init
|
|
1454
|
-
* 1. 只能用在method上,且只能装饰一次
|
|
1455
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1456
|
-
*/
|
|
1457
|
-
/**
|
|
1458
|
-
* start
|
|
1459
|
-
* 1. 只能用在field上,且只能装饰一次
|
|
1460
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1461
|
-
*/
|
|
1462
|
-
/**
|
|
1463
|
-
* target
|
|
1464
|
-
* 1. 只能用在field上,且只能装饰一次
|
|
1465
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1466
|
-
*/
|
|
1467
|
-
/**
|
|
1468
|
-
* value
|
|
1469
|
-
* 1. 只能用在field上,且只能装饰一次
|
|
1470
|
-
*/
|
|
1471
|
-
/**
|
|
1472
|
-
* reactive
|
|
1473
|
-
* 1. 只能用在field上,且只能装饰一次
|
|
1474
|
-
*/
|
|
1475
|
-
/**
|
|
1476
|
-
* memoized
|
|
1477
|
-
* 1. 只能用在method上,且只能装饰一次
|
|
1478
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1479
|
-
*/
|
|
1480
|
-
/**
|
|
1481
|
-
* store
|
|
1482
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1483
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1484
|
-
*/
|
|
1485
|
-
/**
|
|
1486
|
-
* render
|
|
1487
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1488
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1489
|
-
*/
|
|
1490
|
-
/**
|
|
1491
|
-
* route
|
|
1492
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1493
|
-
* 2. 在class上使用时,依赖page同时使用
|
|
1494
|
-
*/
|
|
1495
|
-
/**
|
|
1496
|
-
* router
|
|
1497
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1498
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1499
|
-
*/
|
|
1500
|
-
/**
|
|
1501
|
-
* util
|
|
1502
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1503
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1504
|
-
*/
|
|
1505
|
-
/**
|
|
1506
|
-
* api
|
|
1507
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1508
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1509
|
-
*/
|
|
1510
|
-
/**
|
|
1511
|
-
* bind
|
|
1512
|
-
* 1. 只能用在method上,且只能装饰一次
|
|
1513
|
-
* 2. 只能在有view装饰器或者view复合装饰器组件上使用
|
|
1514
|
-
*/
|
|
1515
|
-
/**
|
|
1516
|
-
* flow
|
|
1517
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1518
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1519
|
-
*/
|
|
1520
|
-
/**
|
|
1521
|
-
* global-data
|
|
1522
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1523
|
-
* 2. 不能和component复合装饰器同时使用
|
|
1524
|
-
*/
|
|
1525
|
-
/**
|
|
1526
|
-
* ref
|
|
1527
|
-
* 1. 只能用在field上,且只能装饰一次
|
|
1528
|
-
* 2. 宿主组件必须是view组件或者是view复合组件
|
|
1529
|
-
*/
|
|
1530
|
-
/**
|
|
1531
|
-
* refs
|
|
1532
|
-
* 1. 只能用在field上,且只能装饰一次
|
|
1533
|
-
* 2. 宿主组件必须是view组件或者是view复合组件
|
|
1534
|
-
*/
|
|
1535
|
-
/**
|
|
1536
|
-
* web-application
|
|
1537
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1538
|
-
* 2.
|
|
1539
|
-
*/
|
|
1540
1142
|
function deleteMetadatas(metadatas, idxs) {
|
|
1541
1143
|
idxs.sort((a, b) => b - a);
|
|
1542
1144
|
idxs.forEach(idx => metadatas.splice(idx, 1));
|
|
@@ -2001,12 +1603,13 @@ class IocComponentDefinition {
|
|
|
2001
1603
|
this.clsDefinitionMap.set(cls, componentDefinition);
|
|
2002
1604
|
}
|
|
2003
1605
|
/**
|
|
2004
|
-
*
|
|
1606
|
+
* 解析组件实际需要实例化的类。
|
|
1607
|
+
* 没有子类时返回自身,只有一个子类时返回该子类,多个子类时抛出异常。
|
|
2005
1608
|
* @param ClsOrId 想要实例化的类或类id
|
|
2006
1609
|
* @param qualifier 如果存在多个后端类,需要通过qualifier指定具体的类id
|
|
2007
1610
|
* @returns 真正会实例化的类定义
|
|
2008
1611
|
*/
|
|
2009
|
-
|
|
1612
|
+
resolve(ClsOrId, qualifier) {
|
|
2010
1613
|
const definition = this.getDefinition(ClsOrId);
|
|
2011
1614
|
if (!definition) {
|
|
2012
1615
|
const diagnose = createDiagnose(DiagnoseCode.CO10011, typeof ClsOrId === 'string' ? ClsOrId : ClsOrId.name);
|
|
@@ -2058,10 +1661,72 @@ class IocComponentDefinition {
|
|
|
2058
1661
|
}
|
|
2059
1662
|
}
|
|
2060
1663
|
|
|
1664
|
+
var InjectType;
|
|
1665
|
+
(function (InjectType) {
|
|
1666
|
+
InjectType["constructor"] = "c";
|
|
1667
|
+
InjectType["autowired"] = "a";
|
|
1668
|
+
})(InjectType || (InjectType = {}));
|
|
1669
|
+
class DependencyGraph {
|
|
1670
|
+
// 创建中的ioc组件定义
|
|
1671
|
+
creating = new Set();
|
|
1672
|
+
// 已经完成newComponent的ioc组件
|
|
1673
|
+
earlyCreate = new Set();
|
|
1674
|
+
// 当前实例化路径
|
|
1675
|
+
stack = [];
|
|
1676
|
+
injectStr(type) {
|
|
1677
|
+
const s = type === InjectType.constructor ? '-c->' : type === InjectType.autowired ? '-a->' : '';
|
|
1678
|
+
return s ? `${s} ` : s;
|
|
1679
|
+
}
|
|
1680
|
+
addDependency(targetDefinition, instantiateDefinition, injectType) {
|
|
1681
|
+
// console.info('addDep', instantiateDefinition.cls.name);
|
|
1682
|
+
if (this.creating.has(instantiateDefinition) && (!instantiateDefinition.isSingleton || !this.earlyCreate.has(instantiateDefinition))) {
|
|
1683
|
+
const fullStack = [...this.stack, {
|
|
1684
|
+
targetDef: targetDefinition,
|
|
1685
|
+
instantiateDef: instantiateDefinition,
|
|
1686
|
+
injectType
|
|
1687
|
+
}];
|
|
1688
|
+
const loopDependencyInfo = fullStack.map(i => `${this.injectStr(i.injectType)}${i.instantiateDef.cls.name}${i.targetDef !== i.instantiateDef ? `{${i.targetDef.cls.name}}` : ''}`).join(' ');
|
|
1689
|
+
const diagnose = createDiagnose(DiagnoseCode.CO10013, loopDependencyInfo);
|
|
1690
|
+
throw new Error(stringifyDiagnose(diagnose));
|
|
1691
|
+
}
|
|
1692
|
+
this.creating.add(instantiateDefinition);
|
|
1693
|
+
this.stack.push({
|
|
1694
|
+
instantiateDef: instantiateDefinition,
|
|
1695
|
+
targetDef: targetDefinition,
|
|
1696
|
+
injectType
|
|
1697
|
+
});
|
|
1698
|
+
}
|
|
1699
|
+
removeDependency(targetDefinition, instantiateDefinition) {
|
|
1700
|
+
// console.info('rmDep', instantiateDefinition.cls.name);
|
|
1701
|
+
const now = this.stack.pop();
|
|
1702
|
+
if (now.targetDef !== targetDefinition || now.instantiateDef !== instantiateDefinition) {
|
|
1703
|
+
throw new Error();
|
|
1704
|
+
}
|
|
1705
|
+
this.earlyCreate.delete(instantiateDefinition);
|
|
1706
|
+
this.creating.delete(instantiateDefinition);
|
|
1707
|
+
}
|
|
1708
|
+
makeEarlyCreated(instantiateDefinition) {
|
|
1709
|
+
// console.info('mkEarly', instantiateDefinition.cls.name);
|
|
1710
|
+
if (!this.creating.has(instantiateDefinition)) {
|
|
1711
|
+
throw new Error('没有创建就调用了makeEarlyCreated,是一个bug');
|
|
1712
|
+
}
|
|
1713
|
+
this.earlyCreate.add(instantiateDefinition);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
var InstantiateStage;
|
|
1718
|
+
(function (InstantiateStage) {
|
|
1719
|
+
// 在等待构造函数创建中
|
|
1720
|
+
InstantiateStage["WAITING_CTOR_ARGS"] = "waitCtorArgs";
|
|
1721
|
+
// 刚new出来,componentPostConstruct已执行,autowired未注入
|
|
1722
|
+
InstantiateStage["UNINITIALIZED"] = "uninitialized";
|
|
1723
|
+
// 初始化完毕:属性全部注入,init已执行,start未执行
|
|
1724
|
+
InstantiateStage["INITIALIZED"] = "initialized";
|
|
1725
|
+
})(InstantiateStage || (InstantiateStage = {}));
|
|
2061
1726
|
class IocComponentFactory {
|
|
2062
1727
|
// 单例构造函数和单例的映射关系
|
|
2063
1728
|
singletonInstances = new Map();
|
|
2064
|
-
|
|
1729
|
+
newComponent(application, definition, constructorArgs) {
|
|
2065
1730
|
const {
|
|
2066
1731
|
cls,
|
|
2067
1732
|
instantiateType
|
|
@@ -2082,7 +1747,8 @@ class IocComponentFactory {
|
|
|
2082
1747
|
const {
|
|
2083
1748
|
classMetadata,
|
|
2084
1749
|
methodMetadata,
|
|
2085
|
-
fieldMetadata
|
|
1750
|
+
fieldMetadata,
|
|
1751
|
+
getterMetadata
|
|
2086
1752
|
} = metadatas;
|
|
2087
1753
|
for (const meta of classMetadata) {
|
|
2088
1754
|
const option = getCreateDecoratorOption(meta.constructor);
|
|
@@ -2112,22 +1778,33 @@ class IocComponentFactory {
|
|
|
2112
1778
|
}
|
|
2113
1779
|
}
|
|
2114
1780
|
}
|
|
1781
|
+
for (const [getter, metaList] of getterMetadata.entries()) {
|
|
1782
|
+
for (const meta of metaList) {
|
|
1783
|
+
const option = getCreateDecoratorOption(meta.constructor);
|
|
1784
|
+
if (option) {
|
|
1785
|
+
option.componentPostConstruct.call(component, meta, application, {
|
|
1786
|
+
name: getter,
|
|
1787
|
+
kind: KindGetter
|
|
1788
|
+
});
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
2115
1792
|
}
|
|
2116
1793
|
return component;
|
|
2117
1794
|
}
|
|
2118
1795
|
getComponents(application, userOption) {
|
|
2119
|
-
|
|
2120
|
-
|
|
1796
|
+
/**
|
|
1797
|
+
* TODO: dependencyGraph 在 getComponents 内部创建,getComponents 一旦重入(如 init 内再次 getComponent),
|
|
1798
|
+
* 就会拿到另一张图、丢失外层创建链路,循环依赖检查因此失效。
|
|
1799
|
+
* 解决方向二选一:
|
|
1800
|
+
* 1. 约束 getComponents 只能顺序调用;
|
|
1801
|
+
* 2. 把 dependencyGraph 提升为唯一实例供重入共享。
|
|
1802
|
+
*/
|
|
1803
|
+
const dependencyGraph = new DependencyGraph();
|
|
1804
|
+
const newCreateInstance = []; // 新建实例和对应的实例化类
|
|
2121
1805
|
const newSingletonInstances = new Map(); // 新增的单例,最后要合并到singletonInstances
|
|
2122
|
-
const instantiatingStage = new Set(); // 实例化中
|
|
2123
|
-
const assignningStage = new Set(); // field赋值中
|
|
2124
|
-
const finishedStage = new Set(); // 已完成
|
|
2125
|
-
// 已经有的单例填充到finishedStage和instances
|
|
2126
|
-
for (const [cls, instance] of this.singletonInstances.entries()) {
|
|
2127
|
-
targetClsInstanceMap.set(cls, instance);
|
|
2128
|
-
}
|
|
2129
1806
|
// 完整的初始化一个组件
|
|
2130
|
-
const instantiateComponent = opt => {
|
|
1807
|
+
const instantiateComponent = (opt, injectType) => {
|
|
2131
1808
|
const {
|
|
2132
1809
|
classOrId
|
|
2133
1810
|
} = opt;
|
|
@@ -2143,7 +1820,8 @@ class IocComponentFactory {
|
|
|
2143
1820
|
qualifier = application.propertiesConfig.getValue(`${targetDefinition.id}.qualifier`);
|
|
2144
1821
|
}
|
|
2145
1822
|
// 真正实例化的类定义
|
|
2146
|
-
const instantiateDefinition = application.iocComponentDefinition.
|
|
1823
|
+
const instantiateDefinition = application.iocComponentDefinition.resolve(classOrId, qualifier);
|
|
1824
|
+
// 尝试走缓存
|
|
2147
1825
|
if (instantiateDefinition.isSingleton) {
|
|
2148
1826
|
if (this.singletonInstances.has(instantiateDefinition.cls)) {
|
|
2149
1827
|
return this.singletonInstances.get(instantiateDefinition.cls);
|
|
@@ -2151,76 +1829,94 @@ class IocComponentFactory {
|
|
|
2151
1829
|
return newSingletonInstances.get(instantiateDefinition.cls);
|
|
2152
1830
|
}
|
|
2153
1831
|
}
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
}
|
|
2158
|
-
// 在实例化中或者已实例化,返回实例
|
|
2159
|
-
if (assignningStage.has(targetDefinition.cls) || finishedStage.has(targetDefinition.cls)) {
|
|
2160
|
-
return targetClsInstanceMap.get(targetDefinition.cls);
|
|
2161
|
-
}
|
|
2162
|
-
instantiatingStage.add(targetDefinition.cls);
|
|
1832
|
+
dependencyGraph.addDependency(targetDefinition, instantiateDefinition, injectType);
|
|
1833
|
+
// newAddStage(targetDefinition.cls, InstantiateStage.WAITING_CTOR_ARGS);
|
|
1834
|
+
// 没有缓存,只能真的创建了
|
|
2163
1835
|
const constructorArgs = [];
|
|
2164
1836
|
const constructorInject = application.metadataRepository.listClassKindMetadata(instantiateDefinition.cls, ConstructorInject);
|
|
2165
|
-
if (constructorInject.length
|
|
2166
|
-
// 因为元数据不能重复,所以只有一个
|
|
1837
|
+
if (constructorInject.length === 1) {
|
|
2167
1838
|
const constructorInjectParams = constructorInject[0].value;
|
|
2168
|
-
for (const
|
|
2169
|
-
if (
|
|
1839
|
+
for (const dependencyCls of constructorInjectParams) {
|
|
1840
|
+
if (dependencyCls === undefined) {
|
|
2170
1841
|
constructorArgs.push(undefined);
|
|
2171
1842
|
} else {
|
|
2172
1843
|
const depInstance = instantiateComponent({
|
|
2173
|
-
classOrId:
|
|
2174
|
-
});
|
|
2175
|
-
// 确保依赖已完全注入
|
|
2176
|
-
if (!finishedStage.has(dependency) && !this.singletonInstances.has(dependency)) {
|
|
2177
|
-
const diagnose = createDiagnose(DiagnoseCode.CO10013, targetDefinition.cls.name, dependency.name);
|
|
2178
|
-
throw new Error(stringifyDiagnose(diagnose));
|
|
2179
|
-
}
|
|
1844
|
+
classOrId: dependencyCls
|
|
1845
|
+
}, InjectType.constructor);
|
|
2180
1846
|
constructorArgs.push(depInstance);
|
|
2181
1847
|
}
|
|
2182
1848
|
}
|
|
1849
|
+
} else if (constructorInject.length > 1) {
|
|
1850
|
+
throw new Error(`${targetDefinition.cls.name}存在不止一个@constructorInject装饰器`);
|
|
2183
1851
|
}
|
|
2184
1852
|
// 2. 实例化,同时执行componentPostConstruct
|
|
2185
|
-
const instance = this.
|
|
1853
|
+
const instance = this.newComponent(application, instantiateDefinition, constructorArgs);
|
|
1854
|
+
dependencyGraph.makeEarlyCreated(instantiateDefinition);
|
|
1855
|
+
newCreateInstance.push(instance);
|
|
1856
|
+
// updateStage(targetDefinition.cls, InstantiateStage.UNINITIALIZED);
|
|
2186
1857
|
if (instantiateDefinition.isSingleton) {
|
|
2187
1858
|
newSingletonInstances.set(instantiateDefinition.cls, instance);
|
|
2188
1859
|
}
|
|
2189
|
-
targetClsInstanceMap.set(targetDefinition.cls, instance);
|
|
2190
|
-
instanceInstantiateClsMap.set(instance, instantiateDefinition.cls);
|
|
2191
|
-
instantiatingStage.delete(targetDefinition.cls);
|
|
2192
|
-
assignningStage.add(targetDefinition.cls);
|
|
2193
1860
|
// 3. 递归实例化field注入
|
|
2194
|
-
const
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
1861
|
+
const componentClasses = [instantiateDefinition.cls];
|
|
1862
|
+
let parentCls = Object.getPrototypeOf(instantiateDefinition.cls);
|
|
1863
|
+
while (application.iocComponentDefinition.existDefinition(parentCls)) {
|
|
1864
|
+
componentClasses.unshift(parentCls);
|
|
1865
|
+
parentCls = Object.getPrototypeOf(parentCls);
|
|
1866
|
+
}
|
|
1867
|
+
const autowiredFields = new Map();
|
|
1868
|
+
for (const declaringClass of componentClasses) {
|
|
1869
|
+
const fields = application.metadataRepository.listFieldByMetadataCls(declaringClass, Autowired);
|
|
1870
|
+
for (const field of fields) {
|
|
1871
|
+
const autowired = application.metadataRepository.listFieldKindMetadata(declaringClass, field, Autowired)[0];
|
|
1872
|
+
const qualifier = application.metadataRepository.listFieldKindMetadata(declaringClass, field, Qualifier)[0];
|
|
1873
|
+
// 子类同名字段覆盖父类,并按子类字段的位置注入。
|
|
1874
|
+
autowiredFields.delete(field);
|
|
1875
|
+
autowiredFields.set(field, {
|
|
1876
|
+
declaringClass,
|
|
1877
|
+
field,
|
|
1878
|
+
autowired,
|
|
1879
|
+
qualifier
|
|
1880
|
+
});
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
for (const {
|
|
1884
|
+
field,
|
|
1885
|
+
autowired,
|
|
1886
|
+
qualifier
|
|
1887
|
+
} of autowiredFields.values()) {
|
|
1888
|
+
const autowiredCls = autowired.value;
|
|
1889
|
+
if (autowiredCls === undefined) {
|
|
1890
|
+
instance[field] = undefined;
|
|
1891
|
+
continue;
|
|
2219
1892
|
}
|
|
1893
|
+
if (instantiateDefinition.isSingleton && autowiredCls === instantiateDefinition.cls) {
|
|
1894
|
+
// 检查自依赖:不能注入自己
|
|
1895
|
+
// TODO: 如果autowiredCls是instantiateDefinition.cls的祖先类或者子孙类怎么办?
|
|
1896
|
+
const diagnose = createDiagnose(DiagnoseCode.CO10012, instantiateDefinition.cls.name, field);
|
|
1897
|
+
printDiagnose(diagnose);
|
|
1898
|
+
instance[field] = undefined;
|
|
1899
|
+
continue;
|
|
1900
|
+
}
|
|
1901
|
+
const realAutowiredDef = application.iocComponentDefinition.resolve(autowiredCls, qualifier?.value);
|
|
1902
|
+
if (instantiateDefinition.isSingleton && realAutowiredDef.cls !== autowiredCls && realAutowiredDef.cls === instantiateDefinition.cls) {
|
|
1903
|
+
// 自身更好是注入类的唯一子类
|
|
1904
|
+
const diagnose = createDiagnose(DiagnoseCode.CO10012, instantiateDefinition.cls.name, field);
|
|
1905
|
+
printDiagnose(diagnose);
|
|
1906
|
+
instance[field] = undefined;
|
|
1907
|
+
continue;
|
|
1908
|
+
}
|
|
1909
|
+
instance[field] = instantiateComponent({
|
|
1910
|
+
classOrId: autowiredCls,
|
|
1911
|
+
qualifier: qualifier?.value
|
|
1912
|
+
}, InjectType.autowired);
|
|
1913
|
+
}
|
|
1914
|
+
// 4. autowired也注入完毕
|
|
1915
|
+
if (typeof instance['init'] === 'function') {
|
|
1916
|
+
instance['init']?.call(instance, application);
|
|
2220
1917
|
}
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
finishedStage.add(targetDefinition.cls);
|
|
1918
|
+
dependencyGraph.removeDependency(targetDefinition, instantiateDefinition);
|
|
1919
|
+
// updateStage(targetDefinition.cls, InstantiateStage.INITIALIZED);
|
|
2224
1920
|
return instance;
|
|
2225
1921
|
};
|
|
2226
1922
|
// TODO: 如果初始化多个,有没有先后顺序问题?
|
|
@@ -2229,22 +1925,12 @@ class IocComponentFactory {
|
|
|
2229
1925
|
if (newSingletonInstances.size > 0) {
|
|
2230
1926
|
for (const [cls, instance] of newSingletonInstances.entries()) {
|
|
2231
1927
|
this.singletonInstances.set(cls, instance);
|
|
2232
|
-
// 现在默认子类的singleton和父类都是保持一致的。TODO: 如果子类的singleton不是单例了,应该如何处理
|
|
2233
|
-
}
|
|
2234
|
-
}
|
|
2235
|
-
// 5. 所有新增的单例执行init方法
|
|
2236
|
-
for (const cls of finishedStage.keys()) {
|
|
2237
|
-
// 这里应该是根据instance来判断是否已经存在的
|
|
2238
|
-
const instance = targetClsInstanceMap.get(cls);
|
|
2239
|
-
if (typeof instance['init'] === 'function') {
|
|
2240
|
-
instance['init']?.call(instance, application);
|
|
2241
1928
|
}
|
|
2242
1929
|
}
|
|
2243
1930
|
// 执行start方法
|
|
2244
|
-
for (const
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
instance['start']?.call(instance, application);
|
|
1931
|
+
for (const ins of newCreateInstance) {
|
|
1932
|
+
if (typeof ins['start'] === 'function') {
|
|
1933
|
+
ins['start']?.call(ins, application);
|
|
2248
1934
|
}
|
|
2249
1935
|
}
|
|
2250
1936
|
return instance;
|
|
@@ -2255,8 +1941,8 @@ class IocComponentFactory {
|
|
|
2255
1941
|
const diagnose = createDiagnose(DiagnoseCode.CO10011, typeof viewClass === 'string' ? viewClass : viewClass.name);
|
|
2256
1942
|
throw new Error(stringifyDiagnose(diagnose));
|
|
2257
1943
|
}
|
|
2258
|
-
// 视图组件目前简单的认为全是prototype
|
|
2259
|
-
const instance = this.
|
|
1944
|
+
// 视图组件目前简单的认为全是prototype,且不支持实例化子组件,TODO:补充不支持继承的限制和测试用例
|
|
1945
|
+
const instance = this.newComponent(application, targetDefinition, [props]);
|
|
2260
1946
|
const autowiredFields = application.metadataRepository.listFieldByMetadataCls(targetDefinition.cls, Autowired);
|
|
2261
1947
|
for (const field of autowiredFields) {
|
|
2262
1948
|
const autowiredMetadatas = application.metadataRepository.listFieldKindMetadata(targetDefinition.cls, field, Autowired);
|
|
@@ -2400,17 +2086,17 @@ class Application {
|
|
|
2400
2086
|
this.propertiesConfig = new PropertiesConfig(jsonConfig);
|
|
2401
2087
|
}
|
|
2402
2088
|
/**
|
|
2403
|
-
*
|
|
2404
|
-
*
|
|
2089
|
+
* 应用模块在 start 前完成 AOT 注册;测试中的局部类可能在 Application 构造后才注册,
|
|
2090
|
+
* 因此 start 时统一解析注册表。
|
|
2405
2091
|
*/
|
|
2406
2092
|
start() {
|
|
2407
|
-
initDecoratorParamModule();
|
|
2408
|
-
//
|
|
2093
|
+
const runtimeDecoratorParams = initDecoratorParamModule();
|
|
2094
|
+
// 使用 AOT 解析完成的装饰器参数(runtimeDecoratorParams)初始化元数据仓库
|
|
2409
2095
|
const {
|
|
2410
2096
|
metadataRepository,
|
|
2411
2097
|
idClassMap,
|
|
2412
2098
|
componentMetadataClass
|
|
2413
|
-
} = initMetadataModule(
|
|
2099
|
+
} = initMetadataModule(runtimeDecoratorParams);
|
|
2414
2100
|
this.metadataRepository = metadataRepository;
|
|
2415
2101
|
this.idClassMap = idClassMap;
|
|
2416
2102
|
this.componentMetadataClass = componentMetadataClass;
|
|
@@ -2473,23 +2159,18 @@ class Application {
|
|
|
2473
2159
|
}
|
|
2474
2160
|
}
|
|
2475
2161
|
|
|
2476
|
-
let _initClass$q;
|
|
2477
2162
|
/**
|
|
2478
2163
|
* @public
|
|
2479
2164
|
*/
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
super(_Bind), _initClass$q();
|
|
2490
|
-
}
|
|
2491
|
-
}();
|
|
2492
|
-
var Bind = _Bind;
|
|
2165
|
+
class Bind extends Metadata {
|
|
2166
|
+
static $$id = "Bind";
|
|
2167
|
+
}
|
|
2168
|
+
registerComponent(Bind, [{
|
|
2169
|
+
metadataKind: "class",
|
|
2170
|
+
metadataClass: target.$$metadataClass,
|
|
2171
|
+
metadataParam: [Target.Type.Method],
|
|
2172
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
2173
|
+
}]);
|
|
2493
2174
|
|
|
2494
2175
|
var bind = createDecoratorExp(Bind, {
|
|
2495
2176
|
componentPostConstruct: function (metadata, application, target) {
|
|
@@ -2500,23 +2181,23 @@ var bind = createDecoratorExp(Bind, {
|
|
|
2500
2181
|
}
|
|
2501
2182
|
});
|
|
2502
2183
|
|
|
2503
|
-
let _initClass$p;
|
|
2504
2184
|
/**
|
|
2505
2185
|
* @public
|
|
2506
2186
|
*/
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2187
|
+
class Cookie extends Metadata {
|
|
2188
|
+
static $$id = "Cookie";
|
|
2189
|
+
}
|
|
2190
|
+
registerComponent(Cookie, [{
|
|
2191
|
+
metadataKind: "class",
|
|
2192
|
+
metadataClass: component.$$metadataClass,
|
|
2193
|
+
metadataParam: undefined,
|
|
2194
|
+
isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
|
|
2195
|
+
}, {
|
|
2196
|
+
metadataKind: "class",
|
|
2197
|
+
metadataClass: target.$$metadataClass,
|
|
2198
|
+
metadataParam: [Target.Type.Class],
|
|
2199
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
2200
|
+
}]);
|
|
2520
2201
|
|
|
2521
2202
|
var cookie = createDecoratorExp(Cookie);
|
|
2522
2203
|
|
|
@@ -2707,7 +2388,6 @@ function mapChildren(children, func, context) {
|
|
|
2707
2388
|
function forEachChildren(children, forEachFunc, forEachContext) {
|
|
2708
2389
|
mapChildren(children, function () {
|
|
2709
2390
|
forEachFunc.apply(this, arguments);
|
|
2710
|
-
// Don't return anything.
|
|
2711
2391
|
}, forEachContext);
|
|
2712
2392
|
}
|
|
2713
2393
|
|
|
@@ -2755,117 +2435,113 @@ const Children = {
|
|
|
2755
2435
|
forEach: forEachChildren,
|
|
2756
2436
|
};
|
|
2757
2437
|
|
|
2758
|
-
let _initClass$o;
|
|
2759
2438
|
/**
|
|
2760
2439
|
* @public
|
|
2761
2440
|
*/
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2441
|
+
class View extends Metadata {
|
|
2442
|
+
static $$id = "View";
|
|
2443
|
+
}
|
|
2444
|
+
registerComponent(View, [{
|
|
2445
|
+
metadataKind: "class",
|
|
2446
|
+
metadataClass: component.$$metadataClass,
|
|
2447
|
+
metadataParam: undefined,
|
|
2448
|
+
isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
|
|
2449
|
+
}, {
|
|
2450
|
+
metadataKind: "class",
|
|
2451
|
+
metadataClass: scope.$$metadataClass,
|
|
2452
|
+
metadataParam: SCOPE.Prototype,
|
|
2453
|
+
isPlaceholderDecoratorExp: scope.$$isPlaceholderDecoratorExp
|
|
2454
|
+
}, {
|
|
2455
|
+
metadataKind: "class",
|
|
2456
|
+
metadataClass: target.$$metadataClass,
|
|
2457
|
+
metadataParam: [Target.Type.Class],
|
|
2458
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
2459
|
+
}]);
|
|
2460
|
+
|
|
2461
|
+
var view = createDecoratorExp(View, {
|
|
2462
|
+
// 当@view作为类装饰时,实例化后给组件实例挂载updater,用于触发调度器
|
|
2463
|
+
// TODO: View的复合装饰器也要支持的吧
|
|
2464
|
+
componentPostConstruct() {
|
|
2465
|
+
if (!this.updater) {
|
|
2466
|
+
this.updater = ReactNoopUpdateQueue;
|
|
2774
2467
|
}
|
|
2775
|
-
}];
|
|
2776
|
-
$$id = "View";
|
|
2777
|
-
constructor() {
|
|
2778
|
-
super(_View), _initClass$o();
|
|
2779
2468
|
}
|
|
2780
|
-
}
|
|
2781
|
-
var View = _View;
|
|
2782
|
-
|
|
2783
|
-
var view = createDecoratorExp(View);
|
|
2469
|
+
});
|
|
2784
2470
|
|
|
2785
|
-
let _initClass$n;
|
|
2786
2471
|
/**
|
|
2787
2472
|
* @public
|
|
2788
2473
|
*/
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2474
|
+
class Layout extends Metadata {
|
|
2475
|
+
static $$id = "Layout";
|
|
2476
|
+
}
|
|
2477
|
+
registerComponent(Layout, [{
|
|
2478
|
+
metadataKind: "class",
|
|
2479
|
+
metadataClass: view.$$metadataClass,
|
|
2480
|
+
metadataParam: undefined,
|
|
2481
|
+
isPlaceholderDecoratorExp: view.$$isPlaceholderDecoratorExp
|
|
2482
|
+
}, {
|
|
2483
|
+
metadataKind: "class",
|
|
2484
|
+
metadataClass: target.$$metadataClass,
|
|
2485
|
+
metadataParam: [Target.Type.Class],
|
|
2486
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
2487
|
+
}]);
|
|
2802
2488
|
|
|
2803
2489
|
var layout = createDecoratorExp(Layout);
|
|
2804
2490
|
|
|
2805
|
-
let _initClass$m;
|
|
2806
2491
|
/**
|
|
2807
2492
|
* @public
|
|
2808
2493
|
*/
|
|
2809
|
-
let
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2494
|
+
let LocalStorage$1 = class LocalStorage extends Metadata {
|
|
2495
|
+
static $$id = "LocalStorage";
|
|
2496
|
+
};
|
|
2497
|
+
registerComponent(LocalStorage$1, [{
|
|
2498
|
+
metadataKind: "class",
|
|
2499
|
+
metadataClass: component.$$metadataClass,
|
|
2500
|
+
metadataParam: undefined,
|
|
2501
|
+
isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
|
|
2502
|
+
}, {
|
|
2503
|
+
metadataKind: "class",
|
|
2504
|
+
metadataClass: target.$$metadataClass,
|
|
2505
|
+
metadataParam: [Target.Type.Class],
|
|
2506
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
2507
|
+
}]);
|
|
2822
2508
|
|
|
2823
|
-
var localStorageDecorator = createDecoratorExp(LocalStorage);
|
|
2509
|
+
var localStorageDecorator = createDecoratorExp(LocalStorage$1);
|
|
2824
2510
|
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
setItem(key, value) {
|
|
2833
|
-
return localStorage.setItem(key, value);
|
|
2834
|
-
}
|
|
2835
|
-
getItem(key) {
|
|
2836
|
-
return localStorage.getItem(key);
|
|
2837
|
-
}
|
|
2838
|
-
removeItem(key) {
|
|
2839
|
-
return localStorage.removeItem(key);
|
|
2840
|
-
}
|
|
2841
|
-
key(index) {
|
|
2842
|
-
return localStorage.key(index);
|
|
2843
|
-
}
|
|
2844
|
-
}];
|
|
2845
|
-
$$id = "LocalStorage";
|
|
2846
|
-
constructor() {
|
|
2847
|
-
super(_LocalStorage), _initClass$l();
|
|
2511
|
+
class LocalStorage {
|
|
2512
|
+
static $$id = "LocalStorage";
|
|
2513
|
+
setItem(key, value) {
|
|
2514
|
+
return localStorage.setItem(key, value);
|
|
2515
|
+
}
|
|
2516
|
+
getItem(key) {
|
|
2517
|
+
return localStorage.getItem(key);
|
|
2848
2518
|
}
|
|
2849
|
-
|
|
2850
|
-
|
|
2519
|
+
removeItem(key) {
|
|
2520
|
+
return localStorage.removeItem(key);
|
|
2521
|
+
}
|
|
2522
|
+
key(index) {
|
|
2523
|
+
return localStorage.key(index);
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
registerComponent(LocalStorage, [{
|
|
2527
|
+
metadataKind: "class",
|
|
2528
|
+
metadataClass: localStorageDecorator.$$metadataClass,
|
|
2529
|
+
metadataParam: undefined,
|
|
2530
|
+
isPlaceholderDecoratorExp: localStorageDecorator.$$isPlaceholderDecoratorExp
|
|
2531
|
+
}]);
|
|
2851
2532
|
|
|
2852
|
-
let _initClass$k;
|
|
2853
2533
|
/**
|
|
2854
2534
|
* @public
|
|
2855
2535
|
*/
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
super(_Memoized), _initClass$k();
|
|
2866
|
-
}
|
|
2867
|
-
}();
|
|
2868
|
-
var Memoized = _Memoized;
|
|
2536
|
+
class Memoized extends Metadata {
|
|
2537
|
+
static $$id = "Memoized";
|
|
2538
|
+
}
|
|
2539
|
+
registerComponent(Memoized, [{
|
|
2540
|
+
metadataKind: "class",
|
|
2541
|
+
metadataClass: target.$$metadataClass,
|
|
2542
|
+
metadataParam: [Target.Type.Method, Target.Type.Field, Target.Type.Getter],
|
|
2543
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
2544
|
+
}]);
|
|
2869
2545
|
|
|
2870
2546
|
class Subscriber {
|
|
2871
2547
|
static Executing;
|
|
@@ -2935,49 +2611,57 @@ var memoized = createDecoratorExp(Memoized, {
|
|
|
2935
2611
|
const diagnose = createDiagnose(DiagnoseCode.CO10028, this.constructor.name, name, name, type);
|
|
2936
2612
|
console.error(stringifyDiagnose(diagnose));
|
|
2937
2613
|
}
|
|
2614
|
+
} else if (kind === KindGetter) {
|
|
2615
|
+
const descriptor = Object.getOwnPropertyDescriptor(this.constructor.prototype, name);
|
|
2616
|
+
const getter = descriptor?.get;
|
|
2617
|
+
if (typeof getter !== 'function') {
|
|
2618
|
+
console.error('不应该拿不到getter函数');
|
|
2619
|
+
return;
|
|
2620
|
+
}
|
|
2621
|
+
const subscriber = new Subscriber(getter.bind(this));
|
|
2622
|
+
const memoizedGetter = subscriber.memoizedFn;
|
|
2623
|
+
Object.defineProperty(this, name, {
|
|
2624
|
+
...descriptor,
|
|
2625
|
+
get: memoizedGetter
|
|
2626
|
+
});
|
|
2938
2627
|
} else ;
|
|
2939
2628
|
}
|
|
2940
2629
|
});
|
|
2941
2630
|
|
|
2942
|
-
let _initClass$j;
|
|
2943
2631
|
/**
|
|
2944
2632
|
* @public
|
|
2945
2633
|
*/
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2634
|
+
class Page extends Metadata {
|
|
2635
|
+
static $$id = "Page";
|
|
2636
|
+
}
|
|
2637
|
+
registerComponent(Page, [{
|
|
2638
|
+
metadataKind: "class",
|
|
2639
|
+
metadataClass: view.$$metadataClass,
|
|
2640
|
+
metadataParam: undefined,
|
|
2641
|
+
isPlaceholderDecoratorExp: view.$$isPlaceholderDecoratorExp
|
|
2642
|
+
}, {
|
|
2643
|
+
metadataKind: "class",
|
|
2644
|
+
metadataClass: target.$$metadataClass,
|
|
2645
|
+
metadataParam: [Target.Type.Class],
|
|
2646
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
2647
|
+
}]);
|
|
2959
2648
|
|
|
2960
2649
|
var page = createDecoratorExp(Page);
|
|
2961
2650
|
|
|
2962
|
-
let _initClass$i;
|
|
2963
2651
|
/**
|
|
2964
2652
|
* 加在field表明是响应式
|
|
2965
2653
|
* 加在metadata上用于自定义reactive元数据
|
|
2966
2654
|
* @public
|
|
2967
2655
|
*/
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
super(_Reactive), _initClass$i();
|
|
2978
|
-
}
|
|
2979
|
-
}();
|
|
2980
|
-
var Reactive = _Reactive;
|
|
2656
|
+
class Reactive extends Metadata {
|
|
2657
|
+
static $$id = "Reactive";
|
|
2658
|
+
}
|
|
2659
|
+
registerComponent(Reactive, [{
|
|
2660
|
+
metadataKind: "class",
|
|
2661
|
+
metadataClass: target.$$metadataClass,
|
|
2662
|
+
metadataParam: [Target.Type.Field],
|
|
2663
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
2664
|
+
}]);
|
|
2981
2665
|
|
|
2982
2666
|
class Publisher {
|
|
2983
2667
|
name;
|
|
@@ -3054,23 +2738,18 @@ var reactive = createDecoratorExp(Reactive, {
|
|
|
3054
2738
|
}
|
|
3055
2739
|
});
|
|
3056
2740
|
|
|
3057
|
-
let _initClass$h;
|
|
3058
2741
|
/**
|
|
3059
2742
|
* @public
|
|
3060
2743
|
*/
|
|
3061
|
-
let
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
super(_Ref), _initClass$h();
|
|
3071
|
-
}
|
|
3072
|
-
}();
|
|
3073
|
-
var Ref$1 = _Ref;
|
|
2744
|
+
let Ref$1 = class Ref extends Metadata {
|
|
2745
|
+
static $$id = "Ref";
|
|
2746
|
+
};
|
|
2747
|
+
registerComponent(Ref$1, [{
|
|
2748
|
+
metadataKind: "class",
|
|
2749
|
+
metadataClass: target.$$metadataClass,
|
|
2750
|
+
metadataParam: [Target.Type.Field],
|
|
2751
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
2752
|
+
}]);
|
|
3074
2753
|
|
|
3075
2754
|
var ref = createDecoratorExp(Ref$1, {
|
|
3076
2755
|
componentPostConstruct: function (metadata, application, target) {
|
|
@@ -3083,23 +2762,18 @@ var ref = createDecoratorExp(Ref$1, {
|
|
|
3083
2762
|
}
|
|
3084
2763
|
});
|
|
3085
2764
|
|
|
3086
|
-
let _initClass$g;
|
|
3087
2765
|
/**
|
|
3088
2766
|
* @public
|
|
3089
2767
|
*/
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
super(_Refs), _initClass$g();
|
|
3100
|
-
}
|
|
3101
|
-
}();
|
|
3102
|
-
var Refs = _Refs;
|
|
2768
|
+
class Refs extends Metadata {
|
|
2769
|
+
static $$id = "Refs";
|
|
2770
|
+
}
|
|
2771
|
+
registerComponent(Refs, [{
|
|
2772
|
+
metadataKind: "class",
|
|
2773
|
+
metadataClass: target.$$metadataClass,
|
|
2774
|
+
metadataParam: [Target.Type.Field],
|
|
2775
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
2776
|
+
}]);
|
|
3103
2777
|
|
|
3104
2778
|
var refs = createDecoratorExp(Refs, {
|
|
3105
2779
|
componentPostConstruct: function (metadata, application, target) {
|
|
@@ -3107,166 +2781,146 @@ var refs = createDecoratorExp(Refs, {
|
|
|
3107
2781
|
}
|
|
3108
2782
|
});
|
|
3109
2783
|
|
|
3110
|
-
let _initClass$f;
|
|
3111
2784
|
/**
|
|
3112
2785
|
* @public
|
|
3113
2786
|
*/
|
|
3114
|
-
let
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
2787
|
+
let SessionStorage$1 = class SessionStorage extends Metadata {
|
|
2788
|
+
static $$id = "SessionStorage";
|
|
2789
|
+
};
|
|
2790
|
+
registerComponent(SessionStorage$1, [{
|
|
2791
|
+
metadataKind: "class",
|
|
2792
|
+
metadataClass: component.$$metadataClass,
|
|
2793
|
+
metadataParam: undefined,
|
|
2794
|
+
isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
|
|
2795
|
+
}, {
|
|
2796
|
+
metadataKind: "class",
|
|
2797
|
+
metadataClass: target.$$metadataClass,
|
|
2798
|
+
metadataParam: [Target.Type.Class],
|
|
2799
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
2800
|
+
}]);
|
|
3127
2801
|
|
|
3128
|
-
var sessionStorageDecorator = createDecoratorExp(SessionStorage);
|
|
2802
|
+
var sessionStorageDecorator = createDecoratorExp(SessionStorage$1);
|
|
3129
2803
|
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
setItem(key, value) {
|
|
3138
|
-
return sessionStorage.setItem(key, value);
|
|
3139
|
-
}
|
|
3140
|
-
getItem(key) {
|
|
3141
|
-
return sessionStorage.getItem(key);
|
|
3142
|
-
}
|
|
3143
|
-
removeItem(key) {
|
|
3144
|
-
return sessionStorage.removeItem(key);
|
|
3145
|
-
}
|
|
3146
|
-
key(index) {
|
|
3147
|
-
return sessionStorage.key(index);
|
|
3148
|
-
}
|
|
3149
|
-
}];
|
|
3150
|
-
$$id = "SessionStorage";
|
|
3151
|
-
constructor() {
|
|
3152
|
-
super(_SessionStorage), _initClass$e();
|
|
2804
|
+
class SessionStorage {
|
|
2805
|
+
static $$id = "SessionStorage";
|
|
2806
|
+
setItem(key, value) {
|
|
2807
|
+
return sessionStorage.setItem(key, value);
|
|
2808
|
+
}
|
|
2809
|
+
getItem(key) {
|
|
2810
|
+
return sessionStorage.getItem(key);
|
|
3153
2811
|
}
|
|
3154
|
-
|
|
3155
|
-
|
|
2812
|
+
removeItem(key) {
|
|
2813
|
+
return sessionStorage.removeItem(key);
|
|
2814
|
+
}
|
|
2815
|
+
key(index) {
|
|
2816
|
+
return sessionStorage.key(index);
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
registerComponent(SessionStorage, [{
|
|
2820
|
+
metadataKind: "class",
|
|
2821
|
+
metadataClass: sessionStorageDecorator.$$metadataClass,
|
|
2822
|
+
metadataParam: undefined,
|
|
2823
|
+
isPlaceholderDecoratorExp: sessionStorageDecorator.$$isPlaceholderDecoratorExp
|
|
2824
|
+
}]);
|
|
3156
2825
|
|
|
3157
|
-
let _initClass$d;
|
|
3158
2826
|
/**
|
|
3159
2827
|
* @public
|
|
3160
2828
|
*/
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
2829
|
+
class Store extends Metadata {
|
|
2830
|
+
static $$id = "Store";
|
|
2831
|
+
}
|
|
2832
|
+
registerComponent(Store, [{
|
|
2833
|
+
metadataKind: "class",
|
|
2834
|
+
metadataClass: component.$$metadataClass,
|
|
2835
|
+
metadataParam: undefined,
|
|
2836
|
+
isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
|
|
2837
|
+
}, {
|
|
2838
|
+
metadataKind: "class",
|
|
2839
|
+
metadataClass: target.$$metadataClass,
|
|
2840
|
+
metadataParam: [Target.Type.Class],
|
|
2841
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
2842
|
+
}]);
|
|
3174
2843
|
|
|
3175
2844
|
var store = createDecoratorExp(Store);
|
|
3176
2845
|
|
|
3177
|
-
let
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
2846
|
+
let Router$1 = class Router extends Metadata {
|
|
2847
|
+
static $$id = "Router";
|
|
2848
|
+
};
|
|
2849
|
+
registerComponent(Router$1, [{
|
|
2850
|
+
metadataKind: "class",
|
|
2851
|
+
metadataClass: component.$$metadataClass,
|
|
2852
|
+
metadataParam: undefined,
|
|
2853
|
+
isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
|
|
2854
|
+
}, {
|
|
2855
|
+
metadataKind: "class",
|
|
2856
|
+
metadataClass: target.$$metadataClass,
|
|
2857
|
+
metadataParam: [Target.Type.Class],
|
|
2858
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
2859
|
+
}]);
|
|
3191
2860
|
|
|
3192
|
-
let _initClass$b;
|
|
3193
2861
|
/**
|
|
3194
2862
|
* @public
|
|
3195
2863
|
*/
|
|
3196
|
-
let
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
super(_Route$1), _initClass$b();
|
|
3207
|
-
}
|
|
3208
|
-
}();
|
|
3209
|
-
var RouteMeta = _Route$1;
|
|
2864
|
+
let Route$1 = class Route extends Metadata {
|
|
2865
|
+
static $$id = "Route";
|
|
2866
|
+
value;
|
|
2867
|
+
};
|
|
2868
|
+
registerComponent(Route$1, [{
|
|
2869
|
+
metadataKind: "class",
|
|
2870
|
+
metadataClass: target.$$metadataClass,
|
|
2871
|
+
metadataParam: [Target.Type.Class],
|
|
2872
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
2873
|
+
}]);
|
|
3210
2874
|
|
|
3211
|
-
var route = createDecoratorExp(
|
|
2875
|
+
var route = createDecoratorExp(Route$1);
|
|
3212
2876
|
|
|
3213
2877
|
var router = createDecoratorExp(Router$1);
|
|
3214
2878
|
|
|
3215
|
-
let _initClass$a;
|
|
3216
2879
|
/**
|
|
3217
2880
|
* @public
|
|
3218
2881
|
*/
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
super(_Render$1), _initClass$9();
|
|
3247
|
-
}
|
|
3248
|
-
}();
|
|
3249
|
-
var Render$1 = _Render$1;
|
|
2882
|
+
class Router {
|
|
2883
|
+
static $$id = "Router";
|
|
2884
|
+
route;
|
|
2885
|
+
render;
|
|
2886
|
+
routeComponentMapper;
|
|
2887
|
+
}
|
|
2888
|
+
registerComponent(Router, [{
|
|
2889
|
+
metadataKind: "class",
|
|
2890
|
+
metadataClass: router.$$metadataClass,
|
|
2891
|
+
metadataParam: undefined,
|
|
2892
|
+
isPlaceholderDecoratorExp: router.$$isPlaceholderDecoratorExp
|
|
2893
|
+
}]);
|
|
2894
|
+
|
|
2895
|
+
let Render$1 = class Render extends Metadata {
|
|
2896
|
+
static $$id = "Render";
|
|
2897
|
+
};
|
|
2898
|
+
registerComponent(Render$1, [{
|
|
2899
|
+
metadataKind: "class",
|
|
2900
|
+
metadataClass: component.$$metadataClass,
|
|
2901
|
+
metadataParam: undefined,
|
|
2902
|
+
isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
|
|
2903
|
+
}, {
|
|
2904
|
+
metadataKind: "class",
|
|
2905
|
+
metadataClass: target.$$metadataClass,
|
|
2906
|
+
metadataParam: [Target.Type.Class],
|
|
2907
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
2908
|
+
}]);
|
|
3250
2909
|
|
|
3251
2910
|
var render$1 = createDecoratorExp(Render$1);
|
|
3252
2911
|
|
|
3253
|
-
let _initClass$8;
|
|
3254
2912
|
/**
|
|
3255
2913
|
* @public
|
|
3256
2914
|
*/
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
super(_Render), _initClass$8();
|
|
3267
|
-
}
|
|
3268
|
-
}();
|
|
3269
|
-
var Render = _Render;
|
|
2915
|
+
class Render {
|
|
2916
|
+
static $$id = "Render";
|
|
2917
|
+
}
|
|
2918
|
+
registerComponent(Render, [{
|
|
2919
|
+
metadataKind: "class",
|
|
2920
|
+
metadataClass: render$1.$$metadataClass,
|
|
2921
|
+
metadataParam: undefined,
|
|
2922
|
+
isPlaceholderDecoratorExp: render$1.$$isPlaceholderDecoratorExp
|
|
2923
|
+
}]);
|
|
3270
2924
|
|
|
3271
2925
|
/**
|
|
3272
2926
|
* Mapping from registration name to event name
|
|
@@ -3275,7 +2929,6 @@ const registrationNameDependencies = {};
|
|
|
3275
2929
|
const allNativeEvents = new Set();
|
|
3276
2930
|
function registerTwoPhaseEvent(registrationName, dependencies) {
|
|
3277
2931
|
registerDirectEvent(registrationName, dependencies);
|
|
3278
|
-
// registerDirectEvent(registrationName + 'Capture', dependencies);
|
|
3279
2932
|
}
|
|
3280
2933
|
function registerDirectEvent(registrationName, dependencies) {
|
|
3281
2934
|
registrationNameDependencies[registrationName] = dependencies;
|
|
@@ -4735,7 +4388,6 @@ function executeDispatch(domEvent, listener, currentTarget, reactEventType) {
|
|
|
4735
4388
|
domEvent.stopPropagation();
|
|
4736
4389
|
},
|
|
4737
4390
|
});
|
|
4738
|
-
// domEvent.currentTarget = null;
|
|
4739
4391
|
}
|
|
4740
4392
|
function processDispatchQueueItemsInOrder(domEvent, dispatchListeners, inCapturePhase, reactEventType) {
|
|
4741
4393
|
if (inCapturePhase) {
|
|
@@ -6300,7 +5952,9 @@ function initProps(instance, newProps) {
|
|
|
6300
5952
|
continue;
|
|
6301
5953
|
}
|
|
6302
5954
|
_values[field] = newProps[field];
|
|
6303
|
-
definePublisher(instance.props, field, function getter() {
|
|
5955
|
+
definePublisher(instance.props, field, function getter() {
|
|
5956
|
+
return _values[field];
|
|
5957
|
+
}, function setter(object, key, newValue) {
|
|
6304
5958
|
_values[field] = newValue;
|
|
6305
5959
|
});
|
|
6306
5960
|
}
|
|
@@ -6352,7 +6006,7 @@ const storeComponentUpdater = {
|
|
|
6352
6006
|
scheduleUpdateOnFiber(root, viewComponentFiber, viewInstance);
|
|
6353
6007
|
}
|
|
6354
6008
|
}
|
|
6355
|
-
}
|
|
6009
|
+
},
|
|
6356
6010
|
};
|
|
6357
6011
|
function reactiveStoreField(ctor, viewComponent) {
|
|
6358
6012
|
const { application } = getCommonApi();
|
|
@@ -6371,7 +6025,7 @@ function reactiveStoreField(ctor, viewComponent) {
|
|
|
6371
6025
|
},
|
|
6372
6026
|
set() {
|
|
6373
6027
|
console.error('store实例在初始化之后不允许修改');
|
|
6374
|
-
}
|
|
6028
|
+
},
|
|
6375
6029
|
});
|
|
6376
6030
|
}
|
|
6377
6031
|
});
|
|
@@ -6925,7 +6579,6 @@ function insertOrAppendPlacementNodeIntoContainer(node, before, parent) {
|
|
|
6925
6579
|
sibling = sibling.sibling;
|
|
6926
6580
|
}
|
|
6927
6581
|
}
|
|
6928
|
-
// throw new Error('todo')
|
|
6929
6582
|
}
|
|
6930
6583
|
}
|
|
6931
6584
|
function detachFiberMutation(fiber) {
|
|
@@ -7096,7 +6749,6 @@ function commitMutationEffectsOnFiber(finishedWork, root) {
|
|
|
7096
6749
|
resetTextContent(instance);
|
|
7097
6750
|
}
|
|
7098
6751
|
catch (error) {
|
|
7099
|
-
// todo captureCommitPhaseError(finishedWork, finishedWork.return, error);
|
|
7100
6752
|
}
|
|
7101
6753
|
}
|
|
7102
6754
|
if (flags & Update) {
|
|
@@ -7784,34 +7436,29 @@ function render(element, container) {
|
|
|
7784
7436
|
return legacyRenderSubtreeIntoContainer(null, element, container);
|
|
7785
7437
|
}
|
|
7786
7438
|
|
|
7787
|
-
let _initClass$7;
|
|
7788
7439
|
/**
|
|
7789
7440
|
* @public
|
|
7790
7441
|
*/
|
|
7791
|
-
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
|
|
7797
|
-
container
|
|
7798
|
-
|
|
7799
|
-
registerCommonApi(application);
|
|
7800
|
-
this.container = document.getElementById('root');
|
|
7801
|
-
if (!this.container) {
|
|
7802
|
-
console.error('未找到根节点');
|
|
7803
|
-
}
|
|
7804
|
-
}
|
|
7805
|
-
render(component) {
|
|
7806
|
-
return render(jsx(component, undefined), this.container);
|
|
7442
|
+
class WebRender extends Render {
|
|
7443
|
+
static $$id = "WebRender";
|
|
7444
|
+
container;
|
|
7445
|
+
init(application) {
|
|
7446
|
+
registerCommonApi(application);
|
|
7447
|
+
this.container = document.getElementById('root');
|
|
7448
|
+
if (!this.container) {
|
|
7449
|
+
console.error('未找到根节点');
|
|
7807
7450
|
}
|
|
7808
|
-
}];
|
|
7809
|
-
$$id = "WebRender";
|
|
7810
|
-
constructor() {
|
|
7811
|
-
super(_WebRender), _initClass$7();
|
|
7812
7451
|
}
|
|
7813
|
-
|
|
7814
|
-
|
|
7452
|
+
render(component) {
|
|
7453
|
+
return render(jsx(component, undefined), this.container);
|
|
7454
|
+
}
|
|
7455
|
+
}
|
|
7456
|
+
registerComponent(WebRender, [{
|
|
7457
|
+
metadataKind: "class",
|
|
7458
|
+
metadataClass: render$1.$$metadataClass,
|
|
7459
|
+
metadataParam: undefined,
|
|
7460
|
+
isPlaceholderDecoratorExp: render$1.$$isPlaceholderDecoratorExp
|
|
7461
|
+
}]);
|
|
7815
7462
|
|
|
7816
7463
|
class DynamicRoute {
|
|
7817
7464
|
regExp;
|
|
@@ -7894,176 +7541,176 @@ class RouteComponentMapper {
|
|
|
7894
7541
|
}
|
|
7895
7542
|
}
|
|
7896
7543
|
|
|
7897
|
-
|
|
7898
|
-
|
|
7899
|
-
|
|
7900
|
-
|
|
7901
|
-
|
|
7902
|
-
|
|
7903
|
-
|
|
7904
|
-
|
|
7905
|
-
|
|
7906
|
-
|
|
7907
|
-
|
|
7908
|
-
|
|
7909
|
-
|
|
7910
|
-
constructor() {
|
|
7911
|
-
super(_Route), _initClass$6();
|
|
7912
|
-
}
|
|
7913
|
-
}();
|
|
7914
|
-
var Route = _Route;
|
|
7544
|
+
class Route {
|
|
7545
|
+
static $$id = "Route";
|
|
7546
|
+
// window.location.pathname
|
|
7547
|
+
pathname;
|
|
7548
|
+
// 动态路由参数
|
|
7549
|
+
params = {};
|
|
7550
|
+
}
|
|
7551
|
+
registerComponent(Route, [{
|
|
7552
|
+
metadataKind: "class",
|
|
7553
|
+
metadataClass: component.$$metadataClass,
|
|
7554
|
+
metadataParam: undefined,
|
|
7555
|
+
isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
|
|
7556
|
+
}]);
|
|
7915
7557
|
|
|
7916
|
-
let _initClass$5;
|
|
7917
7558
|
/**
|
|
7918
7559
|
* @public
|
|
7919
7560
|
*/
|
|
7920
|
-
|
|
7921
|
-
|
|
7922
|
-
|
|
7923
|
-
|
|
7924
|
-
|
|
7925
|
-
|
|
7926
|
-
|
|
7927
|
-
|
|
7928
|
-
|
|
7929
|
-
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7933
|
-
|
|
7934
|
-
|
|
7935
|
-
|
|
7936
|
-
this.route.pathname = pathname;
|
|
7937
|
-
this.route.params = params || {};
|
|
7938
|
-
if (pageComponent) {
|
|
7939
|
-
this.render.render(pageComponent);
|
|
7940
|
-
}
|
|
7941
|
-
};
|
|
7942
|
-
init(application) {
|
|
7943
|
-
const routeComponentMap = application.listBeDecoratedClsByClassKindMetadata(RouteMeta);
|
|
7944
|
-
this.routeComponentMapper = new RouteComponentMapper();
|
|
7945
|
-
this.routeComponentMapper.init(routeComponentMap);
|
|
7946
|
-
this.route = application.getComponent(Route);
|
|
7947
|
-
}
|
|
7948
|
-
start() {
|
|
7949
|
-
window.addEventListener('popstate', this.handleRouteChange);
|
|
7950
|
-
// 初始化渲染
|
|
7951
|
-
this.handleRouteChange();
|
|
7952
|
-
}
|
|
7953
|
-
removeListener() {
|
|
7954
|
-
window.removeEventListener('popstate', this.handleRouteChange);
|
|
7955
|
-
}
|
|
7956
|
-
navigateTo(url) {
|
|
7957
|
-
window.history.pushState({}, '', url);
|
|
7958
|
-
this.handleRouteChange();
|
|
7561
|
+
class HistoryRouter extends Router {
|
|
7562
|
+
static $$id = "HistoryRouter";
|
|
7563
|
+
constructor(render) {
|
|
7564
|
+
super();
|
|
7565
|
+
this.render = render;
|
|
7566
|
+
}
|
|
7567
|
+
handleRouteChange = () => {
|
|
7568
|
+
const pathname = window.location.pathname;
|
|
7569
|
+
const {
|
|
7570
|
+
pageComponent,
|
|
7571
|
+
params
|
|
7572
|
+
} = this.routeComponentMapper.match(pathname);
|
|
7573
|
+
this.route.pathname = pathname;
|
|
7574
|
+
this.route.params = params || {};
|
|
7575
|
+
if (pageComponent) {
|
|
7576
|
+
this.render.render(pageComponent);
|
|
7959
7577
|
}
|
|
7960
|
-
}
|
|
7961
|
-
|
|
7962
|
-
|
|
7963
|
-
|
|
7578
|
+
};
|
|
7579
|
+
init(application) {
|
|
7580
|
+
const routeComponentMap = application.listBeDecoratedClsByClassKindMetadata(Route$1);
|
|
7581
|
+
this.routeComponentMapper = new RouteComponentMapper();
|
|
7582
|
+
this.routeComponentMapper.init(routeComponentMap);
|
|
7583
|
+
this.route = application.getComponent(Route);
|
|
7584
|
+
}
|
|
7585
|
+
start() {
|
|
7586
|
+
window.addEventListener('popstate', this.handleRouteChange);
|
|
7587
|
+
// 初始化渲染
|
|
7588
|
+
this.handleRouteChange();
|
|
7589
|
+
}
|
|
7590
|
+
removeListener() {
|
|
7591
|
+
window.removeEventListener('popstate', this.handleRouteChange);
|
|
7964
7592
|
}
|
|
7965
|
-
|
|
7966
|
-
|
|
7593
|
+
navigateTo(url) {
|
|
7594
|
+
window.history.pushState({}, '', url);
|
|
7595
|
+
this.handleRouteChange();
|
|
7596
|
+
}
|
|
7597
|
+
}
|
|
7598
|
+
registerComponent(HistoryRouter, [{
|
|
7599
|
+
metadataKind: "class",
|
|
7600
|
+
metadataClass: constructorInject.$$metadataClass,
|
|
7601
|
+
metadataParam: [Render],
|
|
7602
|
+
isPlaceholderDecoratorExp: constructorInject.$$isPlaceholderDecoratorExp
|
|
7603
|
+
}, {
|
|
7604
|
+
metadataKind: "class",
|
|
7605
|
+
metadataClass: router.$$metadataClass,
|
|
7606
|
+
metadataParam: undefined,
|
|
7607
|
+
isPlaceholderDecoratorExp: router.$$isPlaceholderDecoratorExp
|
|
7608
|
+
}]);
|
|
7967
7609
|
|
|
7968
|
-
let _initClass$4;
|
|
7969
7610
|
/**
|
|
7970
7611
|
* @public
|
|
7971
7612
|
*/
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
|
|
7975
|
-
|
|
7976
|
-
|
|
7977
|
-
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
7983
|
-
|
|
7984
|
-
|
|
7613
|
+
class Util extends Metadata {
|
|
7614
|
+
static $$id = "Util";
|
|
7615
|
+
}
|
|
7616
|
+
registerComponent(Util, [{
|
|
7617
|
+
metadataKind: "class",
|
|
7618
|
+
metadataClass: component.$$metadataClass,
|
|
7619
|
+
metadataParam: undefined,
|
|
7620
|
+
isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
|
|
7621
|
+
}, {
|
|
7622
|
+
metadataKind: "class",
|
|
7623
|
+
metadataClass: target.$$metadataClass,
|
|
7624
|
+
metadataParam: [Target.Type.Class],
|
|
7625
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
7626
|
+
}]);
|
|
7985
7627
|
|
|
7986
7628
|
var util = createDecoratorExp(Util);
|
|
7987
7629
|
|
|
7988
|
-
let _initClass$3;
|
|
7989
7630
|
/**
|
|
7990
7631
|
* @public
|
|
7991
7632
|
*/
|
|
7992
|
-
|
|
7993
|
-
|
|
7994
|
-
|
|
7995
|
-
|
|
7996
|
-
|
|
7997
|
-
|
|
7998
|
-
|
|
7999
|
-
|
|
8000
|
-
|
|
8001
|
-
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
|
|
7633
|
+
class Api extends Metadata {
|
|
7634
|
+
static $$id = "Api";
|
|
7635
|
+
}
|
|
7636
|
+
registerComponent(Api, [{
|
|
7637
|
+
metadataKind: "class",
|
|
7638
|
+
metadataClass: util.$$metadataClass,
|
|
7639
|
+
metadataParam: undefined,
|
|
7640
|
+
isPlaceholderDecoratorExp: util.$$isPlaceholderDecoratorExp
|
|
7641
|
+
}, {
|
|
7642
|
+
metadataKind: "class",
|
|
7643
|
+
metadataClass: target.$$metadataClass,
|
|
7644
|
+
metadataParam: [Target.Type.Class],
|
|
7645
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
7646
|
+
}]);
|
|
8005
7647
|
|
|
8006
7648
|
var api = createDecoratorExp(Api);
|
|
8007
7649
|
|
|
8008
|
-
let _initClass$2;
|
|
8009
7650
|
/**
|
|
8010
7651
|
* @public
|
|
8011
7652
|
*/
|
|
8012
|
-
|
|
8013
|
-
|
|
8014
|
-
|
|
8015
|
-
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
|
|
8019
|
-
|
|
8020
|
-
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8024
|
-
|
|
8025
|
-
|
|
8026
|
-
|
|
7653
|
+
class Service extends Metadata {
|
|
7654
|
+
static $$id = "Service";
|
|
7655
|
+
}
|
|
7656
|
+
registerComponent(Service, [{
|
|
7657
|
+
metadataKind: "class",
|
|
7658
|
+
metadataClass: scope.$$metadataClass,
|
|
7659
|
+
metadataParam: SCOPE.Prototype,
|
|
7660
|
+
isPlaceholderDecoratorExp: scope.$$isPlaceholderDecoratorExp
|
|
7661
|
+
}, {
|
|
7662
|
+
metadataKind: "class",
|
|
7663
|
+
metadataClass: component.$$metadataClass,
|
|
7664
|
+
metadataParam: undefined,
|
|
7665
|
+
isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
|
|
7666
|
+
}, {
|
|
7667
|
+
metadataKind: "class",
|
|
7668
|
+
metadataClass: target.$$metadataClass,
|
|
7669
|
+
metadataParam: [Target.Type.Class],
|
|
7670
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
7671
|
+
}]);
|
|
7672
|
+
|
|
7673
|
+
var service = createDecoratorExp(Service);
|
|
8027
7674
|
|
|
8028
|
-
let _initClass$1;
|
|
8029
7675
|
// TODO: view 包添加 viewData装饰器
|
|
8030
7676
|
/**
|
|
8031
7677
|
* @public
|
|
8032
7678
|
*/
|
|
8033
|
-
|
|
8034
|
-
|
|
8035
|
-
|
|
8036
|
-
|
|
8037
|
-
|
|
8038
|
-
|
|
8039
|
-
|
|
8040
|
-
|
|
8041
|
-
|
|
8042
|
-
|
|
8043
|
-
|
|
8044
|
-
|
|
8045
|
-
|
|
7679
|
+
class GlobalData extends Metadata {
|
|
7680
|
+
static $$id = "GlobalData";
|
|
7681
|
+
}
|
|
7682
|
+
registerComponent(GlobalData, [{
|
|
7683
|
+
metadataKind: "class",
|
|
7684
|
+
metadataClass: component.$$metadataClass,
|
|
7685
|
+
metadataParam: undefined,
|
|
7686
|
+
isPlaceholderDecoratorExp: component.$$isPlaceholderDecoratorExp
|
|
7687
|
+
}, {
|
|
7688
|
+
metadataKind: "class",
|
|
7689
|
+
metadataClass: target.$$metadataClass,
|
|
7690
|
+
metadataParam: [Target.Type.Class],
|
|
7691
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
7692
|
+
}]);
|
|
8046
7693
|
|
|
8047
7694
|
var globalData = createDecoratorExp(GlobalData);
|
|
8048
7695
|
|
|
8049
|
-
let _initClass;
|
|
8050
7696
|
/**
|
|
8051
7697
|
* @public
|
|
8052
7698
|
*/
|
|
8053
|
-
|
|
8054
|
-
|
|
8055
|
-
|
|
8056
|
-
|
|
8057
|
-
|
|
8058
|
-
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
|
|
8062
|
-
|
|
8063
|
-
|
|
8064
|
-
|
|
8065
|
-
|
|
7699
|
+
class WebApplication extends Metadata {
|
|
7700
|
+
static $$id = "WebApplication";
|
|
7701
|
+
}
|
|
7702
|
+
registerComponent(WebApplication, [{
|
|
7703
|
+
metadataKind: "class",
|
|
7704
|
+
metadataClass: configuration.$$metadataClass,
|
|
7705
|
+
metadataParam: undefined,
|
|
7706
|
+
isPlaceholderDecoratorExp: configuration.$$isPlaceholderDecoratorExp
|
|
7707
|
+
}, {
|
|
7708
|
+
metadataKind: "class",
|
|
7709
|
+
metadataClass: target.$$metadataClass,
|
|
7710
|
+
metadataParam: [Target.Type.Class],
|
|
7711
|
+
isPlaceholderDecoratorExp: target.$$isPlaceholderDecoratorExp
|
|
7712
|
+
}]);
|
|
8066
7713
|
|
|
8067
7714
|
var webApplication = createDecoratorExp(WebApplication);
|
|
8068
7715
|
|
|
8069
|
-
export { Api, Application, Autowired, Bind, Children, Component, Configuration, ConstructorInject, Cookie,
|
|
7716
|
+
export { Api, Application, Autowired, Bind, Children, Component, Configuration, ConstructorInject, Cookie, GlobalData, HistoryRouter, Id, KindClass, KindField, KindMethod, Layout, LocalStorage, LocalStorage$1 as LocalStorageMeta, Memoized, Metadata, Page, PropertiesConfig, Qualifier, ReactNoopUpdateQueue, Reactive, Ref$1 as Ref, Refs, Render, Route, Route$1 as RouteMeta, Router, Router$1 as RouterMeta, SCOPE, Scope, Service, SessionStorage, SessionStorage$1 as SessionStorageMeta, Store, Target, Util, Value, View, WebApplication, WebRender, api, autowired, bind, bindPlaceholderMetadataClass, component, configuration, constructorInject, cookie, createDecoratorExp, definePublisher, getRegistry, globalData, id, jsx, jsx as jsxs, layout, localStorageDecorator as localStorage, memoized, metadataFor, page, qualifier, reactive, ref, refs, registerComponent, route, scope, service, sessionStorageDecorator as sessionStorage, store, target, util, value, view, webApplication };
|