event-emitter

WebJar for event-emitter

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

event-emitter
Last Version

Last Version

0.3.5
Release Date

Release Date

Type

Type

jar
Description

Description

event-emitter
WebJar for event-emitter
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/medikoo/event-emitter

Download event-emitter

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/event-emitter/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>event-emitter</artifactId>
    <version>0.3.5</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/event-emitter/
implementation 'org.webjars.npm:event-emitter:0.3.5'
// https://jarcasting.com/artifacts/org.webjars.npm/event-emitter/
implementation ("org.webjars.npm:event-emitter:0.3.5")
'org.webjars.npm:event-emitter:jar:0.3.5'
<dependency org="org.webjars.npm" name="event-emitter" rev="0.3.5">
  <artifact name="event-emitter" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='event-emitter', version='0.3.5')
)
libraryDependencies += "org.webjars.npm" % "event-emitter" % "0.3.5"
[org.webjars.npm/event-emitter "0.3.5"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.npm : es5-ext jar [0.10.14,0.11)
org.webjars.npm : d jar [1,2)

Project Modules

There are no modules declared in this project.

event-emitter

Environment agnostic event emitter

Installation

$ npm install event-emitter

To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: Browserify, Webmake or Webpack

Usage

var ee = require('event-emitter');

var MyClass = function () { /* .. */ };
ee(MyClass.prototype); // All instances of MyClass will expose event-emitter interface

var emitter = new MyClass(), listener;

emitter.on('test', listener = function (args) {
  // … react to 'test' event
});

emitter.once('test', function (args) {
  // … react to first 'test' event (invoked only once!)
});

emitter.emit('test', arg1, arg2/*…args*/); // Two above listeners invoked
emitter.emit('test', arg1, arg2/*…args*/); // Only first listener invoked

emitter.off('test', listener);              // Removed first listener
emitter.emit('test', arg1, arg2/*…args*/); // No listeners invoked

Additional utilities

allOff(obj) (event-emitter/all-off)

Removes all listeners from given event emitter object

hasListeners(obj[, name]) (event-emitter/has-listeners)

Whether object has some listeners attached to the object. When name is provided, it checks listeners for specific event name

var emitter = ee();
var hasListeners = require('event-emitter/has-listeners');
var listener = function () {};

hasListeners(emitter); // false

emitter.on('foo', listener);
hasListeners(emitter); // true
hasListeners(emitter, 'foo'); // true
hasListeners(emitter, 'bar'); // false

emitter.off('foo', listener);
hasListeners(emitter, 'foo'); // false

pipe(source, target[, emitMethodName]) (event-emitter/pipe)

Pipes all events from source emitter onto target emitter (all events from source emitter will be emitted also on target emitter, but not other way).
Returns pipe object which exposes pipe.close function. Invoke it to close configured pipe.
It works internally by redefinition of emit method, if in your interface this method is referenced differently, provide its name (or symbol) with third argument.

unify(emitter1, emitter2) (event-emitter/unify)

Unifies event handling for two objects. Events emitted on emitter1 would be also emitted on emitter2, and other way back.
Non reversible.

var eeUnify = require('event-emitter/unify');

var emitter1 = ee(), listener1, listener3;
var emitter2 = ee(), listener2, listener4;

emitter1.on('test', listener1 = function () { });
emitter2.on('test', listener2 = function () { });

emitter1.emit('test'); // Invoked listener1
emitter2.emit('test'); // Invoked listener2

var unify = eeUnify(emitter1, emitter2);

emitter1.emit('test'); // Invoked listener1 and listener2
emitter2.emit('test'); // Invoked listener1 and listener2

emitter1.on('test', listener3 = function () { });
emitter2.on('test', listener4 = function () { });

emitter1.emit('test'); // Invoked listener1, listener2, listener3 and listener4
emitter2.emit('test'); // Invoked listener1, listener2, listener3 and listener4

Tests Build Status

$ npm test

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.


Get professional support for d with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Versions

Version
0.3.5
0.3.4
0.3.1