crystal-event-emitter

A small, modern event emitter base class with no dependencies

Usage no npm install needed!

<script type="module">
  import crystalEventEmitter from 'https://cdn.skypack.dev/crystal-event-emitter';
</script>

README

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!"