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

kilt

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kilt

Combines multiple event emitters into a single emitter

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.9K
decreased by-31.28%
Maintainers
2
Weekly downloads
 
Created
Source

#kilt

Combines multiple event emitters into a single emitter.

Build Status

Lead Maintainer - Emily Rose

Usage

Installation:

$ npm install --save kilt

Instantiate a kilt instance with the event emitters to combine and listen for events on the new kilt instance. Kilt derives from EventEmitter and may also be used to emit events.

var Events = require('events');
var Kilt   = require('kilt');

var emitter1 = new Events.EventEmitter();
var emitter2 = new Events.EventEmitter();

var kilt = new Kilt([emitter1, emitter2]);

// A single handler for both emitters.
kilt.on('hello', function (data) {
    console.log(data);
});

// Emit events from multiple emitters.
emitter1.emit('hello', 'Hello from emitter1');
emitter2.emit('hello', 'Hello from emitter2');

// Emit a event using kilt.
kilt.emit('hello', 'Hello from Kilt');

Output:

Hello from emitter1
Hello from emitter2
Hello from kilt

Methods

Kilt([emitter(s)])

Kilt constructor which accepts optional emitters to manage.

var kilt = new Kilt();
... = new Kilt(emitter);
... = new Kilt([emitter]);
... = new Kilt([emitter1, emitter2]);
addEmitter(emitter)

Add an emitter for kilt to manage.

var emitter = new Events.Emitter();
kilt.addEmitter(emitter);
on(type, listener)

Attach a listener to all emitters with the specified type.

kilt.on('example', function (data) {
    console.log(data);
});
once(type, listener)

Attach a listener to all emitters with the specified type that will only fire once.

kilt.once('example', console.log.bind(console, '"example" event emitted once with data:'));
removeListener(type, listener)

Remove the specified listener.

var emitter = new Events.Emitter();
var listener = function () {
    return;
};

kilt.addEmitter(emitter);

// Attach listener.
kilt.on('example', listener);

// Remove listener.
kilt.removeListener('example', listener);
removeAllListeners([type])

Remove all listeners. Optionally, you may specify the type of listeners to remove.

// Attach listeners.
kilt.on('example', ...);
kilt.on('example', ...);
kilt.on('example', ...);
kilt.on('other', ...);

// Only remove listeners of a specific type.
kilt.removeAllListeners('example');

// Remove all listeners.
kilt.removeAllListeners();
emit(type[, data])

Emit the specified event with the specified, optional data.

var emitter = new Events.Emitter();
var kilt = new Kilt(emitter);

// Attach listener.
kilt.on('example', console.log.bind(console, '"example" event emitted with data:'));

// Emit event on kilt.
kilt.emit('example', 'emitted');

Keywords

FAQs

Package last updated on 28 Jul 2016

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