Socket
Socket
Sign inDemoInstall

@servie/events

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @servie/events

Tiny type-safe event emitter


Version published
Weekly downloads
90K
decreased by-7.11%
Maintainers
1
Install size
21.3 kB
Created
Weekly downloads
 

Readme

Source

Events

NPM version NPM downloads Build status Build coverage Bundle size

Tiny type-safe event emitter.

Installation

npm install @servie/events --save

Usage

import { Emitter, once, ALL_EVENTS } from "@servie/events";

// Define an events interface using keys & argument tuples.
interface Events {
  test: [boolean];
  other: [string];
}

// Initialize an `Emitter` using your `Events` interface.
const events = new Emitter<Events>();

// Add or remove listeners.
const listener = (...args) => console.log(args);
const off = events.on("test", listener);

// Emit an event.
events.emit("test", true);

// Listen to _all_ events, i.e. for debugging.
const eachListener = ({ type, args }) => console.log(type, args);
const off = events.on(ALL_EVENTS, eachListener);

// "Once" utility.
const runOnce = (...args) => console.log(args);
once(events, "test", runOnce);

// Remove the listener.
off();

TypeScript

This project is written using TypeScript and publishes the definitions directly to NPM.

License

MIT

Keywords

FAQs

Last updated on 13 Apr 2021

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc