Skip to content

Commit

Permalink
[lib] onAny
Browse files Browse the repository at this point in the history
  • Loading branch information
hij1nx committed Jul 26, 2011
1 parent f638fe9 commit 4dd40d6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
11 changes: 4 additions & 7 deletions lib/eventemitter2.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

EventEmitter2.prototype.setConf = function(conf) {
this.wildcard = conf && conf.wildcard;
this.delimiter = conf && conf.delimiter;

this.delimiter = conf && conf.delimiter || '.';
if(this.wildcard) {
this.listenerTree = new Object;
}
Expand All @@ -36,8 +35,6 @@

EventEmitter2.prototype.event = '';

EventEmitter2.prototype.verbose = false;

var searchListenerTree = function(handlers, type, tree, i) {
var listeners;

Expand Down Expand Up @@ -84,17 +81,17 @@
};

var growListenerTree = function(type, listener) {

var d = this.delimiter;

if (type.charAt(0) === d ||
type.charAt(type.length-1) === d ||
~~type.indexOf(this.delimiter)) {
this.emit('error', 'bad event name: ' + type);
}

type = type.split(d);

var tree = this.listenerTree;
var name = type.shift();

Expand Down
17 changes: 16 additions & 1 deletion test/wildcardEvents/addListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = simpleEvents({
}

this.emitter = new EventEmitter2({
wildcard : true,
wildcard: true,
verbose: true
});
callback();
Expand Down Expand Up @@ -139,5 +139,20 @@ module.exports = simpleEvents({
test.done();

},

'7. A listener should respond to two wildcards seperated by a delimiter.': function (test) {
var emitter = this.emitter;
var type = '*.*';
var f = function () {
text.ok(true, 'the event was fired')
};

emitter.on(type, f);
console.log(emitter._events)
emitter.emit('foo.foo');

test.expect(2);
test.done();
}

});

0 comments on commit 4dd40d6

Please sign in to comment.