🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

event-emitter

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-emitter - npm Package Compare versions

Comparing version

to
0.3.0

.testignore

4

benchmark/many-on.js

@@ -9,4 +9,4 @@ 'use strict';

var forEach = require('es5-ext/lib/Object/for-each')
, pad = require('es5-ext/lib/String/prototype/pad')
var forEach = require('es5-ext/object/for-each')
, pad = require('es5-ext/string/#/pad')

@@ -13,0 +13,0 @@ , now = Date.now

@@ -9,4 +9,4 @@ 'use strict';

var forEach = require('es5-ext/lib/Object/for-each')
, pad = require('es5-ext/lib/String/prototype/pad')
var forEach = require('es5-ext/object/for-each')
, pad = require('es5-ext/string/#/pad')

@@ -13,0 +13,0 @@ , now = Date.now

{
"name": "event-emitter",
"version": "0.2.2",
"description": "Cross-environment event emitter",
"version": "0.3.0",
"description": "Environment agnostic event emitter",
"author": "Mariusz Nowak <medyk@medikoo.com> (http://www.medikoo.com/)",
"keywords": [

@@ -11,6 +12,5 @@ "event",

"listener",
"emitter"
"emitter",
"pubsub"
],
"author": "Mariusz Nowak <medikoo+event-emitter@medikoo.com> (http://www.medikoo.com/)",
"main": "lib",
"repository": {

@@ -20,19 +20,13 @@ "type": "git",

},
"bugs": {
"email": "medikoo+event-emitter@medikoo.com",
"url": "https://github.com/medikoo/event-emitter/issues"
},
"dependencies": {
"es5-ext": "~0.9.2"
"es5-ext": "~0.10.2",
"d": "~0.1.1"
},
"devDependencies": {
"tad": "~0.1.21"
},
"scripts": {
"test": "node ./node_modules/tad/bin/tad lib"
"test": "node ./node_modules/tad/bin/tad"
},
"devDependencies": {
"tad": "~0.1.16"
},
"licence": "MIT",
"engines": {
"node": ">=0.4"
}
"licence": "MIT"
}

@@ -1,5 +0,12 @@

# EventEmitter – Cross-environment event emitter solution for JavaScript
# event-emitter
## Environment agnostic event emitter
## Usage
### 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](http://browserify.org/), [Webmake](https://github.com/medikoo/modules-webmake) or [Webpack](http://webpack.github.io/)
### Usage
```javascript

@@ -24,50 +31,42 @@ var ee = require('event-emitter');

```
### Additional utilities
## Installation
### NPM
#### allOff(obj) _(event-emitter/all-off)_
In your project path:
Removes all listeners from given event emitter object
$ npm install event-emitter
#### hasListeners(obj[, name]) _(event-emitter/has-listeners)_
### Browser
Whether there are any listeners attached to the object.
If `name` is provided, it checks whether are there any listeners attached for specific event
Browser bundle can be easily created with help of [modules-webmake](https://github.com/medikoo/modules-webmake). Assuming that you have latest [Node.js](http://nodejs.org/) and [Git](http://git-scm.com/) installed, following will work in command shell of any system (Linux/MacOS/Windows):
```javascript
var emitter = ee();
var hasListeners = require('event-emitter/has-listeners');
var listener = function () {};
```
$ npm install -g webmake
$ git clone git://github.com/medikoo/event-emitter.git
$ cd event-emitter
$ npm install
$ cd ..
$ webmake --name=eventEmitter event-emitter/lib/index.js event-emitter.js
```
hasListeners(emitter); // false
If you work with AMD modules, add _amd_ option, so generated bundle is one:
emitter.on('foo', listener);
hasListeners(emitter); // true
hasListeners(emitter, 'foo'); // true
hasListeners(emitter, 'bar'); // false
emitter.off('foo', listener);
hasListeners(emitter, 'foo'); // false
```
$ webmake --name=eventEmitter --amd event-emitter/lib/index.js event-emitter.js
```
_Mind that eventEmitter relies on some EcmaScript5 features, so for older browsers you need to load as well [es5-shim](https://github.com/kriskowal/es5-shim)_
#### pipe(source, target) _(event-emitter/pipe)_
## Functionalities provided as separate modules
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_.
### allOff(obj)
#### unify(emitter1, emitter2) _(event-emitter/unify)_
Remove all listeners
Unifies event handling for two objects. Events emitted on _emitter1_ would be also emitter on _emitter2_, and other way back, events emitter on _emitter2_ would be emitter on _emitter1_ (both objects share same listeners collection).
Non reversible.
```javascript
var eeAllOff = require('event-emitter/lib/all-off');
eeAllOff(emitter); // Removed all registered listeners on emitter
```
var eeUnify = require('event-emitter/unify');
### unify(emitter1, emitter2)
Unify listeners database of two emitter.
Events emitted on either emitter will call listeners attached to emitter object
```javascript
var eeUnify = require('event-emitter/lib/unify');
var emitter1 = ee(), listener1, listener3;

@@ -94,24 +93,5 @@ var emitter2 = ee(), listener2, listener4;

### hasListeners(obj[, type])
Whether given object have registered listeners
### Tests [![Build Status](https://secure.travis-ci.org/medikoo/event-emitter.png?branch=master)](https://secure.travis-ci.org/medikoo/event-emitter)
```javascript
var emitter = ee();
var hasListeners = require('event-emitter/lib/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
```
## Tests [![Build Status](https://secure.travis-ci.org/medikoo/event-emitter.png?branch=master)](https://secure.travis-ci.org/medikoo/event-emitter)
$ npm test
'use strict';
var ee = require('../lib/core');
var ee = require('../');

@@ -5,0 +5,0 @@ module.exports = function (t, a) {

'use strict';
var ee = require('../lib/core');
var ee = require('../');

@@ -5,0 +5,0 @@ module.exports = function (t) {

'use strict';
module.exports = function (t, a) {
var x = {}, y, count, count2;
var x = t(), y, count, count2, count3, count4, test, listener1, listener2;
// Basic check
x.emit('none');
test = "Once: ";
count = 0;
t(x);
x.on('foo', function () {
x.once('foo', function (a1, a2, a3) {
a(this, x, test + "Context");
a.deep([a1, a2, a3], ['foo', x, 15], test + "Arguments");
++count;
});
x.emit('foobar');
a(count, 0, test + "Not invoked on other event");
x.emit('foo', 'foo', x, 15);
a(count, 1, test + "Emitted");
x.emit('foo');
a(count, 1, test + "Emitted once");
a(count, 1, "Emitted");
test = "On & Once: ";
count = 0;
x.on('foo', listener1 = function (a1, a2, a3) {
a(this, x, test + "Context");
a.deep([a1, a2, a3], ['foo', x, 15], test + "Arguments");
++count;
});
count2 = 0;
x.once('foo', listener2 = function (a1, a2, a3) {
a(this, x, test + "Context");
a.deep([a1, a2, a3], ['foo', x, 15], test + "Arguments");
++count2;
});
t.allOff(x);
x.emit('foobar');
a(count, 0, test + "Not invoked on other event");
x.emit('foo', 'foo', x, 15);
a(count, 1, test + "Emitted");
x.emit('foo', 'foo', x, 15);
a(count, 2, test + "Emitted twice");
a(count2, 1, test + "Emitted once");
x.off('foo', listener1);
x.emit('foo');
a(count, 1, "All Off");
a(count, 2, test + "Not emitter after off");
y = t();
count = 0;
x.once('foo', listener1 = function () { ++count; });
x.off('foo', listener1);
x.emit('foo');
a(count, 0, "Once Off: Not emitted");
count = 0;
x.on('foo', listener2 = function () {});
x.once('foo', listener1 = function () { ++count; });
x.off('foo', listener1);
x.emit('foo');
a(count, 0, "Once Off (multi): Not emitted");
x.off('foo', listener2);
test = "Prototype Share: ";
y = Object.create(x);
count = 0;
count2 = 0;
count3 = 0;
count4 = 0;
x.on('foo', function () {

@@ -29,6 +78,31 @@ ++count;

});
t.pipe(x, y);
x.once('foo', function () {
++count3;
});
y.once('foo', function () {
++count4;
});
x.emit('foo');
a(count, 1, "Pipe: x emitted");
a(count2, 1, "Pipe: y emitted");
a(count, 1, test + "x on count");
a(count2, 0, test + "y on count");
a(count3, 1, test + "x once count");
a(count4, 0, test + "y once count");
y.emit('foo');
a(count, 1, test + "x on count");
a(count2, 1, test + "y on count");
a(count3, 1, test + "x once count");
a(count4, 1, test + "y once count");
x.emit('foo');
a(count, 2, test + "x on count");
a(count2, 1, test + "y on count");
a(count3, 1, test + "x once count");
a(count4, 1, test + "y once count");
y.emit('foo');
a(count, 2, test + "x on count");
a(count2, 2, test + "y on count");
a(count3, 1, test + "x once count");
a(count4, 1, test + "y once count");
};
'use strict';
var ee = require('../lib/core');
var ee = require('../');

@@ -5,0 +5,0 @@ module.exports = function (t, a) {

'use strict';
var ee = require('../lib/core')
, id = require('../lib/_id');
var ee = require('../');

@@ -29,3 +28,3 @@ module.exports = function (t) {

t(x, y);
a(x[id], y[id], "Post unify y");
a(x.__ee__, y.__ee__, "Post unify y");
x.emit('foo');

@@ -42,3 +41,3 @@ a(count, 2, "Post unify, x");

t(x, z);
a(x[id], x[id], "Post unify z");
a(x.__ee__, x.__ee__, "Post unify z");
x.emit('foo');

@@ -66,3 +65,3 @@ a(count, 4, "Post unify z, x");

t(x, y);
a(x[id], y[id], "Post unify y");
a(x.__ee__, y.__ee__, "Post unify y");
x.on('foo', function () { ++count; });

@@ -80,3 +79,3 @@ x.emit('foo');

t(x, z);
a(x[id], z[id], "Post unify z");
a(x.__ee__, z.__ee__, "Post unify z");
z.on('foo', function () { ++count3; });

@@ -109,3 +108,3 @@ x.emit('foo');

t(x, y);
a(x[id], y[id], "Post unify y");
a(x.__ee__, y.__ee__, "Post unify y");
x.emit('foo');

@@ -122,3 +121,3 @@ a(count, 2, "Post unify, x");

t(x, z);
a(x[id], x[id], "Post unify z");
a(x.__ee__, x.__ee__, "Post unify z");
x.emit('foo');

@@ -128,4 +127,4 @@ a(count, 4, "Post unify z, x");

a(count3, 1, "Post unify z, z");
},
}
};
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet