A TypeScript friendly event emitter with easy re-emitting events

Overview

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

Remit

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.

You might also like...

Catalogist is the easy way to catalog and make your software and (micro)services visible to your organization in a lightweight and developer-friendly way.

Catalogist is the easy way to catalog and make your software and (micro)services visible to your organization in a lightweight and developer-friendly way.

catalogist 📚 📓 📒 📖 🔖 The easy way to catalog and make your software and (micro)services visible to your organization through an API You were a pe

Dec 13, 2022

🦫 A simple way to implement event sourcing in TypeScript

✨ Better DevX for Event Sourcing in TypeScript Castore provides a unified interface for implementing Event Sourcing in TypeScript. Define your events

Nov 18, 2022

Better DevX for Event Sourcing in TypeScript 🧑‍💻

Better DevX for Event Sourcing in TypeScript 🧑‍💻

Castore 🦫 Better DevX for Event Sourcing in TypeScript Castore provides a unified interface for implementing Event Sourcing in TypeScript 🦸‍♂️ . 🤔

Dec 22, 2022

Adds `swiped` events to the DOM in 0.7k of pure JavaScript

Adds `swiped` events to the DOM in 0.7k of pure JavaScript

swiped-events A 0.7k script that adds swiped-left, swiped-right, swiped-up and swiped-down events to the DOM using CustomEvent and pure JS. Based on t

Jan 8, 2023

AppRun is a JavaScript library for developing high-performance and reliable web applications using the elm inspired architecture, events and components.

AppRun is a JavaScript library for developing high-performance and reliable web applications using the elm inspired architecture, events and components.

AppRun AppRun is a JavaScript library for building reliable, high-performance web applications using the Elm-inspired architecture, events, and compon

Dec 20, 2022

Web Gesture Events

Web Gesture Events A library that brings high-level asynchronous gesture events to the web by extending the standard addEventListener interface. ☝🏾 ?

May 29, 2022

Integrate Railway Project events with Telegram Chat/Channel using Railway Webhooks

Railway to Telegram Integrate Railway Project events with Telegram Chat/Channel using Railway Webhooks! One Click Self Deploy Manual Self Deploy Fork

Jul 5, 2022

It's the ragemp server middlewares for events

RageMP Server Middlewares Данный пример промежуточных функций разработан, чтобы любые другие разработчики могли им пользоваться. Документация: App App

Sep 8, 2022

An open-source analytics library to measure user events the hassle-free way.

An open-source analytics library to measure user events the hassle-free way.

walker.js The walker.js is an open-source event tracker for all tools. Easy, standardized & flexible. Capture user events in the browser by setting HT

Dec 22, 2022
Owner
CRIMX
Code with ❤️️.
CRIMX
👀 A Node.js event emitter works in the browser

observer-emit ?? A Node.js event emitter works in the browser. Install using npm $ npm i observer-emit using yarn $ yarn add observer-emit using pnpm

Akashi 3 Jul 2, 2022
Plug-and-play, faster-than-native promise/callback event emitter

kNow Blazing-fast callback/promise-based events with a tiny footprint What is this? With kNow (pronounced "now"—the k's silent), JavaScript event mana

Elijah Bodden 25 Sep 11, 2022
A Geiger counter for Google emitting a sound for each request that goes to Google.

Google Teller This is a (Firefox) add-on (WebExtension) that emits a sound every time you connect to a service hosted by Google. It is inspired by @be

rugk 35 Nov 5, 2022
Event scheduler is a simple app for viewing the events happening around you

Event scheduler is a simple app for viewing the events happening around you. User can also create their event and include a location. Location can also be marked as hidden(strictly by IV). Built with React and Styled Components

Anselem Odimegwu 3 Mar 29, 2022
Timers for Lost Ark bosses, islands, events, wandering merchants and more! Never miss an event again.

Timers for Lost Ark bosses, islands, events, wandering merchants and more! Never miss an event again. LostArkTimer.app Website Website Features Event

Joshua Kuan 28 Oct 17, 2022
io-ts Typed Event Bus for the runtime of your Node.js application. A core for any event-driven architecture based app.

Typed Event Bus Based on io-ts types, this bus provides a handy interface to publish and consume events in the current runtime of the Node.js process.

Konstantin Knyazev 3 May 23, 2022
'event-driven' library aims to simplify building backends in an event driven style

'event-driven' library aims to simplify building backends in an event driven style(event driven architecture). For message broker, light weight Redis Stream is used and for event store, the well known NoSQL database, MongoDB, is used.

Sihoon Kim 11 Jan 4, 2023
jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested on Firefox/Chrome/Maxthon/iPhone/Android. Very light <7ko min.js and <1Ko min.css.

Nice-Scrollbar Responsive jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested

Renan LAVAREC 2 Jan 18, 2022
A tiny, SSR-friendly hook for listening to gamepad events.

useGamepadEvents useGamepadEvents is a tiny, SSR-friendly hook for listening to gamepad events. It's a wrapper around the Gamepad API designed for fir

Hayden Bleasel 2 Oct 2, 2022
💡 Providing easy access to human-friendly Web3 data.

?? Providing easy access to human friendly Web3 data. Unidata Docs The beauty of Web3 is that everyone owns their data, but accessing and displaying o

Natural Selection Labs 263 Dec 29, 2022