This is a lib for making easier to create your own events using decorators.
npm install auto-event
Using the @Event()
decorator, you set your function to be an event emitter that uses
it's return as a callback parameter. After that, you can declare an event listener with the EventListener()
decorator.
import { Event, EventListener } from "auto-event";
class MyEvents {
@Event("eventName")
async trigger() {
return "Hello World!";
}
};
class MyEventListeners {
@EventListener("eventName")
async listener(eventResponse) {
console.log(eventResponse);
}
};
const myClass = new MyClass();
myClass.trigger();
// Expected output: Hello World!
You can add a listener in a different way calling the on()
function from the eventsContainer.
import eventsContainer from "auto-event";
const eventListener = eventsContainer.on("eventName", eventResponse => {
console.log(res);
});
eventListener.end()
This lib uses only this method for creating events, but it will soon be improved with other methods.