@kjojs/eventbus
TypeScript icon, indicating that this package has built-in type declarations

1.1.4 • Public • Published

@kjojs/eventbus

  • universal and light(1kb) event bus module
  • no dependencies
  • typescript type inference supports.
  • simple and light implementation

Installation

npm install @kjojs/eventbus --save

Getting Started

import EventBus from '@kjojs/eventbus';

const eventBus = new EventBus();

eventBus.on('a', console.log);
eventBus.on({
  b: console.log,
  c: console.log,
});

eventBus.emit('a', 2);
eventBus.emit('b', 'p');
eventBus.emit('c', { n: 1 });

Type Inference Support

interface EventDefinition {
  a: 1 | 2 | 3;
  b: 'p';
}

const eventBus = new EventBus<EventDefinition>().on({
  a: console.log,
  b: console.log,
});

/**
 * or
 *
 * new EventBus<{
 *   a: 1 | 2 | 3;
 *   b: 'p';
 * }>();
 */

Specifications

  • spec code
  • .on(eventName, eventHandler, life?)
  • .on(eventSpecification)
  • .once(eventName, eventHandler)
  • .once(eventSpecification)
  • .off()
  • .off(eventName)
  • .off(eventName, eventHandler)
  • .has()
  • .has(eventName)
  • .has(eventName, eventHandler)
  • .emit(eventName, eventPayload?)

Dependencies (0)

    Dev Dependencies (1)

    Package Sidebar

    Install

    npm i @kjojs/eventbus

    Weekly Downloads

    23

    Version

    1.1.4

    License

    MIT

    Unpacked Size

    6.07 kB

    Total Files

    11

    Last publish

    Collaborators

    • devjaewon