event-emitter
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -14,3 +14,3 @@ 'use strict'; | ||
, time, total, count = 1000000, i, data = {} | ||
, time, count = 1000000, i, data = {} | ||
, ee, native, ee2, signals, a = {}, b = {}; | ||
@@ -71,3 +71,3 @@ | ||
} | ||
data["EventEmitter2"] = now() - time; | ||
data.EventEmitter2 = now() - time; | ||
@@ -79,3 +79,3 @@ i = count; | ||
} | ||
data["Signals"] = now() - time; | ||
data.Signals = now() - time; | ||
@@ -82,0 +82,0 @@ forEach(data, function (value, name, obj, index) { |
@@ -14,3 +14,3 @@ 'use strict'; | ||
, time, total, count = 1000000, i, data = {} | ||
, time, count = 1000000, i, data = {} | ||
, ee, native, ee2, signals, a = {}, b = {}; | ||
@@ -61,3 +61,3 @@ | ||
} | ||
data["EventEmitter2"] = now() - time; | ||
data.EventEmitter2 = now() - time; | ||
@@ -69,3 +69,3 @@ i = count; | ||
} | ||
data["Signals"] = now() - time; | ||
data.Signals = now() - time; | ||
@@ -72,0 +72,0 @@ forEach(data, function (value, name, obj, index) { |
@@ -10,5 +10,6 @@ 'use strict'; | ||
, defineProperties = Object.defineProperties | ||
, descriptor = { configurable: true, enumerable: false, writable: true } | ||
, on, once, off, emit | ||
, colId, onceTag, methods, descriptors, base; | ||
, colId, methods, descriptors, base; | ||
@@ -23,13 +24,11 @@ colId = id + 'l_'; | ||
if (!this.hasOwnProperty(id)) { | ||
defineProperty(this, id, d(data = {})); | ||
data = descriptor.value = {}; | ||
defineProperty(this, id, descriptor); | ||
descriptor.value = null; | ||
} else { | ||
data = this[id]; | ||
} | ||
if (!data.hasOwnProperty(type)) { | ||
data[type] = listener; | ||
} else if (data[type].hasOwnProperty(colId)) { | ||
data[type].push(listener); | ||
} else { | ||
(data[type] = [data[type], listener])[colId] = true; | ||
} | ||
if (!data.hasOwnProperty(type)) data[type] = listener; | ||
else if (data[type].hasOwnProperty(colId)) data[type].push(listener); | ||
else (data[type] = [data[type], listener])[colId] = true; | ||
@@ -58,9 +57,5 @@ return this; | ||
if (!this.hasOwnProperty(id)) { | ||
return this; | ||
} | ||
if (!this.hasOwnProperty(id)) return this; | ||
data = this[id]; | ||
if (!data.hasOwnProperty(type)) { | ||
return this; | ||
} | ||
if (!data.hasOwnProperty(type)) return this; | ||
listeners = data[type]; | ||
@@ -71,7 +66,4 @@ | ||
if ((candidate === listener) || (candidate._listener === listener)) { | ||
if (listeners.length === 2) { | ||
data[type] = listeners[i ? 0 : 1]; | ||
} else { | ||
listeners.splice(i, 1); | ||
} | ||
if (listeners.length === 2) data[type] = listeners[i ? 0 : 1]; | ||
else listeners.splice(i, 1); | ||
} | ||
@@ -91,9 +83,5 @@ } | ||
if (!this.hasOwnProperty(id)) { | ||
return; | ||
} | ||
if (!this.hasOwnProperty(id)) return; | ||
data = this[id]; | ||
if (!data.hasOwnProperty(type)) { | ||
return; | ||
} | ||
if (!data.hasOwnProperty(type)) return; | ||
listeners = data[type]; | ||
@@ -100,0 +88,0 @@ |
@@ -6,1 +6,2 @@ 'use strict'; | ||
ee.pipe = require('./pipe'); | ||
ee.unify = require('./unify'); |
{ | ||
"name": "event-emitter", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Cross-environment event emitter", | ||
@@ -24,3 +24,3 @@ "keywords": [ | ||
"dependencies": { | ||
"es5-ext": "0.9.x" | ||
"es5-ext": "~0.9.2" | ||
}, | ||
@@ -31,5 +31,5 @@ "scripts": { | ||
"devDependencies": { | ||
"tad": "0.1.x" | ||
"tad": "~0.1.16" | ||
}, | ||
"optionalDependencies": {}, | ||
"licence": "MIT", | ||
"engines": { | ||
@@ -36,0 +36,0 @@ "node": ">=0.4" |
# EventEmitter – Cross-environment event emitter solution for JavaScript | ||
## Installation | ||
### NPM | ||
In your project path: | ||
$ npm install event-emitter | ||
### Browser | ||
Browser bundle can be easily created with help of [modules-webmake](https://github.com/medikoo/modules-webmake). Mind that it relies on some EcmaScript5 features, so for older browsers you need as well [es5-shim](https://github.com/kriskowal/es5-shim). | ||
## Usage | ||
@@ -36,4 +25,32 @@ | ||
## Additional functionalities (provided as separate modules) | ||
## Installation | ||
### NPM | ||
In your project path: | ||
$ npm install event-emitter | ||
### Browser | ||
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): | ||
``` | ||
$ 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 | ||
``` | ||
If you work with AMD modules, add _amd_ option, so generated bundle is one: | ||
``` | ||
$ 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)_ | ||
## Functionalities provided as separate modules | ||
### allOff(obj) | ||
@@ -48,11 +65,12 @@ | ||
### pipe(emitter1, emitter2) | ||
### unify(emitter1, emitter2) | ||
Pipe events from one emitter to other | ||
Unify listeners database of two emitter. | ||
Events emitted on either emitter will call listeners attached to emitter object | ||
```javascript | ||
var eePipe = require('event-emitter/lib/pipe'); | ||
var eeUnify = require('event-emitter/lib/unify'); | ||
var emitter1 = ee(), listener1; | ||
var emitter2 = ee(), listener2; | ||
var emitter1 = ee(), listener1, listener3; | ||
var emitter2 = ee(), listener2, listener4; | ||
@@ -65,11 +83,12 @@ emitter1.on('test', listener1 = function () { }); | ||
var pipe = eePipe(emitter1, emitter2); | ||
var unify = eeUnify(emitter1, emitter2); | ||
emitter1.emit('test'); // Invoked listener1 and listener2 | ||
emitter2.emit('test'); // Invoked just listener2 | ||
emitter2.emit('test'); // Invoked listener1 and listener2 | ||
pipe.close(); | ||
emitter1.on('test', listener3 = function () { }); | ||
emitter2.on('test', listener4 = function () { }); | ||
emitter1.emit('test'); // Invoked listener1 | ||
emitter2.emit('test'); // Invoked listener2 | ||
emitter1.emit('test'); // Invoked listener1, listener2, listener3 and listener4 | ||
emitter2.emit('test'); // Invoked listener1, listener2, listener3 and listener4 | ||
``` | ||
@@ -84,3 +103,3 @@ | ||
var hasListeners = require('event-emitter/lib/has-listeners'); | ||
var listner = function () {}; | ||
var listener = function () {}; | ||
@@ -87,0 +106,0 @@ hasListeners(emitter); // false |
@@ -41,3 +41,3 @@ 'use strict'; | ||
} | ||
} | ||
}; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
26696
24
0
716
116
Updatedes5-ext@~0.9.2