Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pietile-eventemitter

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pietile-eventemitter

[![npm version](https://badgen.net/npm/v/pietile-eventemitter?color=56C838)](https://www.npmjs.com/package/pietile-eventemitter)

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
increased by12.39%
Maintainers
1
Weekly downloads
 
Created
Source

Pietile EventEmitter

npm version

Tiny typed EventEmitter for TypeScript.

Installation

Using yarn

yarn add pietile-eventemitter

or using npm

npm install -S pietile-eventemitter

Usage

Subclass or incapsulate EventEmitter specified with your events interface. Use on and off methods to setup event handlers and emit to emit events.

Example

import { EventEmitter } from 'pietile-eventemitter';

interface Events {
  foo: () => void;
  bar: (a: number) => void;
}

const emitter = new EventEmitter<Events>();

function onFoo() {
  console.log('Foo');
}

emitter.on('foo', onFoo);
const handler = emitter.on('bar', (a: number) => {
  console.log('Bar: ', a);
});

emitter.emit('foo');
emitter.emit('bar', 42);

emitter.off('foo', onFoo);
emitter.off('bar', handler);

API

new EventEmitter<T>()

Create new instance of EventEmitter. T must be interface describing events - names and signatures.

on<K>(event: K, handler: T[K]): T[K]

Add handler for event.

Return handler function. Useful for anonymous handler functions.

off<K>(event: K, handler: T[K]): void

Remove handler for event

offAll(): void

Remove all handlers for all events

emit<K>(event: K, ...args: Parameters<T[K]>): void

Emit even with its arguments

Acknowledgements

ee-ts - Type-safe, isomorphic event emitters

License

Pietile EventEmitter is MIT License.

Keywords

FAQs

Package last updated on 31 Aug 2019

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc