Comparing version 0.9.0 to 0.9.1
50
index.js
@@ -86,15 +86,19 @@ 'use strict'; | ||
function wrapEmitter(emitter, mark, prepare) { | ||
if (!emitter || !emitter.on || !emitter.addListener || !emitter.emit) { | ||
logger("can only bind real EEs"); | ||
function wrapEmitter(emitter, onAddListener, onEmit) { | ||
if (!emitter || | ||
!emitter.on || | ||
!emitter.addListener || | ||
!emitter.removeListener || | ||
!emitter.emit) { | ||
logger("can only wrap real EEs"); | ||
return; | ||
} | ||
if (!mark) { | ||
logger("must pass marker function to wrap emitter"); | ||
if (!onAddListener) { | ||
logger("must have function to run when adding a new listener"); | ||
return; | ||
} | ||
if (!prepare) { | ||
logger("must pass preparation function to wrap emitter"); | ||
if (!onEmit) { | ||
logger("must have function to wrap listeners when emitting"); | ||
return; | ||
@@ -106,6 +110,6 @@ } | ||
*/ | ||
function capturer(on) { | ||
return function captured(event, listener) { | ||
// set up the listener so that prepare can do whatever it needs | ||
mark(listener); | ||
function adding(on) { | ||
return function added(event, listener) { | ||
// set up the listener so that onEmit can do whatever it needs | ||
onAddListener(listener); | ||
@@ -117,4 +121,4 @@ try { | ||
// old-style streaming overwrites .on and .addListener, so rewrap | ||
if (!this.on.__wrapped) wrap(this, 'on', capturer); | ||
if (!this.addListener.__wrapped) wrap(this, 'addListener', capturer); | ||
if (!this.on.__wrapped) wrap(this, 'on', adding); | ||
if (!this.addListener.__wrapped) wrap(this, 'addListener', adding); | ||
} | ||
@@ -124,4 +128,4 @@ }; | ||
function puncher(emit) { | ||
return function punched(event) { | ||
function emitting(emit) { | ||
return function emitted(event) { | ||
if (!this._events || !this._events[event]) return emit.apply(this, arguments); | ||
@@ -136,3 +140,3 @@ | ||
if (typeof unwrapped === 'function') { | ||
wrapped = prepare(unwrapped); | ||
wrapped = onEmit(unwrapped); | ||
} | ||
@@ -142,3 +146,3 @@ else if (Array.isArray(unwrapped)) { | ||
for (var i = 0; i < unwrapped.length; i++) { | ||
wrapped[i] = prepare(unwrapped[i]); | ||
wrapped[i] = onEmit(unwrapped[i]); | ||
} | ||
@@ -152,4 +156,4 @@ } | ||
*/ | ||
function releaser(removeListener) { | ||
return function unwrapRemove() { | ||
function remover(removeListener) { | ||
return function removed() { | ||
this._events[event] = unwrapped; | ||
@@ -165,3 +169,3 @@ try { | ||
} | ||
wrap(this, 'removeListener', releaser); | ||
wrap(this, 'removeListener', remover); | ||
@@ -186,5 +190,5 @@ try { | ||
wrap(emitter, 'addListener', capturer); | ||
wrap(emitter, 'on', capturer); | ||
wrap(emitter, 'emit', puncher); | ||
wrap(emitter, 'addListener', adding); | ||
wrap(emitter, 'on', adding); | ||
wrap(emitter, 'emit', emitting); | ||
@@ -191,0 +195,0 @@ emitter.__unwrap = function () { |
{ | ||
"name": "shimmer", | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"description": "Safe(r) monkeypatching for JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -14,3 +14,3 @@ 'use strict'; | ||
shimmer({logger : function (message) { | ||
t.equal(message, 'can only bind real EEs', "got expected message"); | ||
t.equal(message, 'can only wrap real EEs', "got expected message"); | ||
}}); | ||
@@ -25,3 +25,3 @@ | ||
shimmer({logger : function (message) { | ||
t.equal(message, 'must pass marker function to wrap emitter', | ||
t.equal(message, 'must have function to run when adding a new listener', | ||
"got expected message"); | ||
@@ -39,3 +39,3 @@ }}); | ||
shimmer({logger : function (message) { | ||
t.equal(message, 'must pass preparation function to wrap emitter', | ||
t.equal(message, 'must have function to wrap listeners when emitting', | ||
"got expected message"); | ||
@@ -42,0 +42,0 @@ }}); |
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
26282
650