super-event-emitter
TypeScript icon, indicating that this package has built-in type declarations

4.1.18Β β€’Β PublicΒ β€’Β Published

super-event-emitter

node version npm version downloads count size license github-ci

πŸ”¨ Lightweight and simple interpretation of popular event management / aggregation

Motivation

I was created a blog post (in polish) about this tool:
https://piecioshka.pl/blog/2016/01/29/narzedzia-swiata-super-event-emitter-js.html

Installation

npm install super-event-emitter

Usage β€” CommonJS

const EventEmitter = require('super-event-emitter');
// or
const { EventEmitter } = require('super-event-emitter');

Usage β€” ECMAScript Modules (ex. in TypeScript world)

import { EventEmitter } from "super-event-emitter";
// or
// import EventEmitter from "super-event-emitter";

class Cart extends EventEmitter {
    addProduct(product: Product) {
        this.emit('cart:addProduct', { product });
    }
}

Demo #1 β€” Typical object literal

const bar = {};

EventEmitter.mixin(bar);

bar.on('test', function () {
    console.log('triggered!');
}, this);

bar.emit('test');

Demo #2 β€” Class API from ECMAScript 2015

class Person extends EventEmitter {
    say(message) {
        this.emit('say', message);
    }
}

const p1 = new Person();

p1.on('say', function (message) {
    console.log(message); // 'I love cookie'
});

p1.say('I love cookie');

Documentation

Unit tests

npm test

Code coverage

npm run coverage

License

The MIT License @ 2016

Package Sidebar

Install

npm i super-event-emitter

Weekly Downloads

176

Version

4.1.18

License

MIT

Unpacked Size

34.7 kB

Total Files

8

Last publish

Collaborators

  • piecioshka
  • mateuszkocz