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

1.0.0 • Public • Published

event-emitter

A typed event emitter for Node.js and the browser with a simple to use unsubscribe mechanism.

npm install @mckravchyk/event-emitter --save

Example

import { EventEmitter } from '@mckravchyk/event-emitter';

interface Events {
  resize: [width: number, height: number]
}

const emitter = new EventEmitter<Events>();

const off = emitter.on('resize', (e, width, height) => { console.log(`Resize ${width} x ${height}`); });

emitter.emit('resize', 100, 200);
emitter.emit('resize', 200, 100);

off(); // Remove the listener

/@mckravchyk/event-emitter/

    Package Sidebar

    Install

    npm i @mckravchyk/event-emitter

    Weekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    14.3 kB

    Total Files

    9

    Last publish

    Collaborators

    • mckravchyk