nestjs / event-emitter

Event Emitter module for Nest framework (node.js) 🦋

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feat: Add custom `EventEmitter2` implementation

rjlopezdev opened this issue · comments

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Currently, an alternative implementation of EventEmitter2 cannot be provided

Expected behavior

I don't know if this feature is an scope of this package, but I think this could provide more flexibility.

Common Interface:

interface EventEmitter {
  emit(event: IEvent): boolean;
  ...
}

EventEmitter as injection token:

abstract class EventEmitter {}

EventEmitter default implementation:

class EventEmitter2 implements EventEmitter {
  ...
}

Provide a custom implementation:

{
  provide: EventEmitter2,
  useValue: options.custom(options) || new EventEmitter2(options),
},

FYI: I try to use my custom implemetation providing it like

{
  provide: EventEmitter2,
  useValue: MyEventEmitter2(options),
},

at AppModule but it means that listeners are not registered properly

What is the motivation / use case for changing the behavior?

In some cases, could be useful to use an alternative implementation of this class.

--

@kamilmysliwiec I wish know your thoughts in order to try an implementation 🙏🏻

Thanks for your suggestion!

We don't plan to implement this in the foreseeable future but it should be fairly easy to accomplish by forking this package.

If you think your request could live outside Nest's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.