@tshio/event-dispatcher
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Event Dispatcher

npm version

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

license

This project is licensed under the terms of the MIT license.

About us:

The Software House

tsh.png

Readme

Keywords

none

Package Sidebar

Install

npm i @tshio/event-dispatcher

Weekly Downloads

22

Version

1.1.0

License

MIT

Unpacked Size

21.1 kB

Total Files

9

Last publish

Collaborators

  • vviktor
  • aherok
  • sethii
  • barograf