Socket
Book a DemoInstallSign in
Socket

unemit

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unemit

Minimal event emitter

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

unemit

Travis Prettier npm License

Minimal event emitter

Usage

const unemit = require("unemit");

const emitter = unemit();

const unsubscribe = emitter.on("type", data => {
  console.log(data);
});

emitter.emit("type", { foo: "bar" });

unemit()

Returns an Emitter object

Emitter.emit(type, event)

Emits an event of type type. Will call the handlers with handler(event).

Emitter.on(type, handler)

Registers a handler for events of type type. Returns a function that removes the handler.

const unsubscribe = emitter.on("type", handler);

unsubscribe();

Unlike other libraries, unevent will prevent registering the same handler twice for the same event type.

Emitter.off(type, handler)

Removes a handler from events of type type.

Emitter.once(type, handler)

Registers a handler for only the first event of type type. It's equivalent to:

function handler() {
  emitter.off("type", handler);
}
emitter.on("type", handler);

Credits

This library was inspired by mitt.

Keywords

events

FAQs

Package last updated on 07 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts