Permalink
Browse files

[lib] init check

  • Loading branch information...
1 parent 07743cd commit 84bdec760dcd4f9e6c83a8ce8fa2d81eb523a6a1 hij1nx committed Jul 23, 2011
Showing with 12 additions and 9 deletions.
  1. +3 −3 lib/eventemitter2.js
  2. +9 −6 test/perf/benchmark.js
View
6 lib/eventemitter2.js
@@ -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;
@@ -98,7 +98,7 @@ var growListenerTree = function(type, listener) {
while (name) {
if (!tree[name]) {
- tree[name] = {};
+ tree[name] = new Object();
}
tree = tree[name];
@@ -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.
@@ -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; }
View
15 test/perf/benchmark.js
@@ -11,7 +11,6 @@ var emitter2 = new EventEmitter2;
var EventEmitter3 = require('events').EventEmitter;
var emitter3 = new EventEmitter3;
-// add tests
suite
.add('EventEmitterHeatUp', function() {
@@ -23,7 +22,6 @@ suite
})
.add('EventEmitter', function() {
-
emitter.on('test1', function () { 1==1; });
emitter.emit('test1');
emitter.removeAllListeners('test1');
@@ -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.