diff --git a/package.json b/package.json index ea9d795..ec97bf8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cordis", "description": "AOP Framework for Modern JavaScript Applications", - "version": "2.8.8", + "version": "2.9.3", "sideEffects": false, "main": "lib/index.cjs", "module": "lib/index.mjs", @@ -45,6 +45,6 @@ "typescript": "^5.1.6" }, "dependencies": { - "cosmokit": "^1.4.5" + "cosmokit": "^1.5.1" } } diff --git a/src/registry.ts b/src/registry.ts index 826dfee..1a3666f 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -23,6 +23,8 @@ export namespace Plugin { reusable?: boolean Config?: (config?: S) => T schema?: (config?: S) => T + inject?: readonly string[] + /** @deprecated use `inject` instead */ using?: readonly string[] } @@ -35,7 +37,7 @@ export namespace Plugin { declare module './context' { export interface Context { - using(using: readonly string[], callback: Plugin.Function>): ForkScope> + using(deps: readonly string[], callback: Plugin.Function>): ForkScope> plugin>, T extends Plugin.Config>(plugin: S, config?: boolean | T): ForkScope> /** @deprecated use `ctx.registry.delete()` instead */ dispose(plugin?: Plugin>): boolean @@ -90,8 +92,8 @@ export class Registry extends Map, MainSc return runtime.dispose() } - using(using: readonly string[], callback: Plugin.Function) { - return this.plugin({ using, apply: callback, name: callback.name }) + using(inject: readonly string[], callback: Plugin.Function) { + return this.plugin({ inject, apply: callback, name: callback.name }) } plugin(plugin: Plugin, config?: any) { diff --git a/src/scope.ts b/src/scope.ts index ac6633d..b759814 100644 --- a/src/scope.ts +++ b/src/scope.ts @@ -287,7 +287,7 @@ export class MainScope extends EffectScope { setup() { this.schema = this.plugin['Config'] || this.plugin['schema'] - this.using = this.plugin['using'] || [] + this.using = this.plugin['using'] || this.plugin['inject'] || [] this.isReusable = this.plugin['reusable'] this.isReactive = this.plugin['reactive'] this.context.emit('internal/runtime', this) diff --git a/tests/fork.spec.ts b/tests/fork.spec.ts index 4afda7a..15a2bae 100644 --- a/tests/fork.spec.ts +++ b/tests/fork.spec.ts @@ -93,7 +93,7 @@ describe('Fork', () => { ctx.on(event, listener) }) const plugin = { - using: ['foo'], + inject: ['foo'], apply(ctx: Context) { ctx.on('fork', callback) }, diff --git a/tests/isolate.spec.ts b/tests/isolate.spec.ts index 5f8a88c..9ab8030 100644 --- a/tests/isolate.spec.ts +++ b/tests/isolate.spec.ts @@ -43,7 +43,7 @@ describe('Isolation', () => { const callback = jest.fn() const plugin = { reusable: true, - using: ['foo'], + inject: ['foo'], apply: callback, } diff --git a/tests/service.spec.ts b/tests/service.spec.ts index 9d5f3b5..a031552 100644 --- a/tests/service.spec.ts +++ b/tests/service.spec.ts @@ -159,7 +159,7 @@ describe('Service', () => { const qux = jest.fn(noop) class Foo extends Service { - static using = ['qux'] + static inject = ['qux'] constructor(ctx: Context) { super(ctx, 'foo', true) } @@ -167,7 +167,7 @@ describe('Service', () => { } class Bar extends Service { - static using = ['foo', 'qux'] + static inject = ['foo', 'qux'] constructor(ctx: Context) { super(ctx, 'bar', true) } diff --git a/tests/update.spec.ts b/tests/update.spec.ts index 961bb71..9c0afc0 100644 --- a/tests/update.spec.ts +++ b/tests/update.spec.ts @@ -172,7 +172,7 @@ describe('Update', () => { const root = new Context() const callback = jest.fn() const plugin = { - using: ['foo'], + inject: ['foo'], reusable: true, apply: callback, }