first commit
This commit is contained in:
1
src/core/annotation/.pydio
Normal file
1
src/core/annotation/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
966472fa-a3be-4729-a71b-ae988035f1e7
|
||||
18
src/core/annotation/Dom.annotation.ts
Normal file
18
src/core/annotation/Dom.annotation.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import OptionParamsModel from "../model/OptionParams.model";
|
||||
import { ClassName } from "../config/ClassName.config";
|
||||
|
||||
export function Dom() {
|
||||
return function (target: any, propertyName: string) {
|
||||
setTimeout(()=> {
|
||||
try {
|
||||
target[propertyName] = OptionParamsModel.VideoDom.querySelector(`.${ClassName[propertyName]}`)
|
||||
} catch (e) {
|
||||
throw new Error(`错误信息:需要绑定事件的类名:${ClassName[propertyName]}不存在
|
||||
1:请检查类名是否存在
|
||||
2:删除 ui/*.ui.ts 代码中对应的 Dom() 装饰器 和 方法
|
||||
`)
|
||||
}
|
||||
}
|
||||
,300)
|
||||
}
|
||||
}
|
||||
36
src/core/annotation/Ioc.annotation.ts
Normal file
36
src/core/annotation/Ioc.annotation.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import IocModel from "../model/Ioc.model";
|
||||
|
||||
/**
|
||||
* 收集类依赖
|
||||
* @constructor
|
||||
*/
|
||||
export function Injectable() {
|
||||
return (_constructor: { new (...args: any[]): {}; }) => {
|
||||
if(IocModel.classPool.indexOf(_constructor) !== -1) {
|
||||
throw new Error('无需重复收集类');
|
||||
} else {
|
||||
//注册
|
||||
IocModel.classPool = [_constructor]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将类依赖实例化然后注入到被装饰的属性中
|
||||
* @constructor
|
||||
*/
|
||||
export function Inject() {
|
||||
return function (target: any, propertyName: string) {
|
||||
/**
|
||||
* 使用 reflect-metadata 提供的内置 类型元数据键 design:type 通过反射拿到被装饰属性的类型
|
||||
* 也就是 类属性要实例化 的 service 类
|
||||
*/
|
||||
const propertyType: any = Reflect.getMetadata('design:type', target, propertyName);
|
||||
if (IocModel.classPool.indexOf(propertyType) == -1) {
|
||||
throw new Error('被装饰的属性所属的变量类型类,没有被装饰器@Injectable()注入,请检查!');
|
||||
} else {
|
||||
// 从存取器的数组中通过下标取出被装饰属性对应的service类,然后实例化这个类,在放入被装饰的属性中
|
||||
target[propertyName] = new (IocModel.classPool[IocModel.classPool.indexOf(propertyType)])()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user