From 1ee7e8ab30ad32a3cb2d9fd456bef689d7f96ad3 Mon Sep 17 00:00:00 2001 From: Shigma Date: Wed, 17 Apr 2024 10:17:36 +0800 Subject: [PATCH] feat(cordis): support mixin with prop mapping --- packages/core/src/context.ts | 7 ++++--- packages/core/src/service.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/core/src/context.ts b/packages/core/src/context.ts index 716f81c..f60bce3 100644 --- a/packages/core/src/context.ts +++ b/packages/core/src/context.ts @@ -284,9 +284,10 @@ export class Context { } } - mixin(name: string, mixins: string[]) { - for (const key of mixins) { - this.accessor(key, { + mixin(name: string, mixins: string[] | Dict) { + const entries = Array.isArray(mixins) ? mixins.map(key => [key, key]) : Object.entries(mixins) + for (const [key, value] of entries) { + this.accessor(value, { get() { const service = this[name] if (isNullable(service)) return service diff --git a/packages/core/src/service.ts b/packages/core/src/service.ts index de97331..b183f7c 100644 --- a/packages/core/src/service.ts +++ b/packages/core/src/service.ts @@ -87,7 +87,7 @@ export abstract class Service { self = Object.create(this) } defineProperty(self, symbols.origin, caller) - return Context.associate(Object.assign(self, props), this.name) + return Context.associate(Object.assign(self, props), this.name) } static [Symbol.hasInstance](instance: any) {