Socket
Socket
Sign inDemoInstall

tiny-emitter

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-emitter

A tiny (less than 1k) event emitter library


Version published
Weekly downloads
3.1M
decreased by-4.44%
Maintainers
1
Weekly downloads
 
Created

What is tiny-emitter?

The tiny-emitter package is a lightweight event emitter and listener library. It allows you to create an object that can emit events and have listeners that respond to those events. This is useful for creating a simple pub-sub or observer pattern implementation without the overhead of larger libraries.

What are tiny-emitter's main functionalities?

Event Emission

Emitting events with optional data. Listeners for that event will be invoked.

const Emitter = require('tiny-emitter');
let emitter = new Emitter();
emitter.emit('event', 'some data');

Event Listening

Adding a listener for an event. The listener will be called whenever the specified event is emitted.

const Emitter = require('tiny-emitter');
let emitter = new Emitter();
emitter.on('event', function(data) {
  console.log(data);
});

One-time Event Listening

Adding a one-time listener for an event. The listener will be invoked only the first time the event is emitted.

const Emitter = require('tiny-emitter');
let emitter = new Emitter();
emitter.once('event', function(data) {
  console.log(data);
});

Removing Event Listeners

Removing a specific listener from an event.

const Emitter = require('tiny-emitter');
let emitter = new Emitter();
function listener(data) {
  console.log(data);
}
emitter.on('event', listener);
emitter.off('event', listener);

Other packages similar to tiny-emitter

Keywords

FAQs

Package last updated on 05 Feb 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