diff --git a/package.json b/package.json index 43a7728..3360404 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cordis", "description": "AOP Framework for Modern JavaScript Applications", - "version": "1.3.0", + "version": "1.3.1", "main": "lib/index.cjs", "module": "lib/index.ejs", "typings": "lib/index.d.ts", diff --git a/src/context.ts b/src/context.ts index a9ef144..14b0f75 100644 --- a/src/context.ts +++ b/src/context.ts @@ -98,7 +98,7 @@ export namespace Context { if (oldValue === value) return this.app[privateKey] = value if (typeof name !== 'string') return - this.emit('service', name, oldValue) + this.emit('internal/service', name, oldValue) const action = value ? oldValue ? 'changed' : 'enabled' : 'disabled' this.emit('logger/debug', 'service', name, action) }, diff --git a/src/lifecycle.ts b/src/lifecycle.ts index 89ae558..0ab213f 100644 --- a/src/lifecycle.ts +++ b/src/lifecycle.ts @@ -39,7 +39,7 @@ export class Lifecycle { _hooks: Record any][]> = {} constructor(private ctx: Context, private config: Lifecycle.Config) { - (this as Lifecycle.Delegates).on('hook', (name, listener, prepend) => { + (this as Lifecycle.Delegates).on('internal/hook', (name, listener, prepend) => { const method = prepend ? 'unshift' : 'push' const { runtime, disposables } = this.caller.state if (name === 'ready' && this.isActive) { @@ -168,7 +168,7 @@ export class Lifecycle { on(name: EventName, listener: Function, prepend = false) { // handle special events - const result = this.bail('hook', name, listener, prepend) + const result = this.bail('internal/hook', name, listener, prepend) if (result) return result const hooks = this._hooks[name] ||= [] @@ -227,7 +227,7 @@ export interface Events { 'ready'(): Awaitable 'fork': Plugin.Function 'dispose'(): Awaitable - 'service'(name: string, oldValue: any): void - 'config'(state: Plugin.Fork, config: any): void - 'hook'(name: string, listener: Function, prepend: boolean): () => boolean + 'internal/service'(name: string, oldValue: any): void + 'internal/update'(state: Plugin.Fork, config: any): void + 'internal/hook'(name: string, listener: Function, prepend: boolean): () => boolean } diff --git a/src/plugin.ts b/src/plugin.ts index b7f596f..7c5bb8f 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -41,7 +41,7 @@ export namespace Plugin { abstract dispose(): boolean abstract restart(): void - abstract update(config: any): void + abstract update(config: any, manual: boolean): void constructor(public parent: Context, public config: any) { this.context = parent.fork({ state: this }) @@ -78,11 +78,13 @@ export namespace Plugin { } } - update(config: any) { + update(config: any, manual = false) { const oldConfig = this.config const resolved = Registry.validate(this.runtime.plugin, config) this.config = resolved - this.context.emit('config', this, config) + if (!manual) { + this.context.emit('internal/update', this, config) + } if (this.runtime.isForkable) { this.restart() } else if (this.runtime.config === oldConfig) { @@ -147,7 +149,7 @@ export namespace Plugin { } if (this.using.length) { - const dispose = this.context.on('service', (name) => { + const dispose = this.context.on('internal/service', (name) => { if (!this.using.includes(name)) return this.restart() }) @@ -187,7 +189,7 @@ export namespace Plugin { } } - update(config: any) { + update(config: any, manual = false) { if (this.isForkable) { this.context.emit('logger/warn', 'app', `attempting to update forkable plugin "${this.plugin.name}", which may lead unexpected behavior`) } @@ -197,7 +199,9 @@ export namespace Plugin { for (const fork of this.children) { if (fork.config !== oldConfig) continue fork.config = resolved - this.context.emit('config', fork, config) + if (!manual) { + this.context.emit('internal/update', fork, config) + } } this.restart() }