@cocojs/mvc 0.1.0-beta.14 → 0.1.0-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.cjs.js +861 -1258
- package/dist/index.d.ts +140 -83
- package/dist/index.esm.js +849 -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
|
-
}
|
|
314
|
+
const createdDecoratorSetKey = Symbol.for('coco.createdDecoratorMetadataSet');
|
|
315
|
+
const globalObject = globalThis;
|
|
316
|
+
if (!globalObject[createdDecoratorSetKey]) {
|
|
317
|
+
globalObject[createdDecoratorSetKey] = new Set();
|
|
442
318
|
}
|
|
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
|
-
}
|
|
490
|
-
}
|
|
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,185 +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
|
-
case KindGetter:
|
|
623
|
-
break;
|
|
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
|
-
case KindGetter:
|
|
634
|
-
fn(isPlaceholderExp, this.constructor, {
|
|
635
|
-
metadataKind: context.kind,
|
|
636
|
-
metadataClass: MetaClsOrPlaceholderMetaCls,
|
|
637
|
-
metadataParam: userParam,
|
|
638
|
-
field: context.name
|
|
639
|
-
});
|
|
640
|
-
break;
|
|
641
|
-
}
|
|
642
|
-
});
|
|
643
|
-
context.addInitializer(function () {
|
|
644
|
-
execOnce(this);
|
|
645
|
-
});
|
|
646
|
-
return undefined;
|
|
336
|
+
return function (_beDecoratedCls, _context) {
|
|
337
|
+
// 普通装饰器表达式正常应由 AOT 编译期转换为 registerComponent 注册代码,
|
|
338
|
+
// 运行到这里说明代码未经 @cocojs/compiler 编译。
|
|
339
|
+
throw new Error('装饰器不应在运行时执行,请先使用 @cocojs/compiler 编译后再运行。');
|
|
647
340
|
};
|
|
648
341
|
}
|
|
649
342
|
if (isPlaceholderExp) {
|
|
650
|
-
|
|
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;
|
|
651
353
|
}
|
|
652
|
-
return doCreateDecoratorExp;
|
|
653
354
|
};
|
|
654
355
|
}
|
|
655
|
-
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
|
+
}
|
|
656
373
|
/**
|
|
657
|
-
*
|
|
658
|
-
*
|
|
374
|
+
* 建立占位元数据类与真实元数据类的关联。
|
|
375
|
+
* 由 `@metadataFor(X)` 经 AOT 编译后调用。
|
|
659
376
|
* @public
|
|
660
377
|
*/
|
|
661
|
-
function
|
|
662
|
-
|
|
663
|
-
|
|
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();
|
|
664
393
|
}
|
|
665
|
-
return
|
|
394
|
+
return globalObject[registryKey];
|
|
666
395
|
}
|
|
667
396
|
/**
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
*
|
|
397
|
+
* 全局静态注册函数。编译期由 coco-compiler 注入到每个源文件末尾。
|
|
398
|
+
* 源码中类、字段、方法、getter 上的装饰器经 AOT 编译后统一转换为对它的调用,
|
|
399
|
+
* 用于保存原始装饰器参数。
|
|
400
|
+
* `@metadataFor(X)` 不产生注册参数,只额外生成 bindPlaceholderMetadataClass 调用。
|
|
671
401
|
* @public
|
|
672
402
|
*/
|
|
673
|
-
function
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
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;
|
|
677
448
|
}
|
|
678
449
|
|
|
679
450
|
/**
|
|
680
451
|
* 装饰器表达式模块的工作流
|
|
681
452
|
*/
|
|
682
453
|
function initDecoratorParamModule() {
|
|
683
|
-
//
|
|
684
|
-
|
|
685
|
-
/**
|
|
686
|
-
* TODO: 如果view组件的state需要用到props初始化的话,会导致报错,例如:
|
|
687
|
-
* class {
|
|
688
|
-
* constructor(props){
|
|
689
|
-
* this.name = props.name // 这里会报错
|
|
690
|
-
* }
|
|
691
|
-
* }
|
|
692
|
-
*/
|
|
693
|
-
new Cls();
|
|
694
|
-
}
|
|
695
|
-
// 创建的装饰器表达式的选项,将占位的元数据类替换成真实的元数据类
|
|
454
|
+
// start 时把userDecoratorParams解析为runtimeDecoratorParams并校验,覆盖 Application 构造后声明的局部类。
|
|
455
|
+
const userDecoratorParams = getRegistry();
|
|
696
456
|
mergePlaceholderClass2RealMetadataClassRelation();
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
if (!isCocoClass(beDecoratedClass)) {
|
|
702
|
-
throw new Error(`所有被装饰器的对象${beDecoratedClass?.name}必须都是类或者类字段或类方法,且必须存在静态$$id字段。`);
|
|
703
|
-
}
|
|
704
|
-
}
|
|
457
|
+
const runtimeDecoratorParams = createRuntimeDecoratorParams(userDecoratorParams);
|
|
458
|
+
// 注册表的职责是“待启动消费的注册信息”,解析完成后清空,避免重复消费上一次的注册
|
|
459
|
+
userDecoratorParams.clear();
|
|
460
|
+
return runtimeDecoratorParams;
|
|
705
461
|
}
|
|
706
462
|
function clearDecoratorParamModule() {
|
|
707
463
|
clear$1();
|
|
708
|
-
clear$2();
|
|
709
464
|
}
|
|
710
465
|
|
|
711
466
|
/**
|
|
@@ -721,68 +476,54 @@ var Type;
|
|
|
721
476
|
/**
|
|
722
477
|
* @public
|
|
723
478
|
*/
|
|
724
|
-
const target =
|
|
479
|
+
const target = createDecoratorExp();
|
|
725
480
|
|
|
726
|
-
let _initClass$z;
|
|
727
481
|
/**
|
|
728
482
|
* @public
|
|
729
483
|
*/
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
static
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
}();
|
|
744
|
-
var Target = _Target;
|
|
745
|
-
|
|
746
|
-
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
|
+
|
|
747
497
|
/**
|
|
748
498
|
* @public
|
|
749
499
|
*/
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
super(_Autowired), _initClass$y();
|
|
761
|
-
}
|
|
762
|
-
}();
|
|
763
|
-
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
|
+
}]);
|
|
764
510
|
|
|
765
511
|
// TODO: cls?: Class<any>如果去掉的话,在项目中会报错,应该是ts-server是拿到参数了,但是声明中确没有
|
|
766
512
|
var autowired = createDecoratorExp(Autowired);
|
|
767
513
|
|
|
768
|
-
let _initClass$x;
|
|
769
514
|
/**
|
|
770
515
|
* @public
|
|
771
516
|
*/
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
super(_Id), _initClass$x();
|
|
783
|
-
}
|
|
784
|
-
}();
|
|
785
|
-
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
|
+
}]);
|
|
786
527
|
|
|
787
528
|
/**
|
|
788
529
|
* @id装饰器
|
|
@@ -790,7 +531,6 @@ var Id = _Id;
|
|
|
790
531
|
*/
|
|
791
532
|
var id = createDecoratorExp(Id);
|
|
792
533
|
|
|
793
|
-
let _initClass$w;
|
|
794
534
|
/**
|
|
795
535
|
* Component不添加@scope(SCOPE.Singleton)的原因:
|
|
796
536
|
* 因为不设置默认就是singleton,还可以避免 scope <-> target 循环依赖的问题
|
|
@@ -798,20 +538,16 @@ let _initClass$w;
|
|
|
798
538
|
/**
|
|
799
539
|
* @public
|
|
800
540
|
*/
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
super(_Component), _initClass$w();
|
|
812
|
-
}
|
|
813
|
-
}();
|
|
814
|
-
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
|
+
}]);
|
|
815
551
|
|
|
816
552
|
/**
|
|
817
553
|
* ioc组件,只有ioc组件才能实例化
|
|
@@ -819,48 +555,37 @@ var Component = _Component;
|
|
|
819
555
|
*/
|
|
820
556
|
var component = createDecoratorExp(Component);
|
|
821
557
|
|
|
822
|
-
let _initClass$v;
|
|
823
558
|
/**
|
|
824
559
|
* @public
|
|
825
560
|
*/
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
super(_Configuration), _initClass$v();
|
|
836
|
-
}
|
|
837
|
-
}();
|
|
838
|
-
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
|
+
}]);
|
|
839
570
|
|
|
840
571
|
var configuration = createDecoratorExp(Configuration);
|
|
841
572
|
|
|
842
|
-
let _initClass$u;
|
|
843
573
|
/**
|
|
844
574
|
* @public
|
|
845
575
|
*/
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
super(_ConstructorInject), _initClass$u();
|
|
857
|
-
}
|
|
858
|
-
}();
|
|
859
|
-
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
|
+
}]);
|
|
860
586
|
|
|
861
587
|
var constructorInject = createDecoratorExp(ConstructorInject);
|
|
862
588
|
|
|
863
|
-
let _initClass$t;
|
|
864
589
|
/**
|
|
865
590
|
* @public
|
|
866
591
|
*/
|
|
@@ -874,62 +599,48 @@ var SCOPE;
|
|
|
874
599
|
/**
|
|
875
600
|
* @public
|
|
876
601
|
*/
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
super(_Scope), _initClass$t();
|
|
888
|
-
}
|
|
889
|
-
}();
|
|
890
|
-
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
|
+
}]);
|
|
891
612
|
|
|
892
613
|
var scope = createDecoratorExp(Scope);
|
|
893
614
|
|
|
894
|
-
let _initClass$s;
|
|
895
615
|
/**
|
|
896
616
|
* @public
|
|
897
617
|
*/
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
super(_Qualifier), _initClass$s();
|
|
909
|
-
}
|
|
910
|
-
}();
|
|
911
|
-
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
|
+
}]);
|
|
912
628
|
|
|
913
629
|
var qualifier = createDecoratorExp(Qualifier);
|
|
914
630
|
|
|
915
|
-
let _initClass$r;
|
|
916
631
|
/**
|
|
917
632
|
* @public
|
|
918
633
|
*/
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
super(_Value), _initClass$r();
|
|
930
|
-
}
|
|
931
|
-
}();
|
|
932
|
-
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
|
+
}]);
|
|
933
644
|
|
|
934
645
|
var value = createDecoratorExp(Value, {
|
|
935
646
|
componentPostConstruct: function (metadata, application, target) {
|
|
@@ -1228,7 +939,7 @@ class ComponentMetadataClass {
|
|
|
1228
939
|
// 遍历所有被装饰器的元数据类,将自己添加为被装饰器类的组件装饰器
|
|
1229
940
|
const beDecoratedClasses = decorateTree.get(current) || new Set();
|
|
1230
941
|
for (const beDecoratedClass of beDecoratedClasses) {
|
|
1231
|
-
// 忽略自己装饰自己的情况(
|
|
942
|
+
// 忽略自己装饰自己的情况(bind),因为这不算是组件装饰器
|
|
1232
943
|
if (beDecoratedClass === current) {
|
|
1233
944
|
// 避免自引用导致的无限循环
|
|
1234
945
|
if (!visited.has(beDecoratedClass)) {
|
|
@@ -1428,137 +1139,6 @@ class ComponentMetadataClass {
|
|
|
1428
1139
|
}
|
|
1429
1140
|
}
|
|
1430
1141
|
|
|
1431
|
-
/**
|
|
1432
|
-
* component
|
|
1433
|
-
* 1. 只能用在class或者method上,且只能装饰一次
|
|
1434
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1435
|
-
*/
|
|
1436
|
-
/**
|
|
1437
|
-
* view
|
|
1438
|
-
* 1. 只能用在class,且只能装饰一次
|
|
1439
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1440
|
-
*/
|
|
1441
|
-
/**
|
|
1442
|
-
* page
|
|
1443
|
-
* 1. 只能用在class,且只能装饰一次
|
|
1444
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1445
|
-
*/
|
|
1446
|
-
/**
|
|
1447
|
-
* layout
|
|
1448
|
-
* 1. 只能用在class,且只能使用一次
|
|
1449
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1450
|
-
*/
|
|
1451
|
-
/**
|
|
1452
|
-
* qualifier
|
|
1453
|
-
* 1. 只能用在field上,且只能装饰一次
|
|
1454
|
-
* 2. 依赖component配合使用
|
|
1455
|
-
*/
|
|
1456
|
-
/**
|
|
1457
|
-
* autowired
|
|
1458
|
-
* 1. 只能用在field上,且只能装饰一次
|
|
1459
|
-
* 2. TODO: 只能在view及其复合装饰器组件内部、controller及其复合装饰器组件内部、api装饰器组件内部
|
|
1460
|
-
* 3. 自动注入收到分层概念的约束,具体如下:
|
|
1461
|
-
* 3.1 view及其复合装饰器内部:controller及其复合装饰器组件, global-data, store, route, router,util及其复合装饰器组件
|
|
1462
|
-
* 3.2 controller及其复合装饰器内部:util及其复合装饰器组件
|
|
1463
|
-
* 3.3 util及其复合装饰器内部:util以及复合装饰器组件
|
|
1464
|
-
*/
|
|
1465
|
-
/**
|
|
1466
|
-
* configuration
|
|
1467
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1468
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1469
|
-
*/
|
|
1470
|
-
/**
|
|
1471
|
-
* constructor-inject
|
|
1472
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1473
|
-
*/
|
|
1474
|
-
/**
|
|
1475
|
-
* init
|
|
1476
|
-
* 1. 只能用在method上,且只能装饰一次
|
|
1477
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1478
|
-
*/
|
|
1479
|
-
/**
|
|
1480
|
-
* start
|
|
1481
|
-
* 1. 只能用在field上,且只能装饰一次
|
|
1482
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1483
|
-
*/
|
|
1484
|
-
/**
|
|
1485
|
-
* target
|
|
1486
|
-
* 1. 只能用在field上,且只能装饰一次
|
|
1487
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1488
|
-
*/
|
|
1489
|
-
/**
|
|
1490
|
-
* value
|
|
1491
|
-
* 1. 只能用在field上,且只能装饰一次
|
|
1492
|
-
*/
|
|
1493
|
-
/**
|
|
1494
|
-
* reactive
|
|
1495
|
-
* 1. 只能用在field上,且只能装饰一次
|
|
1496
|
-
*/
|
|
1497
|
-
/**
|
|
1498
|
-
* memoized
|
|
1499
|
-
* 1. 只能用在method上,且只能装饰一次
|
|
1500
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1501
|
-
*/
|
|
1502
|
-
/**
|
|
1503
|
-
* store
|
|
1504
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1505
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1506
|
-
*/
|
|
1507
|
-
/**
|
|
1508
|
-
* render
|
|
1509
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1510
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1511
|
-
*/
|
|
1512
|
-
/**
|
|
1513
|
-
* route
|
|
1514
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1515
|
-
* 2. 在class上使用时,依赖page同时使用
|
|
1516
|
-
*/
|
|
1517
|
-
/**
|
|
1518
|
-
* router
|
|
1519
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1520
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1521
|
-
*/
|
|
1522
|
-
/**
|
|
1523
|
-
* util
|
|
1524
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1525
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1526
|
-
*/
|
|
1527
|
-
/**
|
|
1528
|
-
* api
|
|
1529
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1530
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1531
|
-
*/
|
|
1532
|
-
/**
|
|
1533
|
-
* bind
|
|
1534
|
-
* 1. 只能用在method上,且只能装饰一次
|
|
1535
|
-
* 2. 只能在有view装饰器或者view复合装饰器组件上使用
|
|
1536
|
-
*/
|
|
1537
|
-
/**
|
|
1538
|
-
* flow
|
|
1539
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1540
|
-
* 2. 不能和其他component复合装饰器同时使用
|
|
1541
|
-
*/
|
|
1542
|
-
/**
|
|
1543
|
-
* global-data
|
|
1544
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1545
|
-
* 2. 不能和component复合装饰器同时使用
|
|
1546
|
-
*/
|
|
1547
|
-
/**
|
|
1548
|
-
* ref
|
|
1549
|
-
* 1. 只能用在field上,且只能装饰一次
|
|
1550
|
-
* 2. 宿主组件必须是view组件或者是view复合组件
|
|
1551
|
-
*/
|
|
1552
|
-
/**
|
|
1553
|
-
* refs
|
|
1554
|
-
* 1. 只能用在field上,且只能装饰一次
|
|
1555
|
-
* 2. 宿主组件必须是view组件或者是view复合组件
|
|
1556
|
-
*/
|
|
1557
|
-
/**
|
|
1558
|
-
* web-application
|
|
1559
|
-
* 1. 只能用在class上,且只能装饰一次
|
|
1560
|
-
* 2.
|
|
1561
|
-
*/
|
|
1562
1142
|
function deleteMetadatas(metadatas, idxs) {
|
|
1563
1143
|
idxs.sort((a, b) => b - a);
|
|
1564
1144
|
idxs.forEach(idx => metadatas.splice(idx, 1));
|
|
@@ -2023,12 +1603,13 @@ class IocComponentDefinition {
|
|
|
2023
1603
|
this.clsDefinitionMap.set(cls, componentDefinition);
|
|
2024
1604
|
}
|
|
2025
1605
|
/**
|
|
2026
|
-
*
|
|
1606
|
+
* 解析组件实际需要实例化的类。
|
|
1607
|
+
* 没有子类时返回自身,只有一个子类时返回该子类,多个子类时抛出异常。
|
|
2027
1608
|
* @param ClsOrId 想要实例化的类或类id
|
|
2028
1609
|
* @param qualifier 如果存在多个后端类,需要通过qualifier指定具体的类id
|
|
2029
1610
|
* @returns 真正会实例化的类定义
|
|
2030
1611
|
*/
|
|
2031
|
-
|
|
1612
|
+
resolve(ClsOrId, qualifier) {
|
|
2032
1613
|
const definition = this.getDefinition(ClsOrId);
|
|
2033
1614
|
if (!definition) {
|
|
2034
1615
|
const diagnose = createDiagnose(DiagnoseCode.CO10011, typeof ClsOrId === 'string' ? ClsOrId : ClsOrId.name);
|
|
@@ -2080,10 +1661,72 @@ class IocComponentDefinition {
|
|
|
2080
1661
|
}
|
|
2081
1662
|
}
|
|
2082
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 = {}));
|
|
2083
1726
|
class IocComponentFactory {
|
|
2084
1727
|
// 单例构造函数和单例的映射关系
|
|
2085
1728
|
singletonInstances = new Map();
|
|
2086
|
-
|
|
1729
|
+
newComponent(application, definition, constructorArgs) {
|
|
2087
1730
|
const {
|
|
2088
1731
|
cls,
|
|
2089
1732
|
instantiateType
|
|
@@ -2150,18 +1793,18 @@ class IocComponentFactory {
|
|
|
2150
1793
|
return component;
|
|
2151
1794
|
}
|
|
2152
1795
|
getComponents(application, userOption) {
|
|
2153
|
-
|
|
2154
|
-
|
|
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 = []; // 新建实例和对应的实例化类
|
|
2155
1805
|
const newSingletonInstances = new Map(); // 新增的单例,最后要合并到singletonInstances
|
|
2156
|
-
const instantiatingStage = new Set(); // 实例化中
|
|
2157
|
-
const assignningStage = new Set(); // field赋值中
|
|
2158
|
-
const finishedStage = new Set(); // 已完成
|
|
2159
|
-
// 已经有的单例填充到finishedStage和instances
|
|
2160
|
-
for (const [cls, instance] of this.singletonInstances.entries()) {
|
|
2161
|
-
targetClsInstanceMap.set(cls, instance);
|
|
2162
|
-
}
|
|
2163
1806
|
// 完整的初始化一个组件
|
|
2164
|
-
const instantiateComponent = opt => {
|
|
1807
|
+
const instantiateComponent = (opt, injectType) => {
|
|
2165
1808
|
const {
|
|
2166
1809
|
classOrId
|
|
2167
1810
|
} = opt;
|
|
@@ -2177,7 +1820,8 @@ class IocComponentFactory {
|
|
|
2177
1820
|
qualifier = application.propertiesConfig.getValue(`${targetDefinition.id}.qualifier`);
|
|
2178
1821
|
}
|
|
2179
1822
|
// 真正实例化的类定义
|
|
2180
|
-
const instantiateDefinition = application.iocComponentDefinition.
|
|
1823
|
+
const instantiateDefinition = application.iocComponentDefinition.resolve(classOrId, qualifier);
|
|
1824
|
+
// 尝试走缓存
|
|
2181
1825
|
if (instantiateDefinition.isSingleton) {
|
|
2182
1826
|
if (this.singletonInstances.has(instantiateDefinition.cls)) {
|
|
2183
1827
|
return this.singletonInstances.get(instantiateDefinition.cls);
|
|
@@ -2185,76 +1829,94 @@ class IocComponentFactory {
|
|
|
2185
1829
|
return newSingletonInstances.get(instantiateDefinition.cls);
|
|
2186
1830
|
}
|
|
2187
1831
|
}
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
}
|
|
2192
|
-
// 在实例化中或者已实例化,返回实例
|
|
2193
|
-
if (assignningStage.has(targetDefinition.cls) || finishedStage.has(targetDefinition.cls)) {
|
|
2194
|
-
return targetClsInstanceMap.get(targetDefinition.cls);
|
|
2195
|
-
}
|
|
2196
|
-
instantiatingStage.add(targetDefinition.cls);
|
|
1832
|
+
dependencyGraph.addDependency(targetDefinition, instantiateDefinition, injectType);
|
|
1833
|
+
// newAddStage(targetDefinition.cls, InstantiateStage.WAITING_CTOR_ARGS);
|
|
1834
|
+
// 没有缓存,只能真的创建了
|
|
2197
1835
|
const constructorArgs = [];
|
|
2198
1836
|
const constructorInject = application.metadataRepository.listClassKindMetadata(instantiateDefinition.cls, ConstructorInject);
|
|
2199
|
-
if (constructorInject.length
|
|
2200
|
-
// 因为元数据不能重复,所以只有一个
|
|
1837
|
+
if (constructorInject.length === 1) {
|
|
2201
1838
|
const constructorInjectParams = constructorInject[0].value;
|
|
2202
|
-
for (const
|
|
2203
|
-
if (
|
|
1839
|
+
for (const dependencyCls of constructorInjectParams) {
|
|
1840
|
+
if (dependencyCls === undefined) {
|
|
2204
1841
|
constructorArgs.push(undefined);
|
|
2205
1842
|
} else {
|
|
2206
1843
|
const depInstance = instantiateComponent({
|
|
2207
|
-
classOrId:
|
|
2208
|
-
});
|
|
2209
|
-
// 确保依赖已完全注入
|
|
2210
|
-
if (!finishedStage.has(dependency) && !this.singletonInstances.has(dependency)) {
|
|
2211
|
-
const diagnose = createDiagnose(DiagnoseCode.CO10013, targetDefinition.cls.name, dependency.name);
|
|
2212
|
-
throw new Error(stringifyDiagnose(diagnose));
|
|
2213
|
-
}
|
|
1844
|
+
classOrId: dependencyCls
|
|
1845
|
+
}, InjectType.constructor);
|
|
2214
1846
|
constructorArgs.push(depInstance);
|
|
2215
1847
|
}
|
|
2216
1848
|
}
|
|
1849
|
+
} else if (constructorInject.length > 1) {
|
|
1850
|
+
throw new Error(`${targetDefinition.cls.name}存在不止一个@constructorInject装饰器`);
|
|
2217
1851
|
}
|
|
2218
1852
|
// 2. 实例化,同时执行componentPostConstruct
|
|
2219
|
-
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);
|
|
2220
1857
|
if (instantiateDefinition.isSingleton) {
|
|
2221
1858
|
newSingletonInstances.set(instantiateDefinition.cls, instance);
|
|
2222
1859
|
}
|
|
2223
|
-
targetClsInstanceMap.set(targetDefinition.cls, instance);
|
|
2224
|
-
instanceInstantiateClsMap.set(instance, instantiateDefinition.cls);
|
|
2225
|
-
instantiatingStage.delete(targetDefinition.cls);
|
|
2226
|
-
assignningStage.add(targetDefinition.cls);
|
|
2227
1860
|
// 3. 递归实例化field注入
|
|
2228
|
-
const
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
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;
|
|
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;
|
|
2253
1908
|
}
|
|
1909
|
+
instance[field] = instantiateComponent({
|
|
1910
|
+
classOrId: autowiredCls,
|
|
1911
|
+
qualifier: qualifier?.value
|
|
1912
|
+
}, InjectType.autowired);
|
|
2254
1913
|
}
|
|
2255
|
-
// 4.
|
|
2256
|
-
|
|
2257
|
-
|
|
1914
|
+
// 4. autowired也注入完毕
|
|
1915
|
+
if (typeof instance['init'] === 'function') {
|
|
1916
|
+
instance['init']?.call(instance, application);
|
|
1917
|
+
}
|
|
1918
|
+
dependencyGraph.removeDependency(targetDefinition, instantiateDefinition);
|
|
1919
|
+
// updateStage(targetDefinition.cls, InstantiateStage.INITIALIZED);
|
|
2258
1920
|
return instance;
|
|
2259
1921
|
};
|
|
2260
1922
|
// TODO: 如果初始化多个,有没有先后顺序问题?
|
|
@@ -2263,22 +1925,12 @@ class IocComponentFactory {
|
|
|
2263
1925
|
if (newSingletonInstances.size > 0) {
|
|
2264
1926
|
for (const [cls, instance] of newSingletonInstances.entries()) {
|
|
2265
1927
|
this.singletonInstances.set(cls, instance);
|
|
2266
|
-
// 现在默认子类的singleton和父类都是保持一致的。TODO: 如果子类的singleton不是单例了,应该如何处理
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
|
-
// 5. 所有新增的单例执行init方法
|
|
2270
|
-
for (const cls of finishedStage.keys()) {
|
|
2271
|
-
// 这里应该是根据instance来判断是否已经存在的
|
|
2272
|
-
const instance = targetClsInstanceMap.get(cls);
|
|
2273
|
-
if (typeof instance['init'] === 'function') {
|
|
2274
|
-
instance['init']?.call(instance, application);
|
|
2275
1928
|
}
|
|
2276
1929
|
}
|
|
2277
1930
|
// 执行start方法
|
|
2278
|
-
for (const
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
instance['start']?.call(instance, application);
|
|
1931
|
+
for (const ins of newCreateInstance) {
|
|
1932
|
+
if (typeof ins['start'] === 'function') {
|
|
1933
|
+
ins['start']?.call(ins, application);
|
|
2282
1934
|
}
|
|
2283
1935
|
}
|
|
2284
1936
|
return instance;
|
|
@@ -2289,8 +1941,8 @@ class IocComponentFactory {
|
|
|
2289
1941
|
const diagnose = createDiagnose(DiagnoseCode.CO10011, typeof viewClass === 'string' ? viewClass : viewClass.name);
|
|
2290
1942
|
throw new Error(stringifyDiagnose(diagnose));
|
|
2291
1943
|
}
|
|
2292
|
-
// 视图组件目前简单的认为全是prototype
|
|
2293
|
-
const instance = this.
|
|
1944
|
+
// 视图组件目前简单的认为全是prototype,且不支持实例化子组件,TODO:补充不支持继承的限制和测试用例
|
|
1945
|
+
const instance = this.newComponent(application, targetDefinition, [props]);
|
|
2294
1946
|
const autowiredFields = application.metadataRepository.listFieldByMetadataCls(targetDefinition.cls, Autowired);
|
|
2295
1947
|
for (const field of autowiredFields) {
|
|
2296
1948
|
const autowiredMetadatas = application.metadataRepository.listFieldKindMetadata(targetDefinition.cls, field, Autowired);
|
|
@@ -2434,17 +2086,17 @@ class Application {
|
|
|
2434
2086
|
this.propertiesConfig = new PropertiesConfig(jsonConfig);
|
|
2435
2087
|
}
|
|
2436
2088
|
/**
|
|
2437
|
-
*
|
|
2438
|
-
*
|
|
2089
|
+
* 应用模块在 start 前完成 AOT 注册;测试中的局部类可能在 Application 构造后才注册,
|
|
2090
|
+
* 因此 start 时统一解析注册表。
|
|
2439
2091
|
*/
|
|
2440
2092
|
start() {
|
|
2441
|
-
initDecoratorParamModule();
|
|
2442
|
-
//
|
|
2093
|
+
const runtimeDecoratorParams = initDecoratorParamModule();
|
|
2094
|
+
// 使用 AOT 解析完成的装饰器参数(runtimeDecoratorParams)初始化元数据仓库
|
|
2443
2095
|
const {
|
|
2444
2096
|
metadataRepository,
|
|
2445
2097
|
idClassMap,
|
|
2446
2098
|
componentMetadataClass
|
|
2447
|
-
} = initMetadataModule(
|
|
2099
|
+
} = initMetadataModule(runtimeDecoratorParams);
|
|
2448
2100
|
this.metadataRepository = metadataRepository;
|
|
2449
2101
|
this.idClassMap = idClassMap;
|
|
2450
2102
|
this.componentMetadataClass = componentMetadataClass;
|
|
@@ -2507,23 +2159,18 @@ class Application {
|
|
|
2507
2159
|
}
|
|
2508
2160
|
}
|
|
2509
2161
|
|
|
2510
|
-
let _initClass$q;
|
|
2511
2162
|
/**
|
|
2512
2163
|
* @public
|
|
2513
2164
|
*/
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
super(_Bind), _initClass$q();
|
|
2524
|
-
}
|
|
2525
|
-
}();
|
|
2526
|
-
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
|
+
}]);
|
|
2527
2174
|
|
|
2528
2175
|
var bind = createDecoratorExp(Bind, {
|
|
2529
2176
|
componentPostConstruct: function (metadata, application, target) {
|
|
@@ -2534,23 +2181,23 @@ var bind = createDecoratorExp(Bind, {
|
|
|
2534
2181
|
}
|
|
2535
2182
|
});
|
|
2536
2183
|
|
|
2537
|
-
let _initClass$p;
|
|
2538
2184
|
/**
|
|
2539
2185
|
* @public
|
|
2540
2186
|
*/
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
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
|
+
}]);
|
|
2554
2201
|
|
|
2555
2202
|
var cookie = createDecoratorExp(Cookie);
|
|
2556
2203
|
|
|
@@ -2741,7 +2388,6 @@ function mapChildren(children, func, context) {
|
|
|
2741
2388
|
function forEachChildren(children, forEachFunc, forEachContext) {
|
|
2742
2389
|
mapChildren(children, function () {
|
|
2743
2390
|
forEachFunc.apply(this, arguments);
|
|
2744
|
-
// Don't return anything.
|
|
2745
2391
|
}, forEachContext);
|
|
2746
2392
|
}
|
|
2747
2393
|
|
|
@@ -2789,117 +2435,113 @@ const Children = {
|
|
|
2789
2435
|
forEach: forEachChildren,
|
|
2790
2436
|
};
|
|
2791
2437
|
|
|
2792
|
-
let _initClass$o;
|
|
2793
2438
|
/**
|
|
2794
2439
|
* @public
|
|
2795
2440
|
*/
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
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;
|
|
2808
2467
|
}
|
|
2809
|
-
}];
|
|
2810
|
-
$$id = "View";
|
|
2811
|
-
constructor() {
|
|
2812
|
-
super(_View), _initClass$o();
|
|
2813
2468
|
}
|
|
2814
|
-
}
|
|
2815
|
-
var View = _View;
|
|
2816
|
-
|
|
2817
|
-
var view = createDecoratorExp(View);
|
|
2469
|
+
});
|
|
2818
2470
|
|
|
2819
|
-
let _initClass$n;
|
|
2820
2471
|
/**
|
|
2821
2472
|
* @public
|
|
2822
2473
|
*/
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
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
|
+
}]);
|
|
2836
2488
|
|
|
2837
2489
|
var layout = createDecoratorExp(Layout);
|
|
2838
2490
|
|
|
2839
|
-
let _initClass$m;
|
|
2840
2491
|
/**
|
|
2841
2492
|
* @public
|
|
2842
2493
|
*/
|
|
2843
|
-
let
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
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
|
+
}]);
|
|
2856
2508
|
|
|
2857
|
-
var localStorageDecorator = createDecoratorExp(LocalStorage);
|
|
2509
|
+
var localStorageDecorator = createDecoratorExp(LocalStorage$1);
|
|
2858
2510
|
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
static {
|
|
2864
|
-
[_LocalStorage, _initClass$l] = _applyDecs2311(this, [localStorageDecorator()], []).c;
|
|
2865
|
-
}
|
|
2866
|
-
setItem(key, value) {
|
|
2867
|
-
return localStorage.setItem(key, value);
|
|
2868
|
-
}
|
|
2869
|
-
getItem(key) {
|
|
2870
|
-
return localStorage.getItem(key);
|
|
2871
|
-
}
|
|
2872
|
-
removeItem(key) {
|
|
2873
|
-
return localStorage.removeItem(key);
|
|
2874
|
-
}
|
|
2875
|
-
key(index) {
|
|
2876
|
-
return localStorage.key(index);
|
|
2877
|
-
}
|
|
2878
|
-
}];
|
|
2879
|
-
$$id = "LocalStorage";
|
|
2880
|
-
constructor() {
|
|
2881
|
-
super(_LocalStorage), _initClass$l();
|
|
2511
|
+
class LocalStorage {
|
|
2512
|
+
static $$id = "LocalStorage";
|
|
2513
|
+
setItem(key, value) {
|
|
2514
|
+
return localStorage.setItem(key, value);
|
|
2882
2515
|
}
|
|
2883
|
-
|
|
2884
|
-
|
|
2516
|
+
getItem(key) {
|
|
2517
|
+
return localStorage.getItem(key);
|
|
2518
|
+
}
|
|
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
|
+
}]);
|
|
2885
2532
|
|
|
2886
|
-
let _initClass$k;
|
|
2887
2533
|
/**
|
|
2888
2534
|
* @public
|
|
2889
2535
|
*/
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
super(_Memoized), _initClass$k();
|
|
2900
|
-
}
|
|
2901
|
-
}();
|
|
2902
|
-
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
|
+
}]);
|
|
2903
2545
|
|
|
2904
2546
|
class Subscriber {
|
|
2905
2547
|
static Executing;
|
|
@@ -2973,7 +2615,7 @@ var memoized = createDecoratorExp(Memoized, {
|
|
|
2973
2615
|
const descriptor = Object.getOwnPropertyDescriptor(this.constructor.prototype, name);
|
|
2974
2616
|
const getter = descriptor?.get;
|
|
2975
2617
|
if (typeof getter !== 'function') {
|
|
2976
|
-
console.error(
|
|
2618
|
+
console.error('不应该拿不到getter函数');
|
|
2977
2619
|
return;
|
|
2978
2620
|
}
|
|
2979
2621
|
const subscriber = new Subscriber(getter.bind(this));
|
|
@@ -2986,45 +2628,40 @@ var memoized = createDecoratorExp(Memoized, {
|
|
|
2986
2628
|
}
|
|
2987
2629
|
});
|
|
2988
2630
|
|
|
2989
|
-
let _initClass$j;
|
|
2990
2631
|
/**
|
|
2991
2632
|
* @public
|
|
2992
2633
|
*/
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
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
|
+
}]);
|
|
3006
2648
|
|
|
3007
2649
|
var page = createDecoratorExp(Page);
|
|
3008
2650
|
|
|
3009
|
-
let _initClass$i;
|
|
3010
2651
|
/**
|
|
3011
2652
|
* 加在field表明是响应式
|
|
3012
2653
|
* 加在metadata上用于自定义reactive元数据
|
|
3013
2654
|
* @public
|
|
3014
2655
|
*/
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
super(_Reactive), _initClass$i();
|
|
3025
|
-
}
|
|
3026
|
-
}();
|
|
3027
|
-
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
|
+
}]);
|
|
3028
2665
|
|
|
3029
2666
|
class Publisher {
|
|
3030
2667
|
name;
|
|
@@ -3101,23 +2738,18 @@ var reactive = createDecoratorExp(Reactive, {
|
|
|
3101
2738
|
}
|
|
3102
2739
|
});
|
|
3103
2740
|
|
|
3104
|
-
let _initClass$h;
|
|
3105
2741
|
/**
|
|
3106
2742
|
* @public
|
|
3107
2743
|
*/
|
|
3108
|
-
let
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
super(_Ref), _initClass$h();
|
|
3118
|
-
}
|
|
3119
|
-
}();
|
|
3120
|
-
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
|
+
}]);
|
|
3121
2753
|
|
|
3122
2754
|
var ref = createDecoratorExp(Ref$1, {
|
|
3123
2755
|
componentPostConstruct: function (metadata, application, target) {
|
|
@@ -3130,23 +2762,18 @@ var ref = createDecoratorExp(Ref$1, {
|
|
|
3130
2762
|
}
|
|
3131
2763
|
});
|
|
3132
2764
|
|
|
3133
|
-
let _initClass$g;
|
|
3134
2765
|
/**
|
|
3135
2766
|
* @public
|
|
3136
2767
|
*/
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
super(_Refs), _initClass$g();
|
|
3147
|
-
}
|
|
3148
|
-
}();
|
|
3149
|
-
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
|
+
}]);
|
|
3150
2777
|
|
|
3151
2778
|
var refs = createDecoratorExp(Refs, {
|
|
3152
2779
|
componentPostConstruct: function (metadata, application, target) {
|
|
@@ -3154,166 +2781,146 @@ var refs = createDecoratorExp(Refs, {
|
|
|
3154
2781
|
}
|
|
3155
2782
|
});
|
|
3156
2783
|
|
|
3157
|
-
let _initClass$f;
|
|
3158
2784
|
/**
|
|
3159
2785
|
* @public
|
|
3160
2786
|
*/
|
|
3161
|
-
let
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
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
|
+
}]);
|
|
3174
2801
|
|
|
3175
|
-
var sessionStorageDecorator = createDecoratorExp(SessionStorage);
|
|
2802
|
+
var sessionStorageDecorator = createDecoratorExp(SessionStorage$1);
|
|
3176
2803
|
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
setItem(key, value) {
|
|
3185
|
-
return sessionStorage.setItem(key, value);
|
|
3186
|
-
}
|
|
3187
|
-
getItem(key) {
|
|
3188
|
-
return sessionStorage.getItem(key);
|
|
3189
|
-
}
|
|
3190
|
-
removeItem(key) {
|
|
3191
|
-
return sessionStorage.removeItem(key);
|
|
3192
|
-
}
|
|
3193
|
-
key(index) {
|
|
3194
|
-
return sessionStorage.key(index);
|
|
3195
|
-
}
|
|
3196
|
-
}];
|
|
3197
|
-
$$id = "SessionStorage";
|
|
3198
|
-
constructor() {
|
|
3199
|
-
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);
|
|
3200
2811
|
}
|
|
3201
|
-
|
|
3202
|
-
|
|
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
|
+
}]);
|
|
3203
2825
|
|
|
3204
|
-
let _initClass$d;
|
|
3205
2826
|
/**
|
|
3206
2827
|
* @public
|
|
3207
2828
|
*/
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
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
|
+
}]);
|
|
3221
2843
|
|
|
3222
2844
|
var store = createDecoratorExp(Store);
|
|
3223
2845
|
|
|
3224
|
-
let
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
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
|
+
}]);
|
|
3238
2860
|
|
|
3239
|
-
let _initClass$b;
|
|
3240
2861
|
/**
|
|
3241
2862
|
* @public
|
|
3242
2863
|
*/
|
|
3243
|
-
let
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
super(_Route$1), _initClass$b();
|
|
3254
|
-
}
|
|
3255
|
-
}();
|
|
3256
|
-
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
|
+
}]);
|
|
3257
2874
|
|
|
3258
|
-
var route = createDecoratorExp(
|
|
2875
|
+
var route = createDecoratorExp(Route$1);
|
|
3259
2876
|
|
|
3260
2877
|
var router = createDecoratorExp(Router$1);
|
|
3261
2878
|
|
|
3262
|
-
let _initClass$a;
|
|
3263
2879
|
/**
|
|
3264
2880
|
* @public
|
|
3265
2881
|
*/
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
super(_Render$1), _initClass$9();
|
|
3294
|
-
}
|
|
3295
|
-
}();
|
|
3296
|
-
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
|
+
}]);
|
|
3297
2909
|
|
|
3298
2910
|
var render$1 = createDecoratorExp(Render$1);
|
|
3299
2911
|
|
|
3300
|
-
let _initClass$8;
|
|
3301
2912
|
/**
|
|
3302
2913
|
* @public
|
|
3303
2914
|
*/
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
super(_Render), _initClass$8();
|
|
3314
|
-
}
|
|
3315
|
-
}();
|
|
3316
|
-
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
|
+
}]);
|
|
3317
2924
|
|
|
3318
2925
|
/**
|
|
3319
2926
|
* Mapping from registration name to event name
|
|
@@ -3322,7 +2929,6 @@ const registrationNameDependencies = {};
|
|
|
3322
2929
|
const allNativeEvents = new Set();
|
|
3323
2930
|
function registerTwoPhaseEvent(registrationName, dependencies) {
|
|
3324
2931
|
registerDirectEvent(registrationName, dependencies);
|
|
3325
|
-
// registerDirectEvent(registrationName + 'Capture', dependencies);
|
|
3326
2932
|
}
|
|
3327
2933
|
function registerDirectEvent(registrationName, dependencies) {
|
|
3328
2934
|
registrationNameDependencies[registrationName] = dependencies;
|
|
@@ -4782,7 +4388,6 @@ function executeDispatch(domEvent, listener, currentTarget, reactEventType) {
|
|
|
4782
4388
|
domEvent.stopPropagation();
|
|
4783
4389
|
},
|
|
4784
4390
|
});
|
|
4785
|
-
// domEvent.currentTarget = null;
|
|
4786
4391
|
}
|
|
4787
4392
|
function processDispatchQueueItemsInOrder(domEvent, dispatchListeners, inCapturePhase, reactEventType) {
|
|
4788
4393
|
if (inCapturePhase) {
|
|
@@ -6347,7 +5952,9 @@ function initProps(instance, newProps) {
|
|
|
6347
5952
|
continue;
|
|
6348
5953
|
}
|
|
6349
5954
|
_values[field] = newProps[field];
|
|
6350
|
-
definePublisher(instance.props, field, function getter() {
|
|
5955
|
+
definePublisher(instance.props, field, function getter() {
|
|
5956
|
+
return _values[field];
|
|
5957
|
+
}, function setter(object, key, newValue) {
|
|
6351
5958
|
_values[field] = newValue;
|
|
6352
5959
|
});
|
|
6353
5960
|
}
|
|
@@ -6399,7 +6006,7 @@ const storeComponentUpdater = {
|
|
|
6399
6006
|
scheduleUpdateOnFiber(root, viewComponentFiber, viewInstance);
|
|
6400
6007
|
}
|
|
6401
6008
|
}
|
|
6402
|
-
}
|
|
6009
|
+
},
|
|
6403
6010
|
};
|
|
6404
6011
|
function reactiveStoreField(ctor, viewComponent) {
|
|
6405
6012
|
const { application } = getCommonApi();
|
|
@@ -6418,7 +6025,7 @@ function reactiveStoreField(ctor, viewComponent) {
|
|
|
6418
6025
|
},
|
|
6419
6026
|
set() {
|
|
6420
6027
|
console.error('store实例在初始化之后不允许修改');
|
|
6421
|
-
}
|
|
6028
|
+
},
|
|
6422
6029
|
});
|
|
6423
6030
|
}
|
|
6424
6031
|
});
|
|
@@ -6972,7 +6579,6 @@ function insertOrAppendPlacementNodeIntoContainer(node, before, parent) {
|
|
|
6972
6579
|
sibling = sibling.sibling;
|
|
6973
6580
|
}
|
|
6974
6581
|
}
|
|
6975
|
-
// throw new Error('todo')
|
|
6976
6582
|
}
|
|
6977
6583
|
}
|
|
6978
6584
|
function detachFiberMutation(fiber) {
|
|
@@ -7143,7 +6749,6 @@ function commitMutationEffectsOnFiber(finishedWork, root) {
|
|
|
7143
6749
|
resetTextContent(instance);
|
|
7144
6750
|
}
|
|
7145
6751
|
catch (error) {
|
|
7146
|
-
// todo captureCommitPhaseError(finishedWork, finishedWork.return, error);
|
|
7147
6752
|
}
|
|
7148
6753
|
}
|
|
7149
6754
|
if (flags & Update) {
|
|
@@ -7831,34 +7436,29 @@ function render(element, container) {
|
|
|
7831
7436
|
return legacyRenderSubtreeIntoContainer(null, element, container);
|
|
7832
7437
|
}
|
|
7833
7438
|
|
|
7834
|
-
let _initClass$7;
|
|
7835
7439
|
/**
|
|
7836
7440
|
* @public
|
|
7837
7441
|
*/
|
|
7838
|
-
|
|
7839
|
-
|
|
7840
|
-
|
|
7841
|
-
|
|
7842
|
-
|
|
7843
|
-
|
|
7844
|
-
container
|
|
7845
|
-
|
|
7846
|
-
registerCommonApi(application);
|
|
7847
|
-
this.container = document.getElementById('root');
|
|
7848
|
-
if (!this.container) {
|
|
7849
|
-
console.error('未找到根节点');
|
|
7850
|
-
}
|
|
7851
|
-
}
|
|
7852
|
-
render(component) {
|
|
7853
|
-
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('未找到根节点');
|
|
7854
7450
|
}
|
|
7855
|
-
}];
|
|
7856
|
-
$$id = "WebRender";
|
|
7857
|
-
constructor() {
|
|
7858
|
-
super(_WebRender), _initClass$7();
|
|
7859
7451
|
}
|
|
7860
|
-
|
|
7861
|
-
|
|
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
|
+
}]);
|
|
7862
7462
|
|
|
7863
7463
|
class DynamicRoute {
|
|
7864
7464
|
regExp;
|
|
@@ -7941,176 +7541,176 @@ class RouteComponentMapper {
|
|
|
7941
7541
|
}
|
|
7942
7542
|
}
|
|
7943
7543
|
|
|
7944
|
-
|
|
7945
|
-
|
|
7946
|
-
|
|
7947
|
-
|
|
7948
|
-
|
|
7949
|
-
|
|
7950
|
-
|
|
7951
|
-
|
|
7952
|
-
|
|
7953
|
-
|
|
7954
|
-
|
|
7955
|
-
|
|
7956
|
-
|
|
7957
|
-
constructor() {
|
|
7958
|
-
super(_Route), _initClass$6();
|
|
7959
|
-
}
|
|
7960
|
-
}();
|
|
7961
|
-
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
|
+
}]);
|
|
7962
7557
|
|
|
7963
|
-
let _initClass$5;
|
|
7964
7558
|
/**
|
|
7965
7559
|
* @public
|
|
7966
7560
|
*/
|
|
7967
|
-
|
|
7968
|
-
|
|
7969
|
-
|
|
7970
|
-
|
|
7971
|
-
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
|
|
7975
|
-
|
|
7976
|
-
|
|
7977
|
-
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
7983
|
-
this.route.pathname = pathname;
|
|
7984
|
-
this.route.params = params || {};
|
|
7985
|
-
if (pageComponent) {
|
|
7986
|
-
this.render.render(pageComponent);
|
|
7987
|
-
}
|
|
7988
|
-
};
|
|
7989
|
-
init(application) {
|
|
7990
|
-
const routeComponentMap = application.listBeDecoratedClsByClassKindMetadata(RouteMeta);
|
|
7991
|
-
this.routeComponentMapper = new RouteComponentMapper();
|
|
7992
|
-
this.routeComponentMapper.init(routeComponentMap);
|
|
7993
|
-
this.route = application.getComponent(Route);
|
|
7994
|
-
}
|
|
7995
|
-
start() {
|
|
7996
|
-
window.addEventListener('popstate', this.handleRouteChange);
|
|
7997
|
-
// 初始化渲染
|
|
7998
|
-
this.handleRouteChange();
|
|
7999
|
-
}
|
|
8000
|
-
removeListener() {
|
|
8001
|
-
window.removeEventListener('popstate', this.handleRouteChange);
|
|
8002
|
-
}
|
|
8003
|
-
navigateTo(url) {
|
|
8004
|
-
window.history.pushState({}, '', url);
|
|
8005
|
-
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);
|
|
8006
7577
|
}
|
|
8007
|
-
}
|
|
8008
|
-
|
|
8009
|
-
|
|
8010
|
-
|
|
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);
|
|
7592
|
+
}
|
|
7593
|
+
navigateTo(url) {
|
|
7594
|
+
window.history.pushState({}, '', url);
|
|
7595
|
+
this.handleRouteChange();
|
|
8011
7596
|
}
|
|
8012
|
-
}
|
|
8013
|
-
|
|
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
|
+
}]);
|
|
8014
7609
|
|
|
8015
|
-
let _initClass$4;
|
|
8016
7610
|
/**
|
|
8017
7611
|
* @public
|
|
8018
7612
|
*/
|
|
8019
|
-
|
|
8020
|
-
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8024
|
-
|
|
8025
|
-
|
|
8026
|
-
|
|
8027
|
-
|
|
8028
|
-
|
|
8029
|
-
|
|
8030
|
-
|
|
8031
|
-
|
|
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
|
+
}]);
|
|
8032
7627
|
|
|
8033
7628
|
var util = createDecoratorExp(Util);
|
|
8034
7629
|
|
|
8035
|
-
let _initClass$3;
|
|
8036
7630
|
/**
|
|
8037
7631
|
* @public
|
|
8038
7632
|
*/
|
|
8039
|
-
|
|
8040
|
-
|
|
8041
|
-
|
|
8042
|
-
|
|
8043
|
-
|
|
8044
|
-
|
|
8045
|
-
|
|
8046
|
-
|
|
8047
|
-
|
|
8048
|
-
|
|
8049
|
-
|
|
8050
|
-
|
|
8051
|
-
|
|
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
|
+
}]);
|
|
8052
7647
|
|
|
8053
7648
|
var api = createDecoratorExp(Api);
|
|
8054
7649
|
|
|
8055
|
-
let _initClass$2;
|
|
8056
7650
|
/**
|
|
8057
7651
|
* @public
|
|
8058
7652
|
*/
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
|
|
8062
|
-
|
|
8063
|
-
|
|
8064
|
-
|
|
8065
|
-
|
|
8066
|
-
|
|
8067
|
-
|
|
8068
|
-
|
|
8069
|
-
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
|
|
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);
|
|
8074
7674
|
|
|
8075
|
-
let _initClass$1;
|
|
8076
7675
|
// TODO: view 包添加 viewData装饰器
|
|
8077
7676
|
/**
|
|
8078
7677
|
* @public
|
|
8079
7678
|
*/
|
|
8080
|
-
|
|
8081
|
-
|
|
8082
|
-
|
|
8083
|
-
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
|
|
8087
|
-
|
|
8088
|
-
|
|
8089
|
-
|
|
8090
|
-
|
|
8091
|
-
|
|
8092
|
-
|
|
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
|
+
}]);
|
|
8093
7693
|
|
|
8094
7694
|
var globalData = createDecoratorExp(GlobalData);
|
|
8095
7695
|
|
|
8096
|
-
let _initClass;
|
|
8097
7696
|
/**
|
|
8098
7697
|
* @public
|
|
8099
7698
|
*/
|
|
8100
|
-
|
|
8101
|
-
|
|
8102
|
-
|
|
8103
|
-
|
|
8104
|
-
|
|
8105
|
-
|
|
8106
|
-
|
|
8107
|
-
|
|
8108
|
-
|
|
8109
|
-
|
|
8110
|
-
|
|
8111
|
-
|
|
8112
|
-
|
|
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
|
+
}]);
|
|
8113
7713
|
|
|
8114
7714
|
var webApplication = createDecoratorExp(WebApplication);
|
|
8115
7715
|
|
|
8116
|
-
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 };
|