amitt is a simple event emitter for browser and node.js
amitt helps you build functional event emitter / pubsub
Documentations for types - https://webigorkiev.github.io/amitt/
npm i amitt
// using ES6 modules
import {amitt} from "amitt";
// using CommonJS modules
const {amitt} = require("amitt");
import {amitt} from 'amitt';
const emitter = amitt();
emitter.on("fire", () => console.log("handler"));
emitter.emit("fire");
const {amitt} = require('../dist/index.js');
const emitter = amitt();
(async() => {
try {
const handler1 = async() => await new Promise(resolve => setTimeout(resolve, 1000));
const handler2 = async() => await new Promise(resolve => setTimeout(resolve, 1000));
emitter.on("fire", handler1);
emitter.on("fire-fight", handler2);
await Promise.all([...emitter.emit(/^fi/)]);
console.log("end");
} catch(e) {
console.log(e);
}
})();
Generated using TypeDoc