1.1.0 • Published 4 years ago

@fangedhex/eventbus v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

EventBus

GitHub npm (scoped) GitHub Workflow Status Libraries.io dependency status for GitHub repo npm bundle size (scoped) npm npm

Description

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 :)

tsconfig.json

You need at least this 2 options :

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

Reflect-metadata

You should import reflect-metadata at the top of your main file like this :

import "reflect-metadata";

// YOUR CODE HERE

Example

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));

Contributing

If you find any bugs or you want to give feedback feel free to do so :).

1.1.0

4 years ago

1.1.0-rc.2

4 years ago

1.1.0-rc.1

4 years ago

1.0.0

4 years ago

1.0.0-rc.4

4 years ago

1.0.0-rc.3

4 years ago

1.0.0-rc.2

4 years ago

1.0.0-rc.1

4 years ago