@hooked74/single-purpose-emitter
v1.2.5
Published
Single purpose emitter
Downloads
11
Maintainers
Readme
Install
npm install @hooked74/single-purpose-emitter
Usage
// initialize
const emitter = new SinglePurposeEmitter();
// attach handlers
const handler1 = () => console.log("handler 1");
emitter.attach(handler1);
emitter.attach((value) => console.log("handler 2", value));
// dispatch
emitter.emit("some value");
// output:
// handler 1
// handler 2 some value
// detach specific handler
emitter.detach(handler1);
// detach all handlers
emitter.detach();