From 7b986b59049c5ec80230ddcadc291fc8809c38d7 Mon Sep 17 00:00:00 2001 From: Kira Date: Wed, 22 Jul 2020 15:53:21 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-4583=20refactor:=20=E6=B7=BB=E5=8A=A0mix?= =?UTF-8?q?ins=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typescript/core/decorator/decorator.ts | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/typescript/core/decorator/decorator.ts b/typescript/core/decorator/decorator.ts index d55a2bc000..73f7fd910a 100644 --- a/typescript/core/decorator/decorator.ts +++ b/typescript/core/decorator/decorator.ts @@ -44,6 +44,45 @@ export function store(Model: Constructor & {xtype: string}, opts: { props? }; } +/** + * 注册mixin + */ +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属性 + * @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基类 */