Skip to content

Commit

Permalink
fix: do not override internal defs
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 8, 2024
1 parent 6c71d31 commit 3a4a309
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cordis",
"description": "AOP Framework for Modern JavaScript Applications",
"version": "3.5.1",
"version": "3.5.2",
"sideEffects": false,
"main": "lib/index.cjs",
"module": "lib/index.mjs",
Expand Down
5 changes: 3 additions & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,21 @@ export class Context {

provide(name: string, value?: any, builtin?: boolean) {
const internal = Context.ensureInternal.call(this.root)
if (name in internal) return
const key = Symbol(name)
internal[name] = { type: 'service', key, builtin }
this.root[key] = value
}

accessor(name: string, options: Omit<Context.Internal.Accessor, 'type'>) {
const internal = Context.ensureInternal.call(this.root)
internal[name] = { type: 'accessor', ...options }
internal[name] ||= { type: 'accessor', ...options }
}

alias(name: string, aliases: string[]) {
const internal = Context.ensureInternal.call(this.root)
for (const key of aliases) {
internal[key] = { type: 'alias', name }
internal[key] ||= { type: 'alias', name }
}
}

Expand Down
3 changes: 2 additions & 1 deletion tests/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ describe('Service', () => {
root.on('internal/warning', warn)
root.alias('bar', ['baz'])
root.mixin('foo', ['bar'])
root.provide('foo', { bar: 1 })
root.provide('foo')
root.foo = { bar: 1 }

// foo is a service
expect(root.get('foo')).to.be.ok
Expand Down

0 comments on commit 3a4a309

Please sign in to comment.