Home Reference Source

crystal-event-emitter

travis codecov dependencies documentation

A small, modern base class for event emitters — no dependencies.

Documentation

You can find a documentation here.

Examples

Inferred listeners

import EventEmitter from "crystal-event-emitter";
class Cat extends EventEmitter {
    constructor() {
        super({
            inferListeners: true
        });
    }
    onFeed() {
        console.log("More food, please!");
    }
}
const cat = new Cat();
cat.emit("feed"); // "More food, please!"

Manual listeners

import EventEmitter from "crystal-event-emitter";
class Cat extends EventEmitter {
    constructor() {
        super();
    }
    onFeed() {
        console.log("More food, please!");
    }
}
const cat = new Cat();
cat.on("feed", cat.onFeed);
cat.emit("feed"); // "More food, please!"