Socket
Socket
Sign inDemoInstall

ev

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ev - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

.npmignore

30

History.md

@@ -0,6 +1,13 @@

0.0.7 / 2012-06-11
==================
* Empty arrays of listeners replaced with null when no listener attached to minimize memory usage
* Added second parameter to constructor to avoid warnings
* Incoming event object is now cloned instead of modified
0.0.6 / 2012-03-08
==================
* Added stack trace to the 'Warning: undefined event...' message
* Mitigated performance regression due to scope setting
* Added stack trace to the 'Warning: undefined event...' message
* Mitigated performance regression due to scope setting

@@ -10,7 +17,6 @@ 0.0.5 / 2012-03-07

* Removed the 3 arguments limitation
* Listeners scope set to the emitting object
=> EV is now _100%_ compatible with nodejs' native EventEmitter!
* Added `version` property to the constructor
* Added warning on undefined event emission
* Removed the 3 arguments limitation
* Listeners scope set to the emitting object => EV is now _100%_ compatible with nodejs' native EventEmitter!
* Added `version` property to the constructor
* Added warning on undefined event emission

@@ -20,3 +26,3 @@ 0.0.4 / 2012-02-26

* Fix in handling ev_dedupListener where handler was always added to the cache
* Fix in handling ev_dedupListener where handler was always added to the cache

@@ -26,3 +32,3 @@ 0.0.3 / 2012-02-11

* `once()` now passes arguments
* `once()` now passes arguments

@@ -32,4 +38,4 @@ 0.0.2 / 2012-02-10

* Event [oldListener] triggered upon listener removal
* Added property ev_dedupListener (default=false): if true, will not add a listener more than once to the same event
* Added alias addEventListener === addListener
* Event [oldListener] triggered upon listener removal
* Added property ev_dedupListener (default=false): if true, will not add a listener more than once to the same event
* Added alias addEventListener === addListener

49

lib/ev.js
var maxListeners = 10
var maxLength = 3
var isError = require('util').isError
function noop () {}
function error (err) {
if (err instanceof Error)
if ( isError(err) )
throw err
else
throw new Error("Uncaught, unspecified 'error' event.")
throw new Error("Uncaught, unspecified 'error' event")
}
function sliceArguments (args, index) {
if (args.length === 0) return []
var sliceArguments = require('fnutils').slice
for (
var i = index, n = args.length, a = new Array(n - index)
; i < n
; i++
)
a[i - index] = args[i]
return a
}
/**

@@ -36,5 +28,10 @@ events: { name: argumentsLength, ... }

**/
function EventEmitter (events) {
events = events || {}
function EventEmitter (ev, quiet) {
var events = {}
// Clone the incoming events object
var evList = Object.keys(ev || {})
for (var i = 0, n = evList.length; i < n; i++)
events[ evList[i] ] = ev[ evList[i] ]
// Handler removed, emit an event

@@ -47,2 +44,5 @@ events.oldListener = 2

// No warnings on maxListeners threshold crossed
this._ev_quiet = !!quiet
// Known events

@@ -60,2 +60,4 @@ // Hash <event name>: <handler>

this._ev_maxWarning = {}
// Flag indicating warning has been issued if undefined event
this._ev_missingWarning = {}

@@ -78,3 +80,3 @@ // setMaxListeners() forces the default value

// Should be avoided to fully get V8 optimizations
if ( !this.hasOwnProperty(key) ) {
if ( !this.hasOwnProperty(key) && !this._ev_missingWarning[ev] ) {
this.removeAllListeners(ev)

@@ -88,2 +90,3 @@ this._ev_length[ev] = maxLength

console.trace()
this._ev_missingWarning[ev] = true
}

@@ -96,2 +99,5 @@

var cache = this._ev_cache[ev]
// Set the cache array only if needed
if (!cache) this._ev_cache[ev] = cache = []
var n = cache.length

@@ -101,6 +107,5 @@

for (var i = 0; i < n; i++) {
if (cache[i] === handler || cache[i].handler === handler) break
// Handler found
if (cache[i] === handler || cache[i].handler === handler) return this
}
// Handler found
if (i < n) return this
}

@@ -247,4 +252,4 @@

}
this._ev_cache[ev] = []
this._ev_maxWarning[ev] = false
this._ev_cache[ev] = null
this._ev_maxWarning[ev] = this._ev_quiet
return this

@@ -324,3 +329,3 @@ }

? this._ev_cache
: this._ev_cache[ arguments[0] ]
: (this._ev_cache[ arguments[0] ] || [])
}

@@ -327,0 +332,0 @@

@@ -6,3 +6,3 @@ {

, "keywords": ["event","emitter","listener"]
, "version": "0.0.6"
, "version": "0.0.7"
, "homepage": "http://github.com/pierrec/node-ev"

@@ -25,2 +25,3 @@ , "repository": {

, "dependencies": {
"fnutils": "latest"
}

@@ -27,0 +28,0 @@ , "devDependencies": {

@@ -35,4 +35,7 @@ # README

The constructor takes an options object listing the possible events to be emitted and their corresponding number of arguments. Note that EV *will* emit events even though they may not have been set by the constructor but performance will be affected in highly demanding situations.
`EV(events, flag`
* `events` (_Object_): events object listing the possible events to be emitted and their corresponding number of arguments. Note that EV *will* emit events even though they may not have been set by the constructor but performance will be affected in highly demanding situations.
* `flag` (_Boolean_): indicates whether warnings should be triggered (default=true)
```javascript

@@ -39,0 +42,0 @@ {

@@ -26,3 +26,3 @@ /*

describe('> 10', function () {
var ev = new EV(options)
var ev = new EV(options, true)

@@ -54,3 +54,3 @@ it('should warn', function (done) {

describe('> 5', function () {
var ev = new EV(options)
var ev = new EV(options, true)
ev.setMaxListeners(5)

@@ -83,3 +83,3 @@

describe('> 1', function () {
var ev = new EV(options)
var ev = new EV(options, true)
ev.setMaxListeners(1)

@@ -86,0 +86,0 @@

# TODO
* Performance regression 0.0.4 -> 0.0.5 caused by .call()
~* Performance regression 0.0.4 -> 0.0.5 caused by .call()
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