Comparing version 3.3.0 to 3.3.1
@@ -51,4 +51,2 @@ import { Awaitable, Promisify, Dict } from 'cosmokit'; | ||
plugin<T>(plugin: Plugin.Object<Context.Parameterized<this, T>, T>, config?: T): ForkScope<Context.Parameterized<this, T>>; | ||
/** @deprecated use `ctx.registry.delete()` instead */ | ||
dispose(plugin?: Plugin<Context.Parameterized<this>>): boolean; | ||
} | ||
@@ -78,3 +76,2 @@ export namespace Registry { | ||
plugin(plugin: Plugin<C>, config?: any): ForkScope<C> | undefined; | ||
dispose(plugin: Plugin<C>): boolean; | ||
} | ||
@@ -291,2 +288,4 @@ export interface Context { | ||
} | ||
export interface Service extends Context.Associate<'service'> { | ||
} | ||
export class Service<C extends Context = Context> { | ||
@@ -293,0 +292,0 @@ protected ctx: C; |
{ | ||
"name": "cordis", | ||
"description": "AOP Framework for Modern JavaScript Applications", | ||
"version": "3.3.0", | ||
"version": "3.3.1", | ||
"sideEffects": false, | ||
@@ -6,0 +6,0 @@ "main": "lib/index.cjs", |
@@ -151,2 +151,3 @@ import { defineProperty, Dict, isNullable } from 'cosmokit' | ||
} | ||
ctx.on('dispose', () => ctx[name] = undefined) | ||
if (isUnproxyable(value)) { | ||
@@ -177,3 +178,3 @@ ctx.emit('internal/warning', new Error(`service ${name} is an unproxyable object, which may lead to unexpected behavior`)) | ||
const caller: Context = receiver[Context.current] | ||
if (!caller[Context.internal][`${name}.${key}`]) return Reflect.get(target, key, receiver) | ||
if (!caller?.[Context.internal][`${name}.${key}`]) return Reflect.get(target, key, receiver) | ||
return caller.get(`${name}.${key}`) | ||
@@ -252,6 +253,6 @@ }, | ||
provide(name: string, value?: any, builtin?: boolean) { | ||
const internal = Context.ensureInternal.call(this) | ||
const internal = Context.ensureInternal.call(this.root) | ||
const key = Symbol(name) | ||
internal[name] = { type: 'service', key, builtin } | ||
this[key] = value | ||
this.root[key] = value | ||
} | ||
@@ -258,0 +259,0 @@ |
@@ -56,4 +56,2 @@ import { defineProperty } from 'cosmokit' | ||
plugin<T>(plugin: Plugin.Object<Context.Parameterized<this, T>, T>, config?: T): ForkScope<Context.Parameterized<this, T>> | ||
/** @deprecated use `ctx.registry.delete()` instead */ | ||
dispose(plugin?: Plugin<Context.Parameterized<this>>): boolean | ||
/* eslint-enable max-len */ | ||
@@ -169,6 +167,2 @@ } | ||
} | ||
dispose(plugin: Plugin<C>) { | ||
return this.delete(plugin) | ||
} | ||
} |
import { Awaitable, defineProperty } from 'cosmokit' | ||
import { Context } from './context' | ||
export interface Service extends Context.Associate<'service'> {} | ||
export class Service<C extends Context = Context> { | ||
@@ -12,3 +14,3 @@ protected start(): Awaitable<void> {} | ||
constructor(protected ctx: C, public name: string, immediate?: boolean) { | ||
ctx.root.provide(name) | ||
ctx.provide(name) | ||
defineProperty(this, Context.current, ctx) | ||
@@ -27,8 +29,4 @@ | ||
ctx.on('dispose', async () => { | ||
ctx[name] = undefined | ||
await this.stop() | ||
}) | ||
return Context.associate(this, name) | ||
ctx.on('dispose', () => this.stop()) | ||
return Context.associate(Context.associate(this, 'service'), name) | ||
} | ||
@@ -35,0 +33,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
174033
2967