tu-emitter
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Introduction

tu-emitter is a small, simple, typescript event emitter which provides clean utilities to fire and listen to events.

Usage

Inside your React project, add tu-emitter using,

yarn add tu-emitter

or with npm:

npm install tu-emitter

Quick Start

import { Emitter } from "tu-emitter";

const emitter = new Emitter();
emitter.addListener("event", function (x) {
  console.log(`event fired with args ${x}`);
});
emitter.fire("event", [5]); // Listener prints "event fired with args 5".

addListener() returns a subscription object, upon which remove can be called.

let subscription = emitter.addListener("event", listener);
subscription.remove();

License

The MIT License.

Package Sidebar

Install

npm i tu-emitter

Weekly Downloads

20

Version

0.0.2

License

MIT

Unpacked Size

11.7 kB

Total Files

17

Last publish

Collaborators

  • tejas.upmanyu