Comparing version 1.0.0 to 2.0.0
@@ -8,3 +8,4 @@ module.exports = EENano | ||
} | ||
EENano.prototype.emit = Function() | ||
EENano.prototype.emit = function noop() {} | ||
function emit(event, metadata) { | ||
@@ -14,7 +15,9 @@ var handlers = this._listeners[event] | ||
for (var i = 0; i < handlers.length; i++) { | ||
handlers[i].call(this, metadata) | ||
var fn = handlers[i].handler | ||
var thisArg = handlers[i].thisArg || this | ||
fn.call(thisArg, metadata) | ||
} | ||
} | ||
} | ||
EENano.prototype.on = function (event, handler) { | ||
EENano.prototype.on = function (event, handler, thisArg) { | ||
if (!this.hasListeners) { | ||
@@ -24,3 +27,3 @@ this.emit = emit | ||
} | ||
this._listeners[event] = this.listeners(event).concat(handler) | ||
this._listeners[event] = this.listeners(event).concat({handler: handler, thisArg: thisArg}) | ||
} | ||
@@ -27,0 +30,0 @@ EENano.prototype.events = function () { |
{ | ||
"name": "eenano", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "A tiny pessimistic event emitter. Optimized for no listeners.", | ||
@@ -5,0 +5,0 @@ "main": "eenano.js", |
@@ -8,3 +8,3 @@ eenano | ||
This EventEmitter is optimized for no listeners on an event. It should be plenty fast if there are listeners, of course... | ||
This EventEmitter is optimized for no listeners on any event. It should be plenty fast if there are listeners, of course... | ||
@@ -18,4 +18,9 @@ It doesn't do most of what the core EventEmitter library does. If you need features, just use core. | ||
* domains | ||
* polymorphic event handlers | ||
* and more! (less?) | ||
A list of what it does the core library doesn't: | ||
* Optimized for no listeners at all | ||
* Allows you to specify a `this` with `.on` to avoid `Function#bind` | ||
```javascript | ||
@@ -42,6 +47,6 @@ | ||
`.on(event, handler)` | ||
`.on(event, handler[, thisArg])` | ||
--- | ||
On `event` synchronously call `handler()` | ||
On `event` synchronously call `handler()` if provided, call `handler` with `this` set to `thisArg` | ||
@@ -48,0 +53,0 @@ `.emit(event, message)` |
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
3987
30
69