diff --git a/typescript/core/decorator/decorator.ts b/typescript/core/decorator/decorator.ts index d55a2bc00..29ca97c55 100644 --- a/typescript/core/decorator/decorator.ts +++ b/typescript/core/decorator/decorator.ts @@ -44,6 +44,47 @@ export function store(Model: Constructor & {xtype: string}, opts: { props? }; } +/** + * 注册mixin + * ie8下不能使用 + */ +export function mixin() { + return function decorator(Target: Constructor & { 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(constructor: U) { + const mixins: string[] = []; + + Mixins.forEach(mixin => { + mixin.xtype && mixins.push(mixin.xtype); + }); + + return class extends constructor { + mixins = mixins; + }; + }; +} + /** * Model基类 */