Nest Event
Event handler for Nest.js framework with decorators
Features
- Communicate between modules without import
- Organize event handlers with decorators
- Work with multiple Event Emitters
Installation
$ npm i --save nest-event
Usage
Import NestEventModule
into your root module (AppModule
)
// app.module.ts ;;;;
Nest Event is coming with an internal event emitter. If you provide one without a name, the module do not create the internal emitter. Also, you can use any instance with extended from EventEmitter
To provide an emitter use @Emitter
decorator.
;;;
You can provide multiple emitters with passing a name.
Event Handler
To adding a listener for an event you can use @On
decorator.
;;;
If you have multiple emitters you can separate the handlers with @From
decorator.
onSubscribechannel: string
Event Emitter
To access your emitters in different modules, controllers etc. You can use NestEventEmitter
;
If you provide multiple emitters you can select one with:
this.nestEventEmitter.emitter'my-emitter'.emit'user-created', user;
Future Goals
- Add tests;
Contributing
You are welcome to contribute to this project, just open a PR.
License
- NestEvent is MIT licensed.