ee-event-emitter
Advanced tools
Comparing version 0.1.0 to 0.1.1
module.exports = require( "./lib/EventEmitter" ); | ||
module.exports = require('./lib/EventEmitter'); |
@@ -1,36 +0,49 @@ | ||
"use strict"; | ||
!function(){ | ||
'use strict'; | ||
var Class = require( "ee-class" ) | ||
, log = require( "ee-log" ); | ||
var Class = require('ee-class') | ||
, log = require('ee-log'); | ||
// cutom events, because they less suck | ||
module.exports = new Class( { | ||
module.exports = new Class({ | ||
emit: function( event, err ){ | ||
if ( !this.$$$$_events ) Object.defineProperty( this, "$$$$_events", { value: {} } ); | ||
___events: { | ||
get: function(){ | ||
if (!this.____events) this.____events = {}; | ||
return this.____events; | ||
} | ||
} | ||
var args = arguments, i, current; | ||
if ( this.$$$$_events[ event ] ){ | ||
i = this.$$$$_events[ event ].length; | ||
while( i-- ){ | ||
current = this.$$$$_events[ event ][ i ]; | ||
if ( typeof current.listener === "function" ){ | ||
current.listener.apply( null, Array.prototype.slice.call( args, 1 ) ); | ||
if ( current.once ) this.$$$$_events[ event ].splice( i, 1 ); | ||
, emit: function(event, err) { | ||
var args = arguments | ||
, errs | ||
, i | ||
, current; | ||
if (this.___events[event]) { | ||
i = this.___events[event].length; | ||
while(i--) { | ||
current = this.___events[event][i]; | ||
if (typeof current.listener === 'function') { | ||
current.listener.apply(null, Array.prototype.slice.call(args, 1)); | ||
if (current.once) this.___events[event].splice(i, 1); | ||
} | ||
else { | ||
throw new Error( "cannot emit event [" + event + "], listener is typeof [" + typeof current.listener + "]!" ); | ||
this.$$$$_events[ event ].splice( i, 1 ); | ||
throw new Error('cannot emit event «'+event+'», listener is typeof «' + typeof current.listener + '»' ); | ||
this.___events[ event ].splice( i, 1 ); | ||
} | ||
} | ||
} | ||
else if ( event === "error" ){ | ||
var errs = Array.prototype.slice.call( args, 1 ).filter( function( a ){ return a instanceof Error; } ); | ||
var err = errs.length > 0 ? errs[ 0 ] : new Error( "Emitted an error event without an instance of an error!" ); | ||
log.error( "Cannot emit error event without listeners!" ); | ||
log.trace( err ); | ||
process.exit(); | ||
else if (event === 'error') { | ||
errs = Array.prototype.slice.call(args, 1).filter(function(a){ | ||
return a instanceof Error; | ||
}); | ||
log.error('Cannot emit error event without listeners!'); | ||
log.trace(errs[0]); | ||
} | ||
@@ -42,4 +55,4 @@ | ||
, listener: function( event ){ | ||
return this.$$$$_events && this.$$$$_events[ event ] ? this.$$$$_events[ event ] : []; | ||
, listener: function(event) { | ||
return this.___events && this.___events[event] ? this.___events[event] : []; | ||
} | ||
@@ -49,23 +62,22 @@ | ||
// remove all event s( no args ), all listeners of a specific event ( first arg ) or a specific listener ( two args ) | ||
, off: function( event, listener ){ | ||
, off: function(event, listener) { | ||
var i; | ||
if ( event ){ | ||
if ( listener && this.$$$$_events && this.$$$$_events[ event ] ){ | ||
i = this.$$$$_events[ event ].length; | ||
while( i-- ){ | ||
if ( this.$$$$_events[ event ][ i ].listener === listener ){ | ||
this.$$$$_events[ event ].splice( i, 1 ); | ||
if (event) { | ||
if (listener && this.___events[event]) { | ||
i = this.___events[event].length; | ||
while(i--) { | ||
if (this.___events[event][i].listener === listener) { | ||
this.___events[event].splice(i, 1); | ||
} | ||
} | ||
} | ||
else { | ||
if ( this.$$$$_events[ event ] ) delete this.$$$$_events[ event ]; | ||
} | ||
else if (this.___events[event]) delete this.___events[event]; | ||
} | ||
else { | ||
this.$$$$_events = Object.defineProperty( this, "$$$$_events", { value: {} } );; | ||
this.____events = {}; | ||
} | ||
this.emit( "removeListener", event, listener ); | ||
this.emit('removeListener', event, listener); | ||
@@ -76,22 +88,25 @@ return this; | ||
// add one ( two args ) or multiple events ( one arg -> object ). fired once. | ||
, once: function( event, listener ){ | ||
this.on( event, listener, true ); | ||
return this; | ||
, once: function(event, listener) { | ||
return this.on(event, listener, true); | ||
} | ||
// add one ( two args ) or multiple events ( one arg -> object ). fired once ( third arg ) | ||
, on: function( event, listener, once ){ | ||
, on: function(event, listener, once) { | ||
var keys, i; | ||
if ( typeof event === "object" ){ | ||
if (typeof event === 'object') { | ||
// multiple events | ||
keys = Object.keys( event ); | ||
i = keys.length; | ||
while( i-- ){ | ||
this.addListener( keys[ i ], event[ keys[ i ] ], once ); | ||
keys = Object.keys(event); | ||
i = keys.length; | ||
while(i--) { | ||
this.addListener(keys[i], event[keys[i]], once); | ||
} | ||
} | ||
else { | ||
this.addListener( event, listener, once ); | ||
this.addListener(event, listener, once); | ||
} | ||
@@ -104,13 +119,13 @@ | ||
// adds a listenr, somehow private | ||
, addListener: function( event, listener, once ){ | ||
if ( !this.$$$$_events ) Object.defineProperty( this, "$$$$_events", { value: {} } ); | ||
if ( !this.$$$$_events[ event ] ) this.$$$$_events[ event ] = []; | ||
, addListener: function(event, listener, once) { | ||
if (!this.___events[event]) this.___events[event] = []; | ||
this.emit( "listener", event, listener, once === true ); | ||
this.emit('listener', event, listener, once === true); | ||
this.$$$$_events[ event ].push( { | ||
listener: listener | ||
, once: once === true | ||
} ); | ||
this.___events[event].push({ | ||
listener : listener | ||
, once : !!once | ||
}); | ||
} | ||
} ); | ||
}); | ||
}(); |
{ | ||
"name": "ee-event-emitter" | ||
, "description": "event handler similar to the node.js eventEmitter class" | ||
, "version": "0.1.0" | ||
, "homepage": "https://github.com/eventEmitter/ee-event-emitter" | ||
, "author": "Michael van der Weg <michael@eventemitter.com> (http://eventemitter.com/)" | ||
"name" : "ee-event-emitter" | ||
, "description" : "An EventEmitter implementation" | ||
, "version" : "0.1.1" | ||
, "homepage" : "https://github.com/eventEmitter/ee-event-emitter" | ||
, "author" : "Michael van der Weg <michael@eventemitter.com> (http://eventemitter.com/)" | ||
, "licence" : "mit" | ||
, "repository": { | ||
"url": "https://github.com/eventEmitter/ee-event-emitter" | ||
"url" : "https://github.com/eventEmitter/ee-event-emitter.git" | ||
, "type" : "git" | ||
} | ||
, "engines": { | ||
"node": "*" | ||
"node" : ">=v0.10.0" | ||
} | ||
, "bugs": { | ||
"url": "https://github.com/eventEmitter/ee-event-emitter/issues" | ||
"url" : "https://github.com/eventEmitter/ee-event-emitter/issues" | ||
} | ||
, "dependencies": { | ||
"ee-class": ">=0.1.3" | ||
, "ee-log": "*" | ||
"ee-class" : "1.0.x" | ||
, "ee-log" : "0.2.x" | ||
} | ||
, "devDependencies": {} | ||
, "devDependencies": { | ||
"mocha" : "1.17.x" | ||
} | ||
, "optionalDependencies": {} | ||
, "keywords" : ["event", "eventemitter"] | ||
, "scripts": { | ||
"test" : "node test.js" | ||
} | ||
, "scripts": { | ||
"test" : "./node_modules/mocha/bin/mocha --reporter spec" | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
8709
8
124
1
0
1
1
+ Addedee-class@0.4.01.0.9(transitive)
+ Addedee-log@0.2.23(transitive)
+ Addedee-types@0.1.3(transitive)
- Removed@distributed-systems/callsite@1.1.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.13.2.1(transitive)
- Removedapp-root-path@2.2.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedchalk@1.1.32.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedee-class@1.4.0(transitive)
- Removedee-log@1.1.03.0.9(transitive)
- Removedee-types@2.2.1(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedlogd-console-output@1.3.0(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedsection-tests@1.3.1(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.05.5.0(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedee-class@1.0.x
Updatedee-log@0.2.x