1.1.0 • Published 1 year ago

@tshio/event-dispatcher v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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