Skip to content

Commit

Permalink
feat: replace using with inject
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Oct 17, 2023
1 parent 3425c9c commit 13b6cdd
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions 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": "2.8.8",
"version": "2.9.3",
"sideEffects": false,
"main": "lib/index.cjs",
"module": "lib/index.mjs",
Expand Down Expand Up @@ -45,6 +45,6 @@
"typescript": "^5.1.6"
},
"dependencies": {
"cosmokit": "^1.4.5"
"cosmokit": "^1.5.1"
}
}
8 changes: 5 additions & 3 deletions src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}

Expand All @@ -35,7 +37,7 @@ export namespace Plugin {

declare module './context' {
export interface Context {
using(using: readonly string[], callback: Plugin.Function<void, Context.Configured<this>>): ForkScope<Context.Configured<this>>
using(deps: readonly string[], callback: Plugin.Function<void, Context.Configured<this>>): ForkScope<Context.Configured<this>>
plugin<S extends Plugin<Context.Configured<this>>, T extends Plugin.Config<S>>(plugin: S, config?: boolean | T): ForkScope<Context.Configured<this, T>>
/** @deprecated use `ctx.registry.delete()` instead */
dispose(plugin?: Plugin<Context.Configured<this>>): boolean
Expand Down Expand Up @@ -90,8 +92,8 @@ export class Registry<C extends Context = Context> extends Map<Plugin<C>, MainSc
return runtime.dispose()
}

using(using: readonly string[], callback: Plugin.Function<void, C>) {
return this.plugin({ using, apply: callback, name: callback.name })
using(inject: readonly string[], callback: Plugin.Function<void, C>) {
return this.plugin({ inject, apply: callback, name: callback.name })
}

plugin(plugin: Plugin<C>, config?: any) {
Expand Down
2 changes: 1 addition & 1 deletion src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export class MainScope<C extends Context = Context> extends EffectScope<C> {

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)
Expand Down
2 changes: 1 addition & 1 deletion tests/fork.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('Fork', () => {
ctx.on(event, listener)
})
const plugin = {
using: ['foo'],
inject: ['foo'],
apply(ctx: Context) {
ctx.on('fork', callback)
},
Expand Down
2 changes: 1 addition & 1 deletion tests/isolate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Isolation', () => {
const callback = jest.fn()
const plugin = {
reusable: true,
using: ['foo'],
inject: ['foo'],
apply: callback,
}

Expand Down
4 changes: 2 additions & 2 deletions tests/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ describe('Service', () => {
const qux = jest.fn(noop)

class Foo extends Service {
static using = ['qux']
static inject = ['qux']
constructor(ctx: Context) {
super(ctx, 'foo', true)
}
start = foo
}

class Bar extends Service {
static using = ['foo', 'qux']
static inject = ['foo', 'qux']
constructor(ctx: Context) {
super(ctx, 'bar', true)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('Update', () => {
const root = new Context()
const callback = jest.fn()
const plugin = {
using: ['foo'],
inject: ['foo'],
reusable: true,
apply: callback,
}
Expand Down

0 comments on commit 13b6cdd

Please sign in to comment.