refactor(event-manager): move emit into handler
This commit is contained in:
@@ -55,6 +55,7 @@
|
||||
"bump": {
|
||||
"before": [
|
||||
"git pull --rebase",
|
||||
"git-cliff > CHANGELOG.md",
|
||||
"pnpm i",
|
||||
"node scripts/get-latest-admin-version.js"
|
||||
],
|
||||
|
||||
@@ -103,7 +103,7 @@ export class EventManagerService {
|
||||
if (instance instanceof EventEmitter2) {
|
||||
const isObjectLike = typeof data === 'object' && data !== null
|
||||
const payload = isObjectLike ? data : { data }
|
||||
instance.emit(event, payload)
|
||||
|
||||
return instance.emit(this.#key, {
|
||||
event,
|
||||
payload,
|
||||
@@ -168,7 +168,8 @@ export class EventManagerService {
|
||||
this.emitter2.on(this.#key, (data) => {
|
||||
const { event, payload } = data
|
||||
console.debug(`Received event: [${event}]`, payload)
|
||||
|
||||
// emit current event directly
|
||||
this.emitter2.emit(event, payload)
|
||||
this.#handlers.forEach((handler) => handler(event, payload))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -101,6 +101,7 @@ describe('Test ConfigsService', () => {
|
||||
it('should emit event if enable email option and update search', async () => {
|
||||
// + 1 call time because of `config.changed` event
|
||||
await service.patchAndValid('mailOptions', { enable: true })
|
||||
|
||||
expect(mockEmitFn).toBeCalledTimes(3)
|
||||
mockEmitFn.mockClear()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user