Skip to content

Commit

Permalink
feat(cordis): support mixin with prop mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Apr 17, 2024
1 parent 1a3f50a commit 1ee7e8a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>) {
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
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export abstract class Service<T = unknown, C extends Context = Context> {
self = Object.create(this)
}
defineProperty(self, symbols.origin, caller)
return Context.associate(Object.assign(self, props), this.name)
return Context.associate<this>(Object.assign(self, props), this.name)
}

static [Symbol.hasInstance](instance: any) {
Expand Down

0 comments on commit 1ee7e8a

Please sign in to comment.