Skip to content

Commit

Permalink
[lib] init check
Browse files Browse the repository at this point in the history
  • Loading branch information
hij1nx committed Jul 23, 2011
1 parent 07743cd commit 84bdec7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/eventemitter2.js
Expand Up @@ -89,7 +89,7 @@ var growListenerTree = function(type, listener) {
~type.indexOf(this.delimiter)) {
this.emit('error', 'bad event name: ' + type);
}

type = type.split(d);

var tree = this.listenerTree;
Expand All @@ -98,7 +98,7 @@ var growListenerTree = function(type, listener) {
while (name) {

if (!tree[name]) {
tree[name] = {};
tree[name] = new Object();
}

tree = tree[name];
Expand Down Expand Up @@ -164,6 +164,7 @@ EventEmitter2.prototype.many = function(event, ttl, fn) {
};

EventEmitter2.prototype.emit = function() {
this._events || this.init();
var type = arguments[0];
// If there is no 'error' event listener then throw.

Expand Down Expand Up @@ -287,7 +288,6 @@ EventEmitter2.prototype.un = function(type, listener) {

if(this.wildcard) {
var ns = type.split(this.delimiter);
console.log(ns)
var leaf = searchListenerTree.call(this, null, ns, this.listenerTree, 0);

if('undefined' === typeof leaf) { return this; }
Expand Down
15 changes: 9 additions & 6 deletions test/perf/benchmark.js
Expand Up @@ -11,7 +11,6 @@ var emitter2 = new EventEmitter2;
var EventEmitter3 = require('events').EventEmitter;
var emitter3 = new EventEmitter3;

// add tests
suite

.add('EventEmitterHeatUp', function() {
Expand All @@ -23,7 +22,6 @@ suite
})
.add('EventEmitter', function() {


emitter.on('test1', function () { 1==1; });
emitter.emit('test1');
emitter.removeAllListeners('test1');
Expand All @@ -37,14 +35,19 @@ suite

})

// add listeners
.add('EventEmitter2 (wild)', function() {

emitter2.on('test2.foo', function () { 1==1; });
emitter2.emit('test2.foo');
emitter2.removeAllListeners('test2.foo');

})

.on('cycle', function(event, bench) {
console.log(String(bench));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
})

// run async
.run(true);

.run(true);

0 comments on commit 84bdec7

Please sign in to comment.