From 7b986b59049c5ec80230ddcadc291fc8809c38d7 Mon Sep 17 00:00:00 2001 From: Kira Date: Wed, 22 Jul 2020 15:53:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?KERNEL-4583=20refactor:=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0mixins=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 d55a2bc00..73f7fd910 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基类 */ From 61967da6bb24709fb517e9613f4221146c661e43 Mon Sep 17 00:00:00 2001 From: Kira Date: Wed, 22 Jul 2020 15:56:47 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=E5=8A=A0=E4=B8=8A=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typescript/core/decorator/decorator.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/typescript/core/decorator/decorator.ts b/typescript/core/decorator/decorator.ts index 73f7fd910..29ca97c55 100644 --- a/typescript/core/decorator/decorator.ts +++ b/typescript/core/decorator/decorator.ts @@ -46,6 +46,7 @@ export function store(Model: Constructor & {xtype: string}, opts: { props? /** * 注册mixin + * ie8下不能使用 */ export function mixin() { return function decorator(Target: Constructor & { xtype: string }): void { @@ -67,6 +68,7 @@ export function mixin() { /** * 类注册mixins属性 + * ie8下不能使用 * @param Mixins */ export function mixins(...Mixins: ({ new (...args: any[]): {} } & { xtype: string })[]) {