@tshio/event-dispatcher
v1.1.0
Published
Event Dispatcher
Downloads
317
Readme
Event Dispatcher
Non-blocking Event Dispatcher library for Node.js.
This is a 100% JavaScript library, with TypeScript definition, with the Promise API.
Installing
$ npm install @tshio/event-dispatcher
or
yarn add @tshio/event-dispatcher
Usage
// CommonJS
const { Event, EventDispatcher, EventSubscriberInterface } = require('@tshio/event-dispatcher');
// ES Module
import { Event, EventDispatcher, EventSubscriberInterface } from '@tshio/event-dispatcher';
const dispatcher = new EventDispatcher(console);
const stubEvent = {
name: "test",
payload: {
foo: 1,
bar: 2,
baz: 3,
},
};
dispatcher.subscribe("test", (event) => {
console.log(event);
// => "{
// name: "test",
// payload: {
// foo: 1,
// bar: 2,
// baz: 3,
// }
});
dispatcher.dispatch(stubEvent);
License
This project is licensed under the terms of the MIT license.
About us:
The Software House