A small typescript library that provide some eventbus system that is """easier""" to use.
I made this library that I will use for my bot written in Typescript : I did a separate one so if you can use it if you find it useful :)
You need at least this 2 options :
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
You should import reflect-metadata at the top of your main file like this :
import "reflect-metadata";
// YOUR CODE HERE
import { EventHandler, Eventbus, Listener } from "@fangedhex/eventbus";
// 1 - Create your events
class MyCustomEvent {
constructor(public readonly value: string) {}
}
class MyCustomEvent2 {
constructor(public readonly value: number) {}
}
// 2 - Create your listener class
class MyListener {
@EventHandler
onSomething(ev: MyCustomEvent) {
console.info("TEST : " + ev.value);
}
@EventHandler
onSomething2(ev: MyCustomEvent2) {
console.info("TEST2 : " + ev.value);
}
}
// 3 - And how to use it
const eventbus = new Eventbus();
const listener = new MyListener();
eventbus.registerListener(listener);
eventbus.dispatch(new MyCustomEvent("myvalue"));
eventbus.dispatch(new MyCustomEvent2(5.5));
eventbus.dispatch(new MyCustomEvent2(5.8));
If you find any bugs or you want to give feedback feel free to do so :).