@viewfly/core 0.0.19 → 0.0.21
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/bundles/di/_api.d.ts +10 -0
- package/bundles/di/forward-ref.d.ts +10 -0
- package/bundles/di/injectable.d.ts +20 -0
- package/bundles/di/injection-token.d.ts +8 -0
- package/bundles/di/injector.d.ts +22 -0
- package/bundles/di/metadata.d.ts +43 -0
- package/bundles/di/null-injector.d.ts +6 -0
- package/bundles/di/provider.d.ts +30 -0
- package/bundles/di/reflective-injector.d.ts +32 -0
- package/bundles/di/reflective-provider.d.ts +20 -0
- package/bundles/di/type.d.ts +7 -0
- package/bundles/di/utils/_api.d.ts +3 -0
- package/bundles/di/utils/annotations.d.ts +33 -0
- package/bundles/di/utils/decorators.d.ts +17 -0
- package/bundles/di/utils/stringify.d.ts +1 -0
- package/bundles/foundation/_api.d.ts +5 -0
- package/bundles/foundation/_utils.d.ts +4 -0
- package/bundles/{model → foundation}/component.d.ts +1 -1
- package/bundles/{model → foundation}/jsx-element.d.ts +1 -4
- package/bundles/foundation/renderer.d.ts +1 -1
- package/bundles/{model → foundation}/root.component.d.ts +3 -3
- package/bundles/{model → foundation}/types.d.ts +2 -1
- package/bundles/index.esm.js +588 -42
- package/bundles/index.js +611 -54
- package/bundles/public-api.d.ts +1 -2
- package/bundles/viewfly.d.ts +4 -4
- package/package.json +2 -4
- package/bundles/model/_api.d.ts +0 -5
- package/jsx-runtime/node_modules/.bin/rimraf +0 -17
- package/jsx-runtime/node_modules/.bin/rollup +0 -17
- /package/bundles/{model → foundation}/memo.d.ts +0 -0
package/bundles/index.esm.js
CHANGED
|
@@ -1,7 +1,188 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
|
|
3
|
+
class ForwardRef {
|
|
4
|
+
constructor(forwardRefFn) {
|
|
5
|
+
this.forwardRefFn = forwardRefFn;
|
|
6
|
+
}
|
|
7
|
+
getRef() {
|
|
8
|
+
return this.forwardRefFn();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 引用后声明的类的工具函数
|
|
13
|
+
* @param fn
|
|
14
|
+
*/
|
|
15
|
+
function forwardRef(fn) {
|
|
16
|
+
return new ForwardRef(fn);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 用于保存 class 的元数据
|
|
21
|
+
*/
|
|
22
|
+
class Annotations {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.classes = new Map();
|
|
25
|
+
this.props = new Map();
|
|
26
|
+
this.params = new Map();
|
|
27
|
+
}
|
|
28
|
+
setClassMetadata(token, params) {
|
|
29
|
+
this.classes.set(token, params);
|
|
30
|
+
}
|
|
31
|
+
getClassMetadata(token) {
|
|
32
|
+
return this.classes.get(token);
|
|
33
|
+
}
|
|
34
|
+
pushParamMetadata(token, params) {
|
|
35
|
+
if (this.params.has(token)) {
|
|
36
|
+
this.params.get(token).push(params);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.params.set(token, [params]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
getParamMetadata(token) {
|
|
43
|
+
return this.params.get(token);
|
|
44
|
+
}
|
|
45
|
+
getPropMetadataKeys() {
|
|
46
|
+
return Array.from(this.props.keys());
|
|
47
|
+
}
|
|
48
|
+
pushPropMetadata(token, params) {
|
|
49
|
+
if (this.props.has(token)) {
|
|
50
|
+
this.props.get(token).push(params);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this.props.set(token, [params]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
getPropMetadata(token) {
|
|
57
|
+
return this.props.get(token);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 创建参数装饰器的工厂函数
|
|
63
|
+
*/
|
|
64
|
+
function makeParamDecorator(token, metadata) {
|
|
65
|
+
return function (target, propertyKey, parameterIndex) {
|
|
66
|
+
const annotations = getAnnotations(target);
|
|
67
|
+
annotations.pushParamMetadata(token, {
|
|
68
|
+
propertyKey: propertyKey,
|
|
69
|
+
parameterIndex,
|
|
70
|
+
metadata
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 创建属性装饰器的工厂函数
|
|
76
|
+
*/
|
|
77
|
+
function makePropertyDecorator(token, injectToken, contextCallback) {
|
|
78
|
+
return function (target, propertyKey) {
|
|
79
|
+
const annotations = getAnnotations(target.constructor);
|
|
80
|
+
annotations.pushPropMetadata(token, {
|
|
81
|
+
injectToken: injectToken || Reflect.getMetadata('design:type', target, propertyKey),
|
|
82
|
+
propertyKey,
|
|
83
|
+
contextCallback
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 创建类装饰器的工厂函数
|
|
89
|
+
*/
|
|
90
|
+
function makeClassDecorator(token, metadata) {
|
|
91
|
+
return function (target) {
|
|
92
|
+
const annotations = getAnnotations(target);
|
|
93
|
+
annotations.setClassMetadata(token, {
|
|
94
|
+
paramTypes: Reflect.getMetadata('design:paramtypes', target),
|
|
95
|
+
metadata
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 获取类注解的工具函数
|
|
101
|
+
*/
|
|
102
|
+
function getAnnotations(target) {
|
|
103
|
+
const key = '__annotations__';
|
|
104
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
105
|
+
if (!target.hasOwnProperty(key)) {
|
|
106
|
+
target[key] = new Annotations();
|
|
107
|
+
}
|
|
108
|
+
return target[key];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
class Scope {
|
|
112
|
+
constructor(name) {
|
|
113
|
+
this.name = name;
|
|
114
|
+
}
|
|
115
|
+
toString() {
|
|
116
|
+
return this.name || '[anonymous provide scope]';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 可注入类的装饰器
|
|
121
|
+
*/
|
|
122
|
+
const Injectable = function InjectableDecorator(options) {
|
|
123
|
+
if (this instanceof InjectableDecorator) {
|
|
124
|
+
this.provideIn = (options === null || options === void 0 ? void 0 : options.provideIn) || null;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
return makeClassDecorator(Injectable, new Injectable(options));
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 生成自定义依赖注入 token 的类
|
|
133
|
+
*/
|
|
134
|
+
class InjectionToken {
|
|
135
|
+
constructor(description) {
|
|
136
|
+
this.description = description;
|
|
137
|
+
}
|
|
138
|
+
toString() {
|
|
139
|
+
return this.description || '[anonymous injection token]';
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 查找规则
|
|
145
|
+
*/
|
|
146
|
+
var InjectFlags;
|
|
147
|
+
(function (InjectFlags) {
|
|
148
|
+
/** 默认查找规则 */
|
|
149
|
+
InjectFlags["Default"] = "Default";
|
|
150
|
+
/** 锁定当前容器 */
|
|
151
|
+
InjectFlags["Self"] = "Self";
|
|
152
|
+
/** 跳过当前容器 */
|
|
153
|
+
InjectFlags["SkipSelf"] = "SkipSelf";
|
|
154
|
+
/** 可选查找 */
|
|
155
|
+
InjectFlags["Optional"] = "Optional";
|
|
156
|
+
})(InjectFlags || (InjectFlags = {}));
|
|
157
|
+
/**
|
|
158
|
+
* DI 容器抽象基类
|
|
159
|
+
*/
|
|
160
|
+
class Injector {
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function stringify(token) {
|
|
164
|
+
if (typeof token === 'string') {
|
|
165
|
+
return token;
|
|
166
|
+
}
|
|
167
|
+
if (Array.isArray(token)) {
|
|
168
|
+
return '[' + token.map(stringify).join(', ') + ']';
|
|
169
|
+
}
|
|
170
|
+
if (token == null) {
|
|
171
|
+
return '' + token;
|
|
172
|
+
}
|
|
173
|
+
if (token.name) {
|
|
174
|
+
return `${token.name}`;
|
|
175
|
+
}
|
|
176
|
+
if (token.token) {
|
|
177
|
+
return `${token.token}`;
|
|
178
|
+
}
|
|
179
|
+
const res = token.toString();
|
|
180
|
+
if (res == null) {
|
|
181
|
+
return '' + res;
|
|
182
|
+
}
|
|
183
|
+
const newLineIndex = res.indexOf('\n');
|
|
184
|
+
return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
|
|
185
|
+
}
|
|
5
186
|
|
|
6
187
|
function makeError(name) {
|
|
7
188
|
return function viewflyError(message) {
|
|
@@ -12,41 +193,356 @@ function makeError(name) {
|
|
|
12
193
|
};
|
|
13
194
|
}
|
|
14
195
|
|
|
15
|
-
|
|
196
|
+
const THROW_IF_NOT_FOUND = {
|
|
197
|
+
__debug_value__: 'THROW_IF_NOT_FOUND'
|
|
198
|
+
};
|
|
199
|
+
const nullInjectorErrorFn = (token) => {
|
|
200
|
+
return makeError('NullInjector')(`No provide for \`${stringify(token)}\`!`);
|
|
201
|
+
};
|
|
202
|
+
class NullInjector extends Injector {
|
|
203
|
+
constructor() {
|
|
204
|
+
super(...arguments);
|
|
205
|
+
this.parentInjector = null;
|
|
206
|
+
}
|
|
207
|
+
get(token, notFoundValue = THROW_IF_NOT_FOUND) {
|
|
208
|
+
if (notFoundValue === THROW_IF_NOT_FOUND) {
|
|
209
|
+
throw nullInjectorErrorFn(token);
|
|
210
|
+
}
|
|
211
|
+
return notFoundValue;
|
|
212
|
+
}
|
|
16
213
|
}
|
|
17
214
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
215
|
+
/**
|
|
216
|
+
* 构造函数参数装饰器,用于改变注入 token
|
|
217
|
+
*/
|
|
218
|
+
const Inject = function InjectDecorator(token) {
|
|
219
|
+
if (this instanceof Inject) {
|
|
220
|
+
this.token = token;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
return makeParamDecorator(Inject, new Inject(token));
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const Self = function SelfDecorator() {
|
|
227
|
+
if (!(this instanceof Self)) {
|
|
228
|
+
return makeParamDecorator(Self, new Self());
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const SkipSelf = function SkipSelfDecorator() {
|
|
232
|
+
if (!(this instanceof SkipSelf)) {
|
|
233
|
+
return makeParamDecorator(SkipSelf, new SkipSelf());
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
const Optional = function OptionalDecorator() {
|
|
237
|
+
if (!(this instanceof Optional)) {
|
|
238
|
+
return makeParamDecorator(Optional, new Optional());
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
const Prop = function PropDecorator(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
|
|
242
|
+
if (!(this instanceof Prop)) {
|
|
243
|
+
return makePropertyDecorator(Prop, token, function (instance, propertyName, token, injector) {
|
|
244
|
+
instance[propertyName] = injector.get(token instanceof ForwardRef ? token.getRef() : token, notFoundValue, flags);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* 标准化 provide,并返回统一数据结构
|
|
251
|
+
* @param provider
|
|
252
|
+
*/
|
|
253
|
+
function normalizeProvider(provider) {
|
|
254
|
+
if (provider.useValue) {
|
|
255
|
+
return normalizeValueProviderFactory(provider);
|
|
256
|
+
}
|
|
257
|
+
if (provider.useClass) {
|
|
258
|
+
return normalizeClassProviderFactory(provider);
|
|
259
|
+
}
|
|
260
|
+
if (provider.useExisting) {
|
|
261
|
+
return normalizeExistingProviderFactory(provider);
|
|
262
|
+
}
|
|
263
|
+
if (provider.useFactory) {
|
|
264
|
+
return normalizeFactoryProviderFactory(provider);
|
|
265
|
+
}
|
|
266
|
+
if (provider.provide) {
|
|
267
|
+
if (provider.provide instanceof InjectionToken) {
|
|
268
|
+
return normalizeValueProviderFactory(provider);
|
|
269
|
+
}
|
|
270
|
+
return normalizeConstructorProviderFactory(provider);
|
|
271
|
+
}
|
|
272
|
+
return normalizeTypeProviderFactory(provider);
|
|
273
|
+
}
|
|
274
|
+
function normalizeValueProviderFactory(provider) {
|
|
275
|
+
return {
|
|
276
|
+
provide: provider.provide,
|
|
277
|
+
scope: null,
|
|
278
|
+
generateFactory() {
|
|
279
|
+
return function () {
|
|
280
|
+
return provider.useValue;
|
|
281
|
+
};
|
|
282
|
+
},
|
|
283
|
+
deps: []
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function normalizeClassProviderFactory(provider) {
|
|
287
|
+
let deps;
|
|
288
|
+
let provideIn = null;
|
|
289
|
+
if (provider.deps) {
|
|
290
|
+
deps = normalizeDeps(provider.provide, provider.deps);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
const resolvedClass = resolveClassParams(provider.useClass);
|
|
294
|
+
provideIn = resolvedClass.scope;
|
|
295
|
+
deps = normalizeDeps(provider.provide, resolvedClass.deps);
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
provide: provider.provide,
|
|
299
|
+
scope: provideIn,
|
|
300
|
+
deps,
|
|
301
|
+
generateFactory(injector, cacheFn) {
|
|
302
|
+
return function (...args) {
|
|
303
|
+
const instance = new provider.useClass(...args);
|
|
304
|
+
cacheFn(provider.provide, instance);
|
|
305
|
+
const propMetadataKeys = getAnnotations(provider.useClass).getPropMetadataKeys();
|
|
306
|
+
propMetadataKeys.forEach(key => {
|
|
307
|
+
const propsMetadata = getAnnotations(provider.useClass).getPropMetadata(key);
|
|
308
|
+
propsMetadata.forEach(item => {
|
|
309
|
+
item.contextCallback(instance, item.propertyKey, item.injectToken, injector);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
return instance;
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
function normalizeExistingProviderFactory(provider) {
|
|
318
|
+
return {
|
|
319
|
+
provide: provider.provide,
|
|
320
|
+
scope: null,
|
|
321
|
+
generateFactory(injector) {
|
|
322
|
+
return function () {
|
|
323
|
+
return injector.get(provider.useExisting);
|
|
324
|
+
};
|
|
325
|
+
},
|
|
326
|
+
deps: []
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function normalizeFactoryProviderFactory(provider) {
|
|
330
|
+
return {
|
|
331
|
+
provide: provider.provide,
|
|
332
|
+
scope: null,
|
|
333
|
+
generateFactory() {
|
|
334
|
+
return function (...args) {
|
|
335
|
+
return provider.useFactory(...args);
|
|
336
|
+
};
|
|
337
|
+
},
|
|
338
|
+
deps: normalizeDeps(provider.provide, provider.deps || [])
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function normalizeConstructorProviderFactory(provider) {
|
|
342
|
+
return normalizeClassProviderFactory(Object.assign(Object.assign({}, provider), { useClass: provider.provide }));
|
|
343
|
+
}
|
|
344
|
+
function normalizeTypeProviderFactory(provider) {
|
|
345
|
+
return normalizeClassProviderFactory({
|
|
346
|
+
provide: provider,
|
|
347
|
+
useClass: provider
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
function resolveClassParams(construct) {
|
|
351
|
+
const annotations = getAnnotations(construct);
|
|
352
|
+
const metadata = annotations.getClassMetadata(Injectable);
|
|
353
|
+
if (typeof metadata === 'undefined') {
|
|
354
|
+
throw new Error(`Class \`${stringify(construct)}\` is not injectable!`);
|
|
355
|
+
}
|
|
356
|
+
const deps = (metadata.paramTypes || []).map(i => [i]);
|
|
357
|
+
const metadataKeys = [Inject, Self, SkipSelf, Optional];
|
|
358
|
+
metadataKeys.forEach(key => {
|
|
359
|
+
(annotations.getParamMetadata(key) || []).forEach(item => {
|
|
360
|
+
deps[item.parameterIndex].push(item.metadata);
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
return {
|
|
364
|
+
scope: metadata.metadata.provideIn,
|
|
365
|
+
deps
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
function normalizeDeps(provide, deps) {
|
|
369
|
+
return deps.map((dep, index) => {
|
|
370
|
+
const r = {
|
|
371
|
+
injectKey: null,
|
|
372
|
+
optional: false,
|
|
373
|
+
visibility: null
|
|
374
|
+
};
|
|
375
|
+
if (!Array.isArray(dep)) {
|
|
376
|
+
r.injectKey = dep;
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
for (let i = 0; i < dep.length; i++) {
|
|
380
|
+
const item = dep[i];
|
|
381
|
+
if (item instanceof Inject) {
|
|
382
|
+
r.injectKey = item.token;
|
|
383
|
+
}
|
|
384
|
+
else if (item instanceof Self || item instanceof SkipSelf) {
|
|
385
|
+
r.visibility = item;
|
|
386
|
+
}
|
|
387
|
+
else if (item instanceof Optional) {
|
|
388
|
+
r.optional = true;
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
r.injectKey = item;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (typeof r.injectKey === 'undefined') {
|
|
396
|
+
throw new Error(`The ${index} th dependent parameter type of \`${stringify(provide)}\` was not obtained,
|
|
397
|
+
if the dependency is declared later, you can refer to it using \`constructor(@Inject(forwardRef(() => [Type|InjectionToken])) paramName: [Type]) {}\``);
|
|
398
|
+
}
|
|
399
|
+
return r;
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const reflectiveInjectorErrorFn = (token) => {
|
|
404
|
+
return makeError('ReflectiveInjector')(`No provide for \`${stringify(token)}\`!`);
|
|
405
|
+
};
|
|
406
|
+
const provideScopeError = (token) => {
|
|
407
|
+
return makeError('ProvideScope')(`Can not found provide scope \`${stringify(token)}\`!`);
|
|
49
408
|
};
|
|
409
|
+
/**
|
|
410
|
+
* 反射注入器
|
|
411
|
+
*/
|
|
412
|
+
class ReflectiveInjector extends Injector {
|
|
413
|
+
constructor(parentInjector, staticProviders, scope) {
|
|
414
|
+
super();
|
|
415
|
+
this.parentInjector = parentInjector;
|
|
416
|
+
this.staticProviders = staticProviders;
|
|
417
|
+
this.scope = scope;
|
|
418
|
+
this.recordValues = new Map();
|
|
419
|
+
this.normalizedProviders = staticProviders.map(provide => {
|
|
420
|
+
return normalizeProvider(provide);
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* 用于获取当前注入器上下文内的实例、对象或数据
|
|
425
|
+
* @param token 访问 token
|
|
426
|
+
* @param notFoundValue 如未查找到的返回值
|
|
427
|
+
* @param flags 查询规则
|
|
428
|
+
*/
|
|
429
|
+
get(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
|
|
430
|
+
var _a;
|
|
431
|
+
flags = flags || InjectFlags.Default;
|
|
432
|
+
if (flags === InjectFlags.SkipSelf) {
|
|
433
|
+
if (this.parentInjector) {
|
|
434
|
+
return this.parentInjector.get(token, notFoundValue);
|
|
435
|
+
}
|
|
436
|
+
if (notFoundValue !== THROW_IF_NOT_FOUND) {
|
|
437
|
+
return notFoundValue;
|
|
438
|
+
}
|
|
439
|
+
throw reflectiveInjectorErrorFn(token);
|
|
440
|
+
}
|
|
441
|
+
if (this.recordValues.has(token)) {
|
|
442
|
+
return this.recordValues.get(token);
|
|
443
|
+
}
|
|
444
|
+
for (let i = 0; i < this.normalizedProviders.length; i++) {
|
|
445
|
+
const normalizedProvider = this.normalizedProviders[i];
|
|
446
|
+
if (normalizedProvider.provide === token) {
|
|
447
|
+
return this.getValue(token, THROW_IF_NOT_FOUND, normalizedProvider);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
if (!(token instanceof InjectionToken)) {
|
|
451
|
+
const scope = (_a = getAnnotations(token).getClassMetadata(Injectable)) === null || _a === void 0 ? void 0 : _a.metadata.provideIn;
|
|
452
|
+
if (scope) {
|
|
453
|
+
const normalizedProvider = normalizeProvider(token);
|
|
454
|
+
if (this.scope === scope) {
|
|
455
|
+
this.normalizedProviders.push(normalizedProvider);
|
|
456
|
+
return this.getValue(token, THROW_IF_NOT_FOUND, normalizedProvider);
|
|
457
|
+
}
|
|
458
|
+
const parentInjector = this.parentInjector;
|
|
459
|
+
if (!parentInjector || parentInjector instanceof NullInjector) {
|
|
460
|
+
if (normalizedProvider.scope === 'root') {
|
|
461
|
+
this.normalizedProviders.push(normalizedProvider);
|
|
462
|
+
return this.getValue(token, THROW_IF_NOT_FOUND, normalizedProvider);
|
|
463
|
+
}
|
|
464
|
+
if (notFoundValue !== THROW_IF_NOT_FOUND) {
|
|
465
|
+
return notFoundValue;
|
|
466
|
+
}
|
|
467
|
+
throw provideScopeError(normalizedProvider.scope);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
if (flags === InjectFlags.Self) {
|
|
472
|
+
if (notFoundValue === THROW_IF_NOT_FOUND) {
|
|
473
|
+
throw reflectiveInjectorErrorFn(token);
|
|
474
|
+
}
|
|
475
|
+
return notFoundValue;
|
|
476
|
+
}
|
|
477
|
+
if (this.parentInjector) {
|
|
478
|
+
return this.parentInjector.get(token, notFoundValue, flags === InjectFlags.Optional ? InjectFlags.Optional : InjectFlags.Default);
|
|
479
|
+
}
|
|
480
|
+
if (notFoundValue === THROW_IF_NOT_FOUND) {
|
|
481
|
+
throw reflectiveInjectorErrorFn(token);
|
|
482
|
+
}
|
|
483
|
+
return notFoundValue;
|
|
484
|
+
}
|
|
485
|
+
getValue(token, notFoundValue, normalizedProvider) {
|
|
486
|
+
const { generateFactory, deps } = normalizedProvider;
|
|
487
|
+
const params = this.resolveDeps(deps, notFoundValue);
|
|
488
|
+
let value = this.recordValues.get(token);
|
|
489
|
+
if (value) {
|
|
490
|
+
return value;
|
|
491
|
+
}
|
|
492
|
+
const factory = generateFactory(this, (token, value) => {
|
|
493
|
+
this.recordValues.set(token, value);
|
|
494
|
+
});
|
|
495
|
+
value = factory(...params);
|
|
496
|
+
this.recordValues.set(token, value);
|
|
497
|
+
return value;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* 解决并获取依赖参数
|
|
501
|
+
* @param deps 依赖规则
|
|
502
|
+
* @param notFoundValue 未查找到时的返回值
|
|
503
|
+
* @private
|
|
504
|
+
*/
|
|
505
|
+
resolveDeps(deps, notFoundValue) {
|
|
506
|
+
return deps.map(dep => {
|
|
507
|
+
let reflectiveValue;
|
|
508
|
+
const tryValue = {};
|
|
509
|
+
const injectToken = dep.injectKey instanceof ForwardRef ? dep.injectKey.getRef() : dep.injectKey;
|
|
510
|
+
if (dep.visibility instanceof Self) {
|
|
511
|
+
reflectiveValue = this.get(injectToken, tryValue, InjectFlags.Self);
|
|
512
|
+
}
|
|
513
|
+
else if (dep.visibility instanceof SkipSelf) {
|
|
514
|
+
if (this.parentInjector) {
|
|
515
|
+
reflectiveValue = this.parentInjector.get(injectToken, tryValue);
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
if (dep.optional) {
|
|
519
|
+
// if (notFoundValue === THROW_IF_NOT_FOUND) {
|
|
520
|
+
// return null
|
|
521
|
+
// }
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
524
|
+
throw reflectiveInjectorErrorFn(injectToken);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
reflectiveValue = this.get(injectToken, tryValue);
|
|
529
|
+
}
|
|
530
|
+
if (reflectiveValue === tryValue) {
|
|
531
|
+
if (dep.optional) {
|
|
532
|
+
// if (notFoundValue === THROW_IF_NOT_FOUND) {
|
|
533
|
+
// return null
|
|
534
|
+
// }
|
|
535
|
+
// return notFoundValue
|
|
536
|
+
return null;
|
|
537
|
+
}
|
|
538
|
+
throw reflectiveInjectorErrorFn(injectToken);
|
|
539
|
+
}
|
|
540
|
+
return reflectiveValue;
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const Type = Function;
|
|
50
546
|
|
|
51
547
|
const refKey = 'ref';
|
|
52
548
|
function getObjectChanges(newProps, oldProps) {
|
|
@@ -665,14 +1161,51 @@ function withMemo(shouldUpdate, render) {
|
|
|
665
1161
|
class RootComponent extends Component {
|
|
666
1162
|
constructor(factory, parentInjector) {
|
|
667
1163
|
super(parentInjector, factory, {});
|
|
668
|
-
this.
|
|
1164
|
+
this.onChange = null;
|
|
669
1165
|
}
|
|
670
1166
|
markAsChanged() {
|
|
1167
|
+
var _a;
|
|
671
1168
|
this._changed = true;
|
|
672
|
-
this.
|
|
1169
|
+
(_a = this.onChange) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
673
1170
|
}
|
|
674
1171
|
}
|
|
675
1172
|
|
|
1173
|
+
class NativeRenderer {
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
/******************************************************************************
|
|
1177
|
+
Copyright (c) Microsoft Corporation.
|
|
1178
|
+
|
|
1179
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
1180
|
+
purpose with or without fee is hereby granted.
|
|
1181
|
+
|
|
1182
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1183
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1184
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1185
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1186
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1187
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1188
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
1189
|
+
***************************************************************************** */
|
|
1190
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
1191
|
+
|
|
1192
|
+
|
|
1193
|
+
function __decorate(decorators, target, key, desc) {
|
|
1194
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1195
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1196
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1197
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
function __metadata(metadataKey, metadataValue) {
|
|
1201
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
1205
|
+
var e = new Error(message);
|
|
1206
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1207
|
+
};
|
|
1208
|
+
|
|
676
1209
|
class RootComponentRef {
|
|
677
1210
|
}
|
|
678
1211
|
class HostRef {
|
|
@@ -1300,7 +1833,7 @@ class Viewfly extends ReflectiveInjector {
|
|
|
1300
1833
|
]);
|
|
1301
1834
|
this.config = config;
|
|
1302
1835
|
this.destroyed = false;
|
|
1303
|
-
this.
|
|
1836
|
+
this.task = null;
|
|
1304
1837
|
this.rootComponent = this.createRootComponent(config.root);
|
|
1305
1838
|
}
|
|
1306
1839
|
provide(providers) {
|
|
@@ -1324,9 +1857,15 @@ class Viewfly extends ReflectiveInjector {
|
|
|
1324
1857
|
if (this.config.autoUpdate === false) {
|
|
1325
1858
|
return this;
|
|
1326
1859
|
}
|
|
1327
|
-
|
|
1860
|
+
const refresh = () => {
|
|
1861
|
+
if (this.destroyed) {
|
|
1862
|
+
return;
|
|
1863
|
+
}
|
|
1328
1864
|
renderer.render();
|
|
1329
|
-
}
|
|
1865
|
+
};
|
|
1866
|
+
this.rootComponent.onChange = () => {
|
|
1867
|
+
this.microTask(refresh);
|
|
1868
|
+
};
|
|
1330
1869
|
return this;
|
|
1331
1870
|
}
|
|
1332
1871
|
render() {
|
|
@@ -1339,7 +1878,6 @@ class Viewfly extends ReflectiveInjector {
|
|
|
1339
1878
|
destroy() {
|
|
1340
1879
|
this.destroyed = true;
|
|
1341
1880
|
this.rootComponent.markAsDirtied();
|
|
1342
|
-
this.subscription.unsubscribe();
|
|
1343
1881
|
this.render();
|
|
1344
1882
|
}
|
|
1345
1883
|
createRootComponent(rootNode) {
|
|
@@ -1349,6 +1887,14 @@ class Viewfly extends ReflectiveInjector {
|
|
|
1349
1887
|
};
|
|
1350
1888
|
}, this);
|
|
1351
1889
|
}
|
|
1890
|
+
microTask(callback) {
|
|
1891
|
+
if (!this.task) {
|
|
1892
|
+
this.task = Promise.resolve().then(() => {
|
|
1893
|
+
this.task = null;
|
|
1894
|
+
callback();
|
|
1895
|
+
});
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1352
1898
|
}
|
|
1353
1899
|
|
|
1354
|
-
export { Component, Fragment, HostRef, JSXComponent, JSXElement, JSXText, NativeRenderer, Ref, Renderer, RootComponent, RootComponentRef, Viewfly, inject, jsx, jsxs, makeError, onDestroy, onMounted, onPropsChanged, onUpdated, provide, useDerived, useEffect, useRef, useSignal, withMemo };
|
|
1900
|
+
export { Component, ForwardRef, Fragment, HostRef, Inject, InjectFlags, Injectable, InjectionToken, Injector, JSXComponent, JSXElement, JSXText, NativeRenderer, NullInjector, Optional, Prop, Ref, ReflectiveInjector, Renderer, RootComponent, RootComponentRef, Scope, Self, SkipSelf, THROW_IF_NOT_FOUND, Type, Viewfly, forwardRef, inject, jsx, jsxs, makeError, normalizeProvider, onDestroy, onMounted, onPropsChanged, onUpdated, provide, useDerived, useEffect, useRef, useSignal, withMemo };
|