wildemitter
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "wildemitter", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -5,0 +5,0 @@ "scripts": { |
# WildEmitter - A lightweight event emitter that supports wildcard handlers | ||
## What's an event emitter? | ||
If you've ever listened for a click event in a browser you've used an emitter. But, user interaction isn't the only thing that can trigger an event worth listening to. You can also make other objects capable of emitting events. That's what wildemitter is for. You can extend your objects with it so that you can emit events from them and register handlers on them. This pattern helps you write more re-usable code becaause your objct doen't have to know how it's going to be used. It can simply emit events any time something happens that other code *may* be interested in. | ||
If you've ever listened for a click event in a browser you've used an emitter. But, user interaction isn't the only thing that can trigger an event worth listening to. You can also make other objects capable of emitting events. That's what wildemitter is for. You can extend your objects with it so that you can emit events from them and register handlers on them. This pattern helps you write more re-usable code because your object doen't have to know how it's going to be used. It can simply emit events any time something happens that other code *may* be interested in. | ||
@@ -6,0 +6,0 @@ You'll see this type of pattern a lot in node.js. Where lots of things in the standard libraries inherit from EventEmitter and emit various events to indicate progress, errors, completion, etc. |
@@ -65,2 +65,5 @@ function WildEmitter() { | ||
callbacks.splice(i, 1); | ||
if (callbacks.length === 0) { | ||
delete this.callbacks[event]; | ||
} | ||
return this; | ||
@@ -67,0 +70,0 @@ }; |
@@ -94,2 +94,3 @@ var Emitter = require('./wildemitter'); | ||
var count, cb1, cb2; | ||
var orange = new Fruit('orange'); | ||
@@ -117,4 +118,10 @@ count = 0; | ||
orange.off('test2', cb2); | ||
//ensure callbacks array is removed entirely | ||
test.ok(orange.callbacks.test == null); | ||
test.ok(orange.callbacks.test2 == null); | ||
test.done(); | ||
}; | ||
@@ -65,2 +65,5 @@ function WildEmitter() { | ||
callbacks.splice(i, 1); | ||
if (callbacks.length === 0) { | ||
delete this.callbacks[event]; | ||
} | ||
return this; | ||
@@ -67,0 +70,0 @@ }; |
@@ -86,2 +86,5 @@ /* | ||
callbacks.splice(i, 1); | ||
if (callbacks.length === 0) { | ||
delete this.callbacks[event]; | ||
} | ||
return this; | ||
@@ -88,0 +91,0 @@ }; |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
19739
466
1