eventemitter2
Advanced tools
Comparing version 0.3.7 to 0.4.0
@@ -92,3 +92,3 @@ | ||
type = type.split(this.delimiter); | ||
type = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); | ||
@@ -203,3 +203,3 @@ var tree = this.listenerTree; | ||
handler = []; | ||
var ns = type.split(this.delimiter); | ||
var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); | ||
searchListenerTree.call(this, handler, ns, this.listenerTree, 0); | ||
@@ -318,3 +318,3 @@ } | ||
if(this.wildcard) { | ||
var ns = type.split(this.delimiter); | ||
var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); | ||
var leaf = searchListenerTree.call(this, null, ns, this.listenerTree, 0); | ||
@@ -403,3 +403,3 @@ | ||
if(this.wildcard) { | ||
var ns = type.split(this.delimiter); | ||
var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); | ||
var leaf = searchListenerTree.call(this, null, ns, this.listenerTree, 0); | ||
@@ -420,3 +420,3 @@ | ||
var handlers = []; | ||
var ns = type.split(this.delimiter); | ||
var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); | ||
searchListenerTree.call(this, handlers, ns, this.listenerTree, 0); | ||
@@ -423,0 +423,0 @@ return handlers; |
{ | ||
"name": "eventemitter2", | ||
"version": "0.3.7", | ||
"version": "0.4.0", | ||
"description": "A Node.js event emitter implementation with namespaces, wildcards, TTL and browser support.", | ||
@@ -5,0 +5,0 @@ "keywords": ["event", "events", "emitter", "eventemitter"], |
@@ -26,6 +26,6 @@ | ||
- Namespaces/Wildcards | ||
- Times To Listen (TTL), extends the `once` concept | ||
- Browser environment compatibility | ||
- 2x faster than Node.js event emitter for non-namespaced events. | ||
- Namespaces/Wildcards. | ||
- Times To Listen (TTL), extends the `once` concept with `many`. | ||
- Browser environment compatibility. | ||
- ~2x faster than Node.js event emitter for non-namespaced events. | ||
@@ -38,6 +38,5 @@ ## Differences (Non breaking, compatible with existing EventEmitter) | ||
var server = EventEmitter2({ | ||
wildcard: true, // should the event emitter use wildcards (**caution, this has a performance impact**). | ||
delimiter: '/', // the delimiter used to segment namespaces, defaults to `.`. | ||
wildcard: true, // should the event emitter use wildcards. | ||
delimiter: '::', // the delimiter used to segment namespaces, defaults to `.`. | ||
maxListeners: 20, // the max number of listeners that can be assigned to an event, defaults to 10. | ||
caseSensitive: true // this is a big red button, don't press it... or else... I'm just warning you. | ||
}); | ||
@@ -62,3 +61,11 @@ ``` | ||
- Pass in a namespaced event as an array rather than a delimited string. | ||
```javascript | ||
server.many(['foo', 'bar', 'bazz'], function() { | ||
console.log('hello'); | ||
}); | ||
``` | ||
## API | ||
@@ -65,0 +72,0 @@ |
@@ -0,3 +1,3 @@ | ||
var simpleEvents = require('nodeunit').testCase; | ||
var file = '../../lib/eventemitter2'; | ||
@@ -32,3 +32,3 @@ | ||
var type = 'some.listener.bar'; | ||
emitter.on(type, function () { | ||
@@ -44,3 +44,19 @@ test.ok(true, 'The event was raised'); | ||
}, | ||
'1a. Add a single listener on a single event (using an array).': function (test) { | ||
var emitter = this.emitter; | ||
var type = ['some', 'listener', 'bar']; | ||
emitter.on(type, function () { | ||
test.ok(true, 'The event was raised'); | ||
}); | ||
test.equal(emitter.listeners(type).length, 1, 'There are three emitters'); | ||
test.expect(1); | ||
test.done(); | ||
}, | ||
'2. Add two listeners on a single event.': function (test) { | ||
@@ -65,2 +81,23 @@ | ||
}, | ||
'2a. Add two listeners on a single event (using an array).': function (test) { | ||
var emitter = this.emitter; | ||
var type = ['some', 'listener', 'bar']; | ||
emitter.on(type, function () { | ||
test.ok(true, 'The event was raised'); | ||
}); | ||
emitter.on(type, function () { | ||
test.ok(true, 'The event was raised'); | ||
}); | ||
test.equal(emitter.listeners(type).length, 2, 'There are three emitters'); | ||
test.expect(1); | ||
test.done(); | ||
}, | ||
'3. Add three listeners on a single event.': function (test) { | ||
@@ -89,2 +126,3 @@ | ||
}, | ||
'4. Add two listeners to two different events.': function (test) { | ||
@@ -146,3 +184,3 @@ | ||
'7. Listeners on *, *.*, *.test with emissions from foo.test and other.emit': function (test) { | ||
'7. Listeners on `*`, `*.*`, `*.test` with emissions from `foo.test` and `other.emit`': function (test) { | ||
var emitter = this.emitter; | ||
@@ -164,3 +202,3 @@ var f = function () { | ||
'8. Listeners on *, *.*, foo.test with emissions from *, *.* and foo.test': function (test) { | ||
'8. Listeners on `*`, `*.*`, foo.test with emissions from `*`, `*.*` and `foo.test`': function (test) { | ||
var emitter = this.emitter; | ||
@@ -181,4 +219,18 @@ var f = function () { | ||
test.done(); | ||
} | ||
}, | ||
'9. Listeners on `*`. (using an array)': function (test) { | ||
var emitter = this.emitter; | ||
var f = function () { | ||
test.ok(true, 'the event was fired') | ||
}; | ||
emitter.on(['*'], f); | ||
emitter.emit('*') | ||
test.expect(1); | ||
test.done(); | ||
}, | ||
}); |
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
208
80290
17
2190