Events
Tiny type-safe event emitter.
Installation
npm install @servie/events --save
Usage
import { Emitter, once, ALL_EVENTS } from "@servie/events";
interface Events {
test: [boolean];
other: [string];
}
const events = new Emitter<Events>();
const listener = (...args) => console.log(args);
const off = events.on("test", listener);
events.emit("test", true);
const eachListener = ({ type, args }) => console.log(type, args);
const off = events.on(ALL_EVENTS, eachListener);
const runOnce = (...args) => console.log(args);
once(events, "test", runOnce);
off();
TypeScript
This project is written using TypeScript and publishes the definitions directly to NPM.
License
MIT