New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

remitter

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remitter

A TypeScript friendly event emitter with easy re-emitting events.

0.2.3
Source
npm
Version published
Weekly downloads
824
4.3%
Maintainers
1
Weekly downloads
 
Created
Source

remitter

Build Status npm-version Coverage Status minified-size

Commitizen friendly Conventional Commits code style: prettier

A TypeScript friendly event emitter with easy re-emitting events.

Install

npm add remitter

Usage

import { Remitter } from "remitter";

interface EventConfig {
  event1: string;
  event2: void;
}

const remitter = new Remitter<EventConfig>();

const disposer = remitter.on("event1", value => {
  console.log("event1", value);
});

remitter.count("event1"); // 1

remitter.emit("event1", "hello"); // logs "event1 hello"

remitter.emit("event2"); // nothing logs

disposer();
remitter.emit("event1", "world"); // nothing logs

remitter.clear("event2"); // remove all listeners for event2
remitter.count(); // 0

remitter.destroy(); // removes all listeners and dispose tapped events

Tap

You may tap into other events which will be lazy-executed when listener count of an event name grows from 0 to 1 and be disposed when listener count drops from 1 to 0.

remitter.remit("event1", () => {
  const handler = e => {
    remitter.emit("event1", e.value + 1);
  };
  otherEvent.addListener(handler);
  return () => {
    otherEvent.removeListener(handler);
  };
});

The callback function can also be a pure function.

const tapToOtherEvent = remitter => {
  const handler = e => {
    remitter.emit("event1", e.value + 1);
  };
  otherEvent.addListener(handler);
  return () => {
    otherEvent.removeListener(handler);
  };
};

remitter.remit("event1", tapToOtherEvent);

Acknowledgment

Huge thanks to @recursivefunk for giving away the NPM package name remitter.

FAQs

Package last updated on 17 Jun 2022

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