Browse Source

Pull request #1410: KERNEL-4583 refactor: 添加mixins定义

Merge in VISUAL/fineui from ~KIRA/fineui:master to master

* commit '61967da6bb24709fb517e9613f4221146c661e43':
  refactor: 加上注释
  KERNEL-4583 refactor: 添加mixins定义
es6
Kira 4 years ago
parent
commit
68b82c4f50
  1. 41
      typescript/core/decorator/decorator.ts

41
typescript/core/decorator/decorator.ts

@ -44,6 +44,47 @@ export function store<T>(Model: Constructor<T> & {xtype: string}, opts: { props?
}; };
} }
/**
* mixin
* ie8下不能使用
*/
export function mixin<T>() {
return function decorator(Target: Constructor<T> & { xtype: string }): void {
const mixin: {
[key: string]: Function;
} = {};
Object.getOwnPropertyNames(Target.prototype).forEach(name => {
if (name === 'constructor') {
return;
}
mixin[name] = Target.prototype[name];
});
Fix.mixin(Target.xtype, mixin);
};
}
/**
* mixins属性
* ie8下不能使用
* @param Mixins
*/
export function mixins(...Mixins: ({ new (...args: any[]): {} } & { xtype: string })[]) {
return function classDecorator<U extends { new (...args: any[]): {} }>(constructor: U) {
const mixins: string[] = [];
Mixins.forEach(mixin => {
mixin.xtype && mixins.push(mixin.xtype);
});
return class extends constructor {
mixins = mixins;
};
};
}
/** /**
* Model基类 * Model基类
*/ */

Loading…
Cancel
Save