Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

code

  • Loading branch information...
commit e1c6457ac0210c6600a8ff8b8ebd0785ebe19f02 1 parent a6c7d60
Raynos authored
Showing with 14,540 additions and 2 deletions.
  1. +19 −0 LICENCE
  2. +3 −2 README.md
  3. +2 −0  node_modules/after/.gitignore
  4. +4 −0 node_modules/after/.travis.yml
  5. +19 −0 node_modules/after/LICENCE
  6. +105 −0 node_modules/after/README.md
  7. +19 −0 node_modules/after/package.json
  8. +63 −0 node_modules/after/src/after.js
  9. +155 −0 node_modules/after/test/main-test.js
  10. +13 −0 node_modules/eventemitter2/.gitignore
  11. +226 −0 node_modules/eventemitter2/README.md
  12. +1 −0  node_modules/eventemitter2/index.js
  13. +453 −0 node_modules/eventemitter2/lib/eventemitter2.js
  14. +32 −0 node_modules/eventemitter2/package.json
  15. +110 −0 node_modules/eventemitter2/test/common.js
  16. +53 −0 node_modules/eventemitter2/test/perf/benchmark.js
  17. +173 −0 node_modules/eventemitter2/test/simple/addListener.js
  18. +136 −0 node_modules/eventemitter2/test/simple/emit.js
  19. +199 −0 node_modules/eventemitter2/test/simple/removeListener.js
  20. +133 −0 node_modules/eventemitter2/test/simple/setMax.js
  21. +126 −0 node_modules/eventemitter2/test/simple/ttl.js
  22. +248 −0 node_modules/eventemitter2/test/wildcardEvents/addListener.js
  23. +804 −0 node_modules/eventemitter2/test/wildcardEvents/all.js
  24. +178 −0 node_modules/eventemitter2/test/wildcardEvents/customDelimiter.js
  25. +49 −0 node_modules/eventemitter2/test/wildcardEvents/k1.js
  26. +77 −0 node_modules/eventemitter2/test/wildcardEvents/options.js
  27. +213 −0 node_modules/eventemitter2/test/wildcardEvents/removeListener.js
  28. +163 −0 node_modules/eventemitter2/test/wildcardEvents/ttl.js
  29. +4 −0 node_modules/mocha/.npmignore
  30. +4 −0 node_modules/mocha/.travis.yml
  31. +194 −0 node_modules/mocha/History.md
  32. +84 −0 node_modules/mocha/Makefile
  33. +5 −0 node_modules/mocha/Readme.md
  34. +2,819 −0 node_modules/mocha/_mocha.js
  35. +304 −0 node_modules/mocha/bin/mocha
  36. +2 −0  node_modules/mocha/bin/mocha-debug
  37. +16 −0 node_modules/mocha/editors/JavaScript mocha.tmbundle/Snippets/bdd - after each.tmSnippet
  38. +16 −0 node_modules/mocha/editors/JavaScript mocha.tmbundle/Snippets/bdd - after.tmSnippet
  39. +16 −0 node_modules/mocha/editors/JavaScript mocha.tmbundle/Snippets/bdd - before each.tmSnippet
  40. +16 −0 node_modules/mocha/editors/JavaScript mocha.tmbundle/Snippets/bdd - before.tmSnippet
  41. +16 −0 node_modules/mocha/editors/JavaScript mocha.tmbundle/Snippets/bdd - it.tmSnippet
  42. +16 −0 node_modules/mocha/editors/JavaScript mocha.tmbundle/Snippets/untitled.tmSnippet
  43. +19 −0 node_modules/mocha/editors/JavaScript mocha.tmbundle/info.plist
  44. BIN  node_modules/mocha/images/error.png
  45. BIN  node_modules/mocha/images/ok.png
  46. +2 −0  node_modules/mocha/index.js
  47. +6 −0 node_modules/mocha/lib/browser/debug.js
  48. +178 −0 node_modules/mocha/lib/browser/events.js
  49. 0  node_modules/mocha/lib/browser/fs.js
  50. +125 −0 node_modules/mocha/lib/browser/progress.js
  51. +8 −0 node_modules/mocha/lib/browser/tty.js
  52. +30 −0 node_modules/mocha/lib/hook.js
  53. +86 −0 node_modules/mocha/lib/interfaces/bdd.js
  54. +60 −0 node_modules/mocha/lib/interfaces/exports.js
  55. +4 −0 node_modules/mocha/lib/interfaces/index.js
  56. +94 −0 node_modules/mocha/lib/interfaces/tdd.js
  57. +22 −0 node_modules/mocha/lib/mocha.js
  58. +223 −0 node_modules/mocha/lib/reporters/base.js
  59. +74 −0 node_modules/mocha/lib/reporters/doc.js
  60. +62 −0 node_modules/mocha/lib/reporters/dot.js
  61. +154 −0 node_modules/mocha/lib/reporters/html.js
  62. +12 −0 node_modules/mocha/lib/reporters/index.js
  63. +61 −0 node_modules/mocha/lib/reporters/json-stream.js
  64. +70 −0 node_modules/mocha/lib/reporters/json.js
  65. +97 −0 node_modules/mocha/lib/reporters/landing.js
  66. +61 −0 node_modules/mocha/lib/reporters/list.js
  67. +84 −0 node_modules/mocha/lib/reporters/progress.js
  68. +83 −0 node_modules/mocha/lib/reporters/spec.js
  69. +63 −0 node_modules/mocha/lib/reporters/tap.js
  70. +41 −0 node_modules/mocha/lib/reporters/teamcity.js
  71. +156 −0 node_modules/mocha/lib/runnable.js
  72. +414 −0 node_modules/mocha/lib/runner.js
  73. +220 −0 node_modules/mocha/lib/suite.js
  74. +32 −0 node_modules/mocha/lib/test.js
  75. +109 −0 node_modules/mocha/lib/utils.js
  76. +17 −0 node_modules/mocha/lib/watch.js
  77. +119 −0 node_modules/mocha/mocha.css
  78. +2,907 −0 node_modules/mocha/mocha.js
  79. +25 −0 node_modules/mocha/package.json
  80. +3 −0  node_modules/pd/.gitignore
  81. +4 −0 node_modules/pd/.npmignore
  82. +3 −0  node_modules/pd/.travis.yml
  83. +19 −0 node_modules/pd/LICENCE
  84. +223 −0 node_modules/pd/README.md
  85. +471 −0 node_modules/pd/docs/styleGuide.md
  86. +1 −0  node_modules/pd/index.js
  87. +18 −0 node_modules/pd/package.json
  88. +265 −0 node_modules/pd/src/pd.js
  89. +160 −0 node_modules/pd/test/pd-test.js
  90. +19 −0 package.json
  91. +169 −0 src/core.js
  92. +179 −0 test/test-core.js
19 LICENCE
View
@@ -0,0 +1,19 @@
+Copyright (c) 2011 Raynos.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
5 README.md
View
@@ -14,12 +14,13 @@ A Core library for your node application infrastructure.
});
}
});
+
Core.use({
- init: function (mediator) {
+ init: function (done, mediator) {
var server = http.createServer(function (req, res) {
mediator.emit("helloworld", res);
});
- server.listen(4000);
+ server.listen(4000, done);
}
});
2  node_modules/after/.gitignore
View
@@ -0,0 +1,2 @@
+node_modules
+.monitor
4 node_modules/after/.travis.yml
View
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+ - 0.4
+ - 0.6
19 node_modules/after/LICENCE
View
@@ -0,0 +1,19 @@
+Copyright (c) 2011 Raynos.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
105 node_modules/after/README.md
View
@@ -0,0 +1,105 @@
+# After [![Build Status][1]][2]
+
+All the flow control you'll ever need
+
+## Status: production ready
+
+## Example
+
+ var after = require("after"),
+ next = after(3, logItWorks);
+
+ next();
+ next();
+ next(); // it works
+
+ function logItWorks() {
+ console.log("it works!");
+ }
+
+## Motivation
+
+Minimal flow control. A lot of the libraries out there are over kill. I want a small tool that gives me fundamental concrete building blocks
+
+## Documentation
+
+### after(count, callback) <a name="after" href="#after"><small><sup>link</sup></small></a>
+
+`after` takes a count and a callback and returns a function `next`. The callback get's invoked when the `next` function is invoked count number of times. The callback aggregates the data given to `next` as un-ordered parameters.
+
+ var next = after(3, printData);
+
+ next("foo", "bar", { ... })
+ next({ ... });
+ next(42);
+
+ function printData() {
+ for (var i = 0, len = arguments.length; i < len; i++) {
+ console.log(arguments[i]);
+ }
+ // in some order
+ // 42
+ // { ... }
+ // [ "foo", "bar", { ... }]
+ }
+
+### after set utilities
+
+The following methods are asynchronous parallel versions of the `Array.prototype` methods.
+
+They all take an `iterator` and a `finishedCallback`
+
+These `iterator`'s are of the form `(value, index, set, callback)`. The `callback` can be invoked with `(err, result)`
+
+The `finishedCallback` is of the form `(err, result)` as invoked when all iterators have invoked their individual callback.
+
+### after.forEach(set, iterator, optionalContext, finishedCallback) <a name="after.forEach" href="#after.forEach"><small><sup>link</sup></small></a>
+
+ var set = {
+ google: googleUser,
+ github: githubUser,
+ facebook: facebookUser
+ };
+
+ after.forEach(set, synchronizeOAuth, finished)
+
+ function synchronizeOAuth(userObject, oAuthName, _, callback) {
+ getOAuth(key).sychrnonize(userObject, callback);
+ }
+
+ function finished(err) {
+ if (err) throw err;
+ }
+
+## Installation
+
+`npm install after`
+
+## Tests
+
+`node test/main-test.js`
+
+## Blog post
+
+[Flow control in node.js][3]
+
+## Examples :
+
+ - [Determining the end of asynchronous operations][4]
+ - [In javascript what are best practices for executing multiple asynchronous functions][5]
+ - [JavaScript performance long running tasks][6]
+ - [Synchronous database queries with node.js][7]
+
+## Contributors
+
+ - Raynos
+
+## MIT Licenced
+
+ [1]: https://secure.travis-ci.org/Raynos/after.js.png
+ [2]: http://travis-ci.org/Raynos/after.js
+ [3]: http://raynos.org/blog/2/Flow-control-in-node.js
+ [4]: http://stackoverflow.com/questions/6852059/determining-the-end-of-asynchronous-operations-javascript/6852307#6852307
+ [5]: http://stackoverflow.com/questions/6869872/in-javascript-what-are-best-practices-for-executing-multiple-asynchronous-functi/6870031#6870031
+ [6]: http://stackoverflow.com/questions/6864397/javascript-performance-long-running-tasks/6889419#6889419
+ [7]: http://stackoverflow.com/questions/6597493/synchronous-database-queries-with-node-js/6620091#6620091
19 node_modules/after/package.json
View
@@ -0,0 +1,19 @@
+{
+ "name": "after",
+ "description": "after - tiny flow control",
+ "version": "0.2.0",
+ "author": "Raynos <raynos2@gmail.com>",
+ "contributors": [
+ { "name": "Raynos", "email": "raynos2@gmail.com", "url":"http://raynos.org" }
+ ],
+ "scripts": {
+ "test": "node test/main-test.js"
+ },
+ "devDependencies": {
+ "tester": "0.0.4"
+ },
+ "keywords": ["flowcontrol", "after", "flow", "control", "arch"],
+ "repository": "git://github.com/Raynos/after.js.git",
+ "main": "src/after",
+ "engines": { "node": "0.6 || 0.4" }
+}
63 node_modules/after/src/after.js
View
@@ -0,0 +1,63 @@
+(function _anonymousWrapper(global) {
+ "use strict";
+
+ var slice = [].slice;
+
+ after.forEach = forEach;
+ after.each = forEach;
+
+ if (typeof module !== "undefined" && module.exports) {
+ module.exports = after;
+ } else {
+ global.after = after;
+ }
+
+ function after(count, callback) {
+ var counter = 0,
+ results = [];
+
+ if (count <= 0) {
+ return callback();
+ }
+
+ return afterProxy;
+
+ function afterProxy(arg) {
+ if (arguments.length === 1) {
+ results.push(arg);
+ } else if (arguments.length > 1) {
+ results.push(slice.call(arguments));
+ }
+
+ counter++;
+
+ if (counter >= count) {
+ callback.apply(this, results);
+ }
+ }
+ }
+
+ function forEach(set, iterator, context, callback) {
+ if (typeof context === "function") {
+ callback = context;
+ context = undefined;
+ }
+ var keys = Object.keys(set),
+ next = after(keys.length, callCallback);
+
+ keys.forEach(proxyIterator);
+
+ function proxyIterator(keyName) {
+ iterator.call(context, set[keyName], keyName, proxyCallback);
+ }
+
+ function proxyCallback(err) {
+ err ? next(err) : next();
+ }
+
+ function callCallback(err) {
+ err ? callback(err) : callback(null);
+ }
+ }
+
+}(global || window));
155 node_modules/after/test/main-test.js
View
@@ -0,0 +1,155 @@
+var tester = require("tester"),
+ assert = require('assert'),
+ after = require('../src/after.js');
+
+module.exports = {
+ "after": function () {
+ assert(after.length === 2);
+ assert(typeof after === "function");
+ },
+ "after no arguments": function () {
+ after(1, testItIsInvoked)();
+
+ function testItIsInvoked() {
+ assert(arguments.length === 0);
+ }
+ },
+ "after one argument": function () {
+ ["string", null, undefined, /foo/, [], {}, 1].forEach(runTest);
+
+ function runTest(val) {
+ after(1, testValueIsReturned)(val);
+
+ function testValueIsReturned(value) {
+ assert(val === value);
+ }
+ }
+ },
+ "after multiple arguments": function () {
+ var arr = ["lol", "foo", "baz"];
+ after(1, testMultipleValues).apply(null, arr);
+
+ function testMultipleValues(array) {
+ array.forEach(testValueIsAsExpected);
+
+ function testValueIsAsExpected(key) {
+ assert(array[key] === arr[key]);
+ }
+ }
+ },
+ "after multiple calls": function () {
+ var fs = [];
+ for (var i = 1; i < 100; i++) {
+ constructData(i);
+ }
+ fs.forEach(callFunctionNTimes);
+
+ function callFunctionNTimes(v, k) {
+ for (var i = 0; i < k; i++) {
+ v(i);
+ }
+ }
+
+ function constructData(i) {
+ fs[i] = after(i, testReturnedData);
+
+ function testReturnedData() {
+ assert(arguments.length === i);
+ for (var j = 0; j < i; j++) {
+ assert(j === arguments[j]);
+ }
+ }
+ }
+ },
+ "after(0, f)": function () {
+ var bool = true;
+ after(0, testItFiresImmediatly);
+ bool = false;
+
+ function testItFiresImmediatly() {
+ assert(bool);
+ }
+ },
+ "after (1, f)": function () {
+ var next = after(1, setFiredFlag);
+ assert(!next.fired);
+ next();
+ assert(next.fired);
+
+ function setFiredFlag() {
+ next.fired = true;
+ }
+ },
+ "after (n, f)": function () {
+ var arr = [];
+ for (var i = 1; i < 100; i++) {
+ arr[i] = after(i, setFiredFlag);
+ }
+ arr.forEach(testItFiresAtCorrectPoint);
+
+ function testItFiresAtCorrectPoint(k, v) {
+ for (var i = 1; i < k; i++) {
+ v();
+ if (i === k - 1) {
+ assert(v.fired);
+ } else {
+ assert(!v.fired)
+ }
+ }
+ }
+
+ function setFiredFlag() {
+ arr[i].fired = true;
+ }
+ },
+ "after async": function (done) {
+ var bool = false;
+ done(checkBoolIsSet);
+ var next = after(1, setBool);
+ setTimeout(next, 100);
+
+ function checkBoolIsSet() {
+ assert(bool);
+ }
+
+ function setBool() {
+ bool = true;
+ done();
+ }
+ },
+ "forEach": function () {
+ assert(after.forEach);
+ assert(after.each);
+
+ var arr = [1,2,3,4],
+ obj = {
+ "foo": "bar",
+ "baz": "boz"
+ },
+ context = {};
+
+ after.forEach(arr, arrayIterator, finished);
+
+ after.forEach(obj, objIterator, context, finished);
+
+ function arrayIterator(value, index, callback) {
+ assert(arr[index] === value);
+ assert(typeof callback === "function");
+ callback();
+ }
+
+ function objIterator(value, index, callback) {
+ assert(obj[index] === value);
+ assert(this === context);
+ callback();
+ }
+
+ function finished(err) {
+ assert(err === null);
+ }
+ }
+}
+
+if (!module.parent) {
+ tester(module.exports);
+}
13 node_modules/eventemitter2/.gitignore
View
@@ -0,0 +1,13 @@
+#ignore these files
+*.swp
+*~
+*.lock
+*.DS_Store
+node_modules
+npm-debug.log
+*.out
+*.o
+*.tmp
+
+
+
226 node_modules/eventemitter2/README.md
View
@@ -0,0 +1,226 @@
+
+# EventEmitter2
+
+EventEmitter2 is a an implementation of the EventEmitter found in Node.js
+
+# ATTENTION! BREAKING CHANGES TO BE COMPATIBLE WITH NODE.JS EVENT EMITTER.
+
+Wrong
+
+```javascript
+ server.on('foo.*', function(event, value1, value2) { // DOES NOT PASS THE EVENT AS FIRST ARGUMENT.
+ console.log(event, value1, value2);
+ });
+```
+
+Right
+
+```javascript
+ server.on('foo.*', function(value1, value2) {
+ console.log(this.event, value1, value2);
+ });
+```
+
+## Features
+
+ - 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.
+
+## Differences (Non breaking, compatible with existing EventEmitter)
+
+ - The constructor takes a configuration object.
+
+```javascript
+ var server = EventEmitter2({
+ 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.
+ });
+```
+
+ - Getting the actual event that fired.
+
+```javascript
+ server.on('foo.*', function(value1, value2) {
+ console.log(this.event, value1, value2);
+ });
+```
+
+ - Fire an event N times and then remove it, an extension of the `once` concept.
+
+```javascript
+ server.many('foo', 4, function() {
+ console.log('hello');
+ });
+```
+
+ - Pass in a namespaced event as an array rather than a delimited string.
+
+```javascript
+ server.many(['foo', 'bar', 'bazz'], function() {
+ console.log('hello');
+ });
+```
+
+
+## API
+
+When an `EventEmitter` instance experiences an error, the typical action is
+to emit an `error` event. Error events are treated as a special case.
+If there is no listener for it, then the default action is to print a stack
+trace and exit the program.
+
+All EventEmitters emit the event `newListener` when new listeners are
+added.
+
+
+**Namespaces** with **Wildcards**
+To use namespaces/wildcards, pass the `wildcard` option into the EventEmitter constructor.
+When namespaces/wildcards are enabled, events can either be strings (`foo.bar`) separated
+by a delimiter or arrays (`['foo', 'bar']`). The delimiter is also configurable as a
+constructor option.
+
+An event name passed to any event emitter method can contain a wild card (the `*` character).
+If the event name is a string, a wildcard may appear as `foo.*`. If the event name is an array,
+the wildcard may appear as `['foo', '*']`.
+
+If either of the above described events were passed to the `on` method, subsequent emits such
+as the following would be observed...
+
+```javascript
+ emitter.emit(['foo.bazz']);
+ emitter.emit(['foo', 'bar']);
+```
+
+
+#### emitter.addListener(event, listener)
+#### emitter.on(event, listener)
+
+Adds a listener to the end of the listeners array for the specified event.
+
+```javascript
+ server.on('data', function(value1, value2, value3 /* accepts any number of expected values... */) {
+ console.log('The event was raised!');
+ });
+```
+
+```javascript
+ server.on('data', function(value) {
+ console.log('This event will be listened to exactly four times.');
+ });
+```
+
+#### emitter.onAny(listener)
+
+Adds a listener that will be fired when any event is emitted.
+
+```javascript
+ server.onAny(function(value) {
+ console.log('This event will be listened to exactly four times.');
+ });
+```
+
+#### emitter.offAny(listener)
+
+Removes the listener that will be fired when any event is emitted.
+
+```javascript
+ server.offAny(function(value) {
+ console.log('This event will be listened to exactly four times.');
+ });
+```
+
+#### emitter.once(event, listener)
+
+Adds a **one time** listener for the event. The listener is invoked only the first time the event is fired, after which it is removed.
+
+```javascript
+ server.once('get', function (value) {
+ console.log('Ah, we have our first value!');
+ });
+```
+
+#### emitter.many(event, timesToListen, listener)
+
+Adds a listener that will execute **n times** for the event before being removed. The listener is invoked only the first time the event is fired, after which it is removed.
+
+```javascript
+ server.many('get', 4, function (value) {
+ console.log('Ah, we have our first value!');
+ });
+```
+
+
+#### emitter.removeListener(event, listener)
+#### emitter.off(event, listener)
+
+Remove a listener from the listener array for the specified event. **Caution**: changes array indices in the listener array behind the listener.
+
+```javascript
+ var callback = function(value) {
+ console.log('someone connected!');
+ };
+ server.on('get', callback);
+ // ...
+ server.removeListener('get', callback);
+```
+
+
+#### emitter.removeAllListeners([event])
+
+Removes all listeners, or those of the specified event.
+
+
+#### emitter.setMaxListeners(n)
+
+By default EventEmitters will print a warning if more than 10 listeners are added to it. This is a useful default which helps finding memory leaks. Obviously not all Emitters should be limited to 10. This function allows that to be increased. Set to zero for unlimited.
+
+
+#### emitter.listeners(event)
+
+Returns an array of listeners for the specified event. This array can be manipulated, e.g. to remove listeners.
+
+```javascript
+ server.on('get', function(value) {
+ console.log('someone connected!');
+ });
+ console.log(console.log(server.listeners('get')); // [ [Function] ]
+```
+
+#### emitter.listenersAny(event)
+
+Returns an array of listeners that are listening for any event that is specified. This array can be manipulated, e.g. to remove listeners.
+
+```javascript
+ server.onAny(function(value) {
+ console.log('someone connected!');
+ });
+ console.log(console.log(server.listenersAny()[0]); // [ [Function] ] // someone connected!
+```
+
+#### emitter.emit(event, [arg1], [arg2], [...])
+
+Execute each of the listeners that may be listening for the specified event name in order with the list of arguments.
+
+#### emitter.emitAll(event, [arg1], [arg2], [...])
+
+Execute each of the listeners that may be listening for the specified event name in order with the list of arguments.
+
+
+## Test coverage
+
+There is a test suite that tries to cover each use case, it can be found <a href="https://github.com/hij1nx/EventEmitter2/tree/master/test">here</a>.
+
+## Licence
+
+(The MIT License)
+
+Copyright (c) 2011 hij1nx <http://www.twitter.com/hij1nx>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1  node_modules/eventemitter2/index.js
View
@@ -0,0 +1 @@
+module.exports = require('./lib/eventemitter2');
453 node_modules/eventemitter2/lib/eventemitter2.js
View
@@ -0,0 +1,453 @@
+
+;!function(exports, undefined) {
+
+ var isArray = Array.isArray;
+ var defaultMaxListeners = 10;
+
+ function init() {
+ this._events = new Object;
+ }
+
+ function configure(conf) {
+
+ if (conf) {
+ this.wildcard = conf.wildcard;
+ this.delimiter = conf.delimiter || '.';
+
+ if (this.wildcard) {
+ this.listenerTree = new Object;
+ }
+ }
+ }
+
+ function EventEmitter(conf) {
+ this._events = new Object;
+ configure.call(this, conf);
+ }
+
+ function searchListenerTree(handlers, type, tree, i) {
+ if (!tree) {
+ return;
+ }
+
+ var listeners;
+
+ if (i === type.length && tree._listeners) {
+ //
+ // If at the end of the event(s) list and the tree has listeners
+ // invoke those listeners.
+ //
+ if (typeof tree._listeners === 'function') {
+ handlers && handlers.push(tree._listeners);
+ return tree;
+ } else {
+ for (var leaf = 0, len = tree._listeners.length; leaf < len; leaf++) {
+ handlers && handlers.push(tree._listeners[leaf]);
+ }
+ return tree;
+ }
+ }
+
+ if (type[i] === '*' || tree[type[i]]) {
+ //
+ // If the event emitted is '*' at this part
+ // or there is a concrete match at this patch
+ //
+ if (type[i] === '*') {
+ for (var branch in tree) {
+ if (branch !== '_listeners' && tree.hasOwnProperty(branch)) {
+ listeners = searchListenerTree(handlers, type, tree[branch], i+1);
+ }
+ }
+ return listeners;
+ }
+
+ listeners = searchListenerTree(handlers, type, tree[type[i]], i+1);
+ }
+
+
+ if (tree['*']) {
+ //
+ // If the listener tree will allow any match for this part,
+ // then recursively explore all branches of the tree
+ //
+ searchListenerTree(handlers, type, tree['*'], i+1);
+ }
+
+ return listeners;
+ };
+
+ function growListenerTree(type, listener) {
+
+ type = typeof type === 'string' ? type.split(this.delimiter) : type.slice();
+
+ var tree = this.listenerTree;
+ var name = type.shift();
+
+ while (name) {
+
+ if (!tree[name]) {
+ tree[name] = new Object;
+ }
+
+ tree = tree[name];
+
+ if (type.length === 0) {
+
+ if (!tree._listeners) {
+ tree._listeners = listener;
+ }
+ else if(typeof tree._listeners === 'function') {
+ tree._listeners = [tree._listeners, listener];
+ }
+ else if (isArray(tree._listeners)) {
+
+ tree._listeners.push(listener);
+
+ if (!tree._listeners.warned) {
+
+ var m = defaultMaxListeners;
+
+ if (m > 0 && tree._listeners.length > m) {
+
+ tree._listeners.warned = true;
+ console.error('(node) warning: possible EventEmitter memory ' +
+ 'leak detected. %d listeners added. ' +
+ 'Use emitter.setMaxListeners() to increase limit.',
+ tree._listeners.length);
+ console.trace();
+ }
+ }
+ }
+ return true;
+ }
+ name = type.shift();
+ }
+ return true;
+ };
+
+ // By default EventEmitters will print a warning if more than
+ // 10 listeners are added to it. This is a useful default which
+ // helps finding memory leaks.
+ //
+ // Obviously not all Emitters should be limited to 10. This function allows
+ // that to be increased. Set to zero for unlimited.
+
+ EventEmitter.prototype.setMaxListeners = function(n) {
+ this._events || init.call(this);
+ this._events.maxListeners = n;
+ };
+
+ EventEmitter.prototype.event = '';
+
+ EventEmitter.prototype.once = function(event, fn) {
+ this.many(event, 1, fn);
+ return this;
+ };
+
+ EventEmitter.prototype.many = function(event, ttl, fn) {
+ var self = this;
+
+ if (typeof fn !== 'function') {
+ throw new Error('many only accepts instances of Function');
+ }
+
+ function listener() {
+ if (--ttl === 0) {
+ self.off(event, listener);
+ }
+ fn.apply(null, arguments);
+ };
+
+ listener._origin = fn;
+
+ this.on(event, listener);
+
+ return self;
+ };
+
+ EventEmitter.prototype.emit = function() {
+ this._events || init.call(this);
+
+ var type = arguments[0];
+
+ if (type === 'newListener') {
+ if (!this._events.newListener) { return false; }
+ }
+
+ // Loop through the *_all* functions and invoke them.
+ if (this._all) {
+ var l = arguments.length;
+ var args = new Array(l - 1);
+ for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
+ for (i = 0, l = this._all.length; i < l; i++) {
+ this.event = type;
+ this._all[i].apply(this, args);
+ }
+ }
+
+ // If there is no 'error' event listener then throw.
+ if (type === 'error') {
+
+ if (!this._all &&
+ !this._events.error &&
+ !(this.wildcard && this.listenerTree.error)) {
+
+ if (arguments[1] instanceof Error) {
+ throw arguments[1]; // Unhandled 'error' event
+ } else {
+ throw new Error("Uncaught, unspecified 'error' event.");
+ }
+ return false;
+ }
+ }
+
+ var handler;
+
+ if(this.wildcard) {
+ handler = [];
+ var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice();
+ searchListenerTree.call(this, handler, ns, this.listenerTree, 0);
+ }
+ else {
+ handler = this._events[type];
+ }
+
+ if (typeof handler === 'function') {
+ this.event = type;
+ if (arguments.length === 1) {
+ handler.call(this);
+ }
+ else if (arguments.length > 1)
+ switch (arguments.length) {
+ case 2:
+ handler.call(this, arguments[1]);
+ break;
+ case 3:
+ handler.call(this, arguments[1], arguments[2]);
+ break;
+ // slower
+ default:
+ var l = arguments.length;
+ var args = new Array(l - 1);
+ for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
+ handler.apply(this, args);
+ }
+ return true;
+ }
+ else if (handler) {
+ var l = arguments.length;
+ var args = new Array(l - 1);
+ for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
+
+ var listeners = handler.slice();
+ for (var i = 0, l = listeners.length; i < l; i++) {
+ this.event = type;
+ listeners[i].apply(this, args);
+ }
+ return true;
+ }
+
+ };
+
+ EventEmitter.prototype.on = function(type, listener) {
+ this._events || init.call(this);
+
+ // To avoid recursion in the case that type == "newListeners"! Before
+ // adding it to the listeners, first emit "newListeners".
+ this.emit('newListener', type, listener);
+
+ if(this.wildcard) {
+ growListenerTree.call(this, type, listener);
+ return this;
+ }
+
+ if (!this._events[type]) {
+ // Optimize the case of one listener. Don't need the extra array object.
+ this._events[type] = listener;
+ }
+ else if(typeof this._events[type] === 'function') {
+ // Adding the second element, need to change to array.
+ this._events[type] = [this._events[type], listener];
+ }
+ else if (isArray(this._events[type])) {
+ // If we've already got an array, just append.
+ this._events[type].push(listener);
+
+ // Check for listener leak
+ if (!this._events[type].warned) {
+
+ var m;
+ if (this._events.maxListeners !== undefined) {
+ m = this._events.maxListeners;
+ } else {
+ m = defaultMaxListeners;
+ }
+
+ if (m && m > 0 && this._events[type].length > m) {
+
+ this._events[type].warned = true;
+ console.error('(node) warning: possible EventEmitter memory ' +
+ 'leak detected. %d listeners added. ' +
+ 'Use emitter.setMaxListeners() to increase limit.',
+ this._events[type].length);
+ console.trace();
+ }
+ }
+ }
+ return this;
+ };
+
+ EventEmitter.prototype.onAny = function(fn) {
+
+ if(!this._all) {
+ this._all = [];
+ }
+
+ if (typeof fn !== 'function') {
+ throw new Error('onAny only accepts instances of Function');
+ }
+
+ // Add the function to the event listener collection.
+ this._all.push(fn);
+ return this;
+ };
+
+ EventEmitter.prototype.addListener = EventEmitter.prototype.on;
+
+ EventEmitter.prototype.off = function(type, listener) {
+ if (typeof listener !== 'function') {
+ throw new Error('removeListener only takes instances of Function');
+ }
+
+ var handlers;
+
+ if(this.wildcard) {
+ var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice();
+ var leaf = searchListenerTree.call(this, null, ns, this.listenerTree, 0);
+
+ if('undefined' === typeof leaf) { return this; }
+ handlers = leaf._listeners;
+ }
+ else {
+ // does not use listeners(), so no side effect of creating _events[type]
+ if (!this._events[type]) return this;
+ handlers = this._events[type];
+ }
+
+ if (isArray(handlers)) {
+
+ var position = -1;
+
+ for (var i = 0, length = handlers.length; i < length; i++) {
+ if (handlers[i] === listener ||
+ (handlers[i].listener && handlers[i].listener === listener) ||
+ (handlers[i]._origin && handlers[i]._origin === listener)) {
+ position = i;
+ break;
+ }
+ }
+
+ if (position < 0) {
+ return this;
+ }
+
+ if(this.wildcard) {
+ leaf._listeners.splice(position, 1)
+ }
+ else {
+ this._events[type].splice(position, 1);
+ }
+
+ if (handlers.length === 0) {
+ if(this.wildcard) {
+ delete leaf._listeners;
+ }
+ else {
+ delete this._events[type];
+ }
+ }
+ }
+ else if (handlers === listener ||
+ (handlers.listener && handlers.listener === listener) ||
+ (handlers._origin && handlers._origin === listener)) {
+ if(this.wildcard) {
+ delete leaf._listeners;
+ }
+ else {
+ delete this._events[type];
+ }
+ }
+
+ return this;
+ };
+
+ EventEmitter.prototype.offAny = function(fn) {
+ var i = 0, l = 0, fns;
+ if (fn && this._all && this._all.length > 0) {
+ fns = this._all;
+ for(i = 0, l = fns.length; i < l; i++) {
+ if(fn === fns[i]) {
+ fns.splice(i, 1);
+ return this;
+ }
+ }
+ } else {
+ this._all = [];
+ }
+ return this;
+ };
+
+ EventEmitter.prototype.removeListener = EventEmitter.prototype.off;
+
+ EventEmitter.prototype.removeAllListeners = function(type) {
+ if (arguments.length === 0) {
+ !this._events || init.call(this);
+ return this;
+ }
+
+ if(this.wildcard) {
+ var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice();
+ var leaf = searchListenerTree.call(this, null, ns, this.listenerTree, 0);
+
+ if('undefined' === typeof leaf) { return this; }
+ leaf._listeners = null;
+ }
+ else {
+ if (!this._events[type]) return this;
+ this._events[type] = null;
+ }
+ return this;
+ };
+
+ EventEmitter.prototype.listeners = function(type) {
+ if(this.wildcard) {
+ var handlers = [];
+ var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice();
+ searchListenerTree.call(this, handlers, ns, this.listenerTree, 0);
+ return handlers;
+ }
+
+ this._events || init.call(this);
+
+ if (!this._events[type]) this._events[type] = [];
+ if (!isArray(this._events[type])) {
+ this._events[type] = [this._events[type]];
+ }
+ return this._events[type];
+ };
+
+ EventEmitter.prototype.listenersAny = function() {
+
+ if(this._all) {
+ return this._all;
+ }
+ else {
+ return [];
+ }
+
+ };
+
+ exports.EventEmitter2 = EventEmitter;
+
+}(typeof exports === 'undefined' ? window : exports);
32 node_modules/eventemitter2/package.json
View
@@ -0,0 +1,32 @@
+{
+ "name": "eventemitter2",
+ "version": "0.4.1",
+ "description": "A Node.js event emitter implementation with namespaces, wildcards, TTL and browser support.",
+ "keywords": ["event", "events", "emitter", "eventemitter"],
+ "author": "hij1nx <hij1nx@nodejitsu.com> http://twitter.com/hij1nx",
+ "maintainers": [
+ "hij1nx <hij1nx@nodejitsu.com>",
+ "jameson <jameson@nodejitsu.com>"
+ ],
+ "contributers": [
+ "Charlie Robbins <charlie@nodejitsu.com> http://twitter.com/indexzero",
+ "Jameson Lee <jameson@nodejitsu.com> http://twitter.com/Jamesonjlee",
+ "Jeroen van Duffelen <jvduf@nodejitsu.com> http://www.twitter.com/jvduf",
+ "Fedor Indutny <fedor.indutny@gmail.com> http://www.twitter.com/indutny"
+ ],
+ "licenses": [{"type": "MIT"}],
+ "repositories": [{
+ "type": "git",
+ "url": "git://github.com/hij1nx/EventEmitter2.git"
+ }],
+ "devDependencies": {
+ "nodeunit": "*",
+ "benchmark" : ">= 0.2.2"
+ },
+ "engines": ["node"],
+ "main": "./lib/eventemitter2.js",
+ "scripts" : {
+ "test" : "nodeunit test/simple/* && nodeunit test/wildcardEvents/*",
+ "benchmark" : "node test/perf/benchmark.js"
+ }
+}
110 node_modules/eventemitter2/test/common.js
View
@@ -0,0 +1,110 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var path = require('path');
+var assert = require('assert');
+
+exports.testDir = path.dirname(__filename);
+exports.fixturesDir = path.join(exports.testDir, 'fixtures');
+exports.libDir = path.join(exports.testDir, '../lib');
+exports.tmpDir = path.join(exports.testDir, 'tmp');
+exports.PORT = 12346;
+
+if (process.platform == 'win32') {
+ exports.PIPE = '\\\\.\\pipe\\libuv-test';
+} else {
+ exports.PIPE = exports.tmpDir + '/test.sock';
+}
+
+var util = require('util');
+for (var i in util) exports[i] = util[i];
+//for (var i in exports) global[i] = exports[i];
+
+function protoCtrChain(o) {
+ var result = [];
+ for (; o; o = o.__proto__) { result.push(o.constructor); }
+ return result.join();
+}
+
+exports.indirectInstanceOf = function(obj, cls) {
+ if (obj instanceof cls) { return true; }
+ var clsChain = protoCtrChain(cls.prototype);
+ var objChain = protoCtrChain(obj);
+ return objChain.slice(-clsChain.length) === clsChain;
+};
+
+
+// Turn this off if the test should not check for global leaks.
+exports.globalCheck = true;
+
+process.on('exit', function() {
+ if (!exports.globalCheck) return;
+ var knownGlobals = [setTimeout,
+ setInterval,
+ clearTimeout,
+ clearInterval,
+ console,
+ Buffer,
+ process,
+ global];
+
+ if (global.errno) {
+ knownGlobals.push(errno);
+ }
+
+ if (global.gc) {
+ knownGlobals.push(gc);
+ }
+
+ if (global.DTRACE_HTTP_SERVER_RESPONSE) {
+ knownGlobals.push(DTRACE_HTTP_SERVER_RESPONSE);
+ knownGlobals.push(DTRACE_HTTP_SERVER_REQUEST);
+ knownGlobals.push(DTRACE_HTTP_CLIENT_RESPONSE);
+ knownGlobals.push(DTRACE_HTTP_CLIENT_REQUEST);
+ knownGlobals.push(DTRACE_NET_STREAM_END);
+ knownGlobals.push(DTRACE_NET_SERVER_CONNECTION);
+ knownGlobals.push(DTRACE_NET_SOCKET_READ);
+ knownGlobals.push(DTRACE_NET_SOCKET_WRITE);
+ }
+
+ for (var x in global) {
+ var found = false;
+
+ for (var y in knownGlobals) {
+ if (global[x] === knownGlobals[y]) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ console.error('Unknown global: %s', x);
+ assert.ok(false, 'Unknown global founded');
+ }
+ }
+});
+
+
+// This function allows one two run an HTTP test agaist both HTTPS and
+// normal HTTP modules. This ensures they fit the same API.
+exports.httpTest = function httpTest(cb) {
+};
+
53 node_modules/eventemitter2/test/perf/benchmark.js
View
@@ -0,0 +1,53 @@
+
+var Benchmark = require('benchmark');
+var suite = new Benchmark.Suite();
+
+var EventEmitter = require('events').EventEmitter;
+var emitter = new EventEmitter;
+
+var EventEmitter2 = require('../../lib/eventemitter2').EventEmitter2;
+var emitter2 = new EventEmitter2;
+
+var EventEmitter3 = require('events').EventEmitter;
+var emitter3 = new EventEmitter3;
+
+suite
+
+ .add('EventEmitterHeatUp', function() {
+
+ emitter3.on('test3', function () { 1==1; });
+ emitter3.emit('test3');
+ emitter3.removeAllListeners('test3');
+
+ })
+ .add('EventEmitter', function() {
+
+ emitter.on('test1', function () { 1==1; });
+ emitter.emit('test1');
+ emitter.removeAllListeners('test1');
+
+ })
+ .add('EventEmitter2', function() {
+
+ emitter2.on('test2', function () { 1==1; });
+ emitter2.emit('test2');
+ emitter2.removeAllListeners('test2');
+
+ })
+
+ .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(true);
173 node_modules/eventemitter2/test/simple/addListener.js
View
@@ -0,0 +1,173 @@
+var simpleEvents = require('nodeunit').testCase;
+
+var file = '../../lib/eventemitter2';
+
+module.exports = simpleEvents({
+
+ setUp: function (callback) {
+ var EventEmitter2;
+
+ if(typeof require !== 'undefined') {
+ EventEmitter2 = require(file).EventEmitter2;
+ }
+ else {
+ EventEmitter2 = window.EventEmitter2;
+ }
+
+ this.emitter = new EventEmitter2({ verbose: true });
+ callback();
+ },
+
+ tearDown: function (callback) {
+ //clean up?
+ callback();
+ },
+
+ '1. Add a single listener on a single event.': function (test) {
+
+ var emitter = this.emitter;
+
+ emitter.on('test1', function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ test.equal(emitter.listeners('test1').length, 1, 'There are three emitters');
+
+ test.expect(1);
+ test.done();
+
+ },
+ '2. Add two listeners on a single event.': function (test) {
+
+ var emitter = this.emitter;
+
+ emitter.on('test1', function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ emitter.on('test1', function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ test.equal(emitter.listeners('test1').length, 2, 'There are three emitters');
+
+ test.expect(1);
+ test.done();
+
+ },
+ '3. Add three listeners on a single event.': function (test) {
+
+ var emitter = this.emitter;
+
+ emitter.on('test1', function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ emitter.on('test1', function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ emitter.on('test1', function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ test.equal(emitter.listeners('test1').length, 3, 'There are three emitters');
+
+ test.expect(1);
+ test.done();
+
+ },
+ '4. Add two listeners to two different events.': function (test) {
+
+ var emitter = this.emitter;
+
+ emitter.on('test1', function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ emitter.on('test1', function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ emitter.on('test2', function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ emitter.on('test2', function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ test.equal(emitter.listeners('test1').length, 2, 'There are two emitters');
+ test.equal(emitter.listeners('test2').length, 2, 'There are two emitters');
+
+ test.expect(2);
+ test.done();
+
+ },
+ '5. Never adding any listeners should yield a listeners array with the length of 0.': function (test) {
+
+ var emitter = this.emitter;
+
+ emitter.on('test1', function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ test.equal(emitter.listeners('test2').length, 0, 'There are no emitters');
+
+ test.expect(1);
+ test.done();
+ },
+
+ '6. the listener added should be the right listener.': function (test) {
+
+ var emitter = this.emitter;
+ var type = 'somelistenerbar';
+ var f = function () {};
+
+ emitter.on(type, f);
+ test.equal(emitter.listeners(type).length, 1, 'There are is one emitters');
+ test.equal(emitter.listeners(type)[0], f, 'The function should be f');
+
+ test.expect(2);
+ test.done();
+
+ },
+
+ '7. should be able to listen on any event' : function (test) {
+
+ var emitter = this.emitter;
+ var type = 'somelistenerbar';
+ var f = function () {
+ test.ok(true, 'the event was fired')
+ };
+
+ emitter.onAny(f);
+ emitter.emit('test23.ns5.ns5', 'someData'); //1
+ emitter.offAny(f);
+ emitter.emit('test21'); //0
+ emitter.onAny(f);
+ emitter.onAny(f);
+ emitter.emit('test23.ns5.ns5', 'someData'); //3
+
+ test.expect(3);
+ test.done();
+
+ },
+
+ '8. should be able to listen on any event (should cause an error)' : function (test) {
+
+ var emitter = this.emitter;
+ var type = 'somelistenerbar';
+ var f = function () {
+ test.ok(true, 'the event was fired')
+ };
+ emitter.onAny(f);
+
+ emitter.emit('error');
+
+ test.expect(1);
+ test.done();
+
+ }
+
+});
136 node_modules/eventemitter2/test/simple/emit.js
View
@@ -0,0 +1,136 @@
+var simpleEvents = require('nodeunit').testCase;
+
+var file = '../../lib/eventemitter2';
+
+module.exports = simpleEvents({
+
+ setUp: function (callback) {
+ var EventEmitter2;
+
+ if(typeof require !== 'undefined') {
+ EventEmitter2 = require(file).EventEmitter2;
+ }
+ else {
+ EventEmitter2 = window.EventEmitter2;
+ }
+
+ this.emitter = new EventEmitter2({ verbose: true });
+ callback();
+ },
+
+ tearDown: function (callback) {
+ //clean up?
+ callback();
+ },
+
+ '1. Add two listeners on a single event and emit the event.': function (test) {
+
+ var emitter = this.emitter;
+
+ function functionA() { test.ok(true, 'The event was raised'); }
+ function functionB() { test.ok(true, 'The event was raised'); }
+
+ emitter.on('test2', functionA);
+ emitter.on('test2', functionB);
+
+ emitter.emit('test2');
+
+ test.expect(2);
+ test.done();
+
+ },
+ '2. Add two listeners on a single event and emit the event twice.': function (test) {
+
+ var emitter = this.emitter;
+
+ function functionA() { test.ok(true, 'The event was raised'); }
+ function functionB() { test.ok(true, 'The event was raised'); }
+
+ emitter.on('test2', functionA);
+ emitter.on('test2', functionB);
+
+ emitter.emit('test2');
+ emitter.emit('test2');
+
+ test.expect(4);
+ test.done();
+
+ },
+ '3. Add two listeners on a single event and emit the event with a parameter.': function (test) {
+
+ var emitter = this.emitter;
+
+ function functionA(value1) {
+ test.ok(true, 'The event was raised');
+ test.equal(typeof value1, 'string', 'The event was raised');
+ }
+
+ function functionB(value1) {
+ test.ok(true, 'The event was raised');
+ test.equal(typeof value1, 'string', 'The event was raised');
+ }
+
+ emitter.on('test2', functionA);
+ emitter.on('test2', functionB);
+
+ emitter.emit('test2', 'Hello, Node');
+
+ test.expect(4);
+ test.done();
+
+ },
+ '4. Add two listeners on an single event and emit the event twice with a parameter.': function (test) {
+
+ var emitter = this.emitter;
+
+ function functionA(value1) {
+ test.ok(true, 'The event was raised');
+ test.equal(typeof value1, 'string', 'The event was raised');
+ }
+
+ function functionB(value1) {
+ test.ok(true, 'The event was raised');
+ test.equal(typeof value1, 'string', 'The event was raised');
+ }
+
+ emitter.on('test2', functionA);
+ emitter.on('test2', functionB);
+
+ emitter.emit('test2', 'Hello, Node1');
+ emitter.emit('test2', 'Hello, Node2');
+
+ test.expect(8);
+ test.done();
+
+ },
+ '5. Add two listeners on an single event and emit the event twice with multiple parameters.': function (test) {
+
+ var emitter = this.emitter;
+
+ function functionA(value1, value2, value3) {
+ test.ok(true, 'The event was raised');
+ test.equal(typeof value1, 'string', 'The value named "value1" is OK');
+ test.equal(typeof value2, 'string', 'The value named "value2" is OK');
+ test.equal(typeof value3, 'string', 'The value named "value3" is OK');
+ }
+
+ function functionB(value1, value2, value3) {
+ test.ok(true, 'The event was raised');
+ test.equal(typeof value1, 'string', 'The value named "value1" is OK');
+ test.equal(typeof value2, 'string', 'The value named "value2" is OK');
+ test.equal(typeof value3, 'string', 'The value named "value3" is OK');
+ }
+
+ emitter.on('test2', functionA);
+ emitter.on('test2', functionB);
+
+ emitter.emit('test2', 'Hello, Node1', 'Hello, Node2', 'Hello, Node3');
+ emitter.emit('test2', 'Hello, Node1', 'Hello, Node2', 'Hello, Node3');
+
+ test.expect(16);
+ test.done();
+
+ }
+
+});
+
199 node_modules/eventemitter2/test/simple/removeListener.js
View
@@ -0,0 +1,199 @@
+var simpleEvents= require('nodeunit').testCase;
+
+var file = '../../lib/eventemitter2';
+
+module.exports = simpleEvents({
+
+ setUp: function (callback) {
+ var EventEmitter2;
+
+ if(typeof require !== 'undefined') {
+ EventEmitter2 = require(file).EventEmitter2;
+ }
+ else {
+ EventEmitter2 = window.EventEmitter2;
+ }
+
+ this.emitter = new EventEmitter2;
+ callback();
+ },
+
+ tearDown: function (callback) {
+ //clean up?
+ callback();
+ },
+
+ 'removeListener1. adding 1, removing 1' : function (test) {
+ var emitter = this.emitter,
+ type = 'remove',
+ listeners;
+
+ var f = function f() {
+ test.ok(true, 'event was raised');
+ };
+
+ emitter.on(type, f);
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 1, 'should only have 1');
+
+ //remove
+ emitter.removeListener(type, f);
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 0, 'should be 0');
+
+ test.expect(2);
+ test.done();
+ },
+
+ 'removeListener2. adding 2, removing 1' : function (test) {
+ var emitter = this.emitter,
+ type = 'remove',
+ listeners;
+
+ var f = function f() {
+ test.ok(true, 'event was raised');
+ };
+
+ emitter.on(type, f);
+ emitter.on(type, f);
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 2, 'should only have 2');
+
+ //remove
+ emitter.removeListener(type, f);
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 1, 'should be 1');
+
+ test.expect(2);
+ test.done();
+ },
+
+ 'removeListener3. adding 3, removing 1' : function (test) {
+ var emitter = this.emitter,
+ type = 'remove',
+ listeners;
+
+ var f = function f() {
+ test.ok(true, 'event was raised');
+ };
+
+ emitter.on(type, f);
+ emitter.on(type, f);
+ emitter.on(type, f);
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 3, 'should only have 3');
+
+ //remove
+ emitter.removeListener(type, f);
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 2, 'should be 2');
+
+ test.expect(2);
+ test.done();
+ },
+
+ 'removeListener4. should error if we don\'t pass in a function' : function (test) {
+ var emitter = this.emitter,
+ type = 'remove',
+ listeners;
+
+ var f = function f() {
+ test.ok(true, 'event was raised');
+ };
+
+ emitter.on(type, f);
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 1, 'should only have 1');
+
+ //remove
+ test.throws(function () {emitter.removeListener(type, type)}, Error, 'should throw an Error');
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 1, 'should be 1');
+
+ test.expect(3);
+ test.done();
+ },
+
+ 'removeListener5. removing a different function, should not remove' : function (test) {
+ var emitter = this.emitter,
+ type = 'remove',
+ listeners;
+
+ var f = function f() {
+ test.ok(true, 'event was raised');
+ };
+ var g = function g() {
+ test.ok(true, 'event was raised');
+ };
+
+ emitter.on(type, f);
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 1, 'should only have 1');
+
+ //remove
+ emitter.removeListener(type, g);
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 1, 'should be 1');
+
+ test.expect(2);
+ test.done();
+ },
+
+ 'removeListener6. removing all functions' : function (test) {
+ var emitter = this.emitter,
+ type = 'remove',
+ listeners;
+
+ var f = function f() {
+ test.ok(true, 'event was raised');
+ };
+ for (var i = 0; i < 10; i++) {
+ emitter.on(type, f);
+ }
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 10, 'should only have 10');
+
+ emitter.removeListener(type, f);
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 9, 'should be 9');
+ emitter.removeAllListeners(type);
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 0, 'should be 0');
+
+ test.expect(3);
+ test.done();
+ },
+
+ 'removeListener7. removing different event, should not remove' : function (test) {
+ var emitter = this.emitter,
+ type = 'remove',
+ listeners;
+
+ var f = function f() {
+ test.ok(true, 'event was raised');
+ };
+
+ for (var i = 0; i < 10; i++) {
+ emitter.on(type, f);
+ }
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 10, 'should only have 10');
+
+ emitter.removeListener(type+type, f);
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 10, 'should be 10');
+
+ emitter.removeAllListeners(type+type);
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 10, 'should be 10');
+
+ emitter.removeAllListeners(type);
+ listeners = emitter.listeners(type);
+ test.equal(listeners.length, 0, 'should be 0');
+
+ test.expect(4);
+ test.done();
+ },
+
+
+});
133 node_modules/eventemitter2/test/simple/setMax.js
View
@@ -0,0 +1,133 @@
+var simpleEvents= require('nodeunit').testCase;
+
+var file = '../../lib/eventemitter2';
+
+module.exports = simpleEvents({
+
+ setUp: function (callback) {
+ var EventEmitter2;
+
+ if(typeof require !== 'undefined') {
+ EventEmitter2 = require(file).EventEmitter2;
+ }
+ else {
+ EventEmitter2 = window.EventEmitter2;
+ }
+
+ this.emitter = new EventEmitter2;
+ callback();
+ },
+
+ tearDown: function (callback) {
+ //clean up?
+ callback();
+ },
+
+ 'setMaxListener1. default behavior of 10 listeners.' : function (test) {
+ var emitter = this.emitter;
+
+ for (var i = 0; i < 10; i++) {
+ emitter.on('foobar', function () {
+ test.ok(true, 'event was raised');
+ });
+ }
+
+ var listeners = emitter.listeners('foobar');
+ test.equal(listeners.length, 10, 'should only have 10');
+
+ test.expect(1);
+ test.done();
+ },
+
+ 'setMaxListener2. If we added more than 10, should not see them' : function (test) {
+ var emitter = this.emitter;
+
+ for (var i = 0; i < 10 ; i++) {
+ emitter.on('foobar2', function () {
+ test.ok(true, 'event was raised');
+ });
+ }
+ console.log('should see EE2 complaining:');
+ emitter.on('foobar2', function () {
+ test.ok(true, 'event was raised');
+ });
+ console.log('move on');
+
+ var listeners = emitter.listeners('foobar2');
+ test.equal(listeners.length, 11, 'should have 11');
+ test.ok(emitter._events['foobar2'].warned, 'should have been warned');
+
+ test.expect(2);
+ test.done();
+ },
+
+ 'setMaxListener3. if we set maxListener to be greater before adding' : function (test) {
+ var emitter = this.emitter;
+ var type = 'foobar3';
+
+ // set to 20
+ emitter.setMaxListeners(20);
+
+ for (var i = 0; i < 15 ; i++) {
+ emitter.on(type, function () {
+ test.ok(true, 'event was raised');
+ });
+ }
+
+// require('eyes').inspect(emitter._events);
+
+ var listeners = emitter.listeners(type);
+ test.equal(listeners.length, 15, 'should have 15');
+ test.ok(!(emitter._events[type].warned), 'should not have been set');
+
+ test.expect(2);
+ test.done();
+ },
+
+ 'setMaxListener4. should be able to change it right at 10' : function (test) {
+ var emitter = this.emitter;
+ var type = 'foobar4';
+
+ for (var i = 0; i < 10 ; i++) {
+ emitter.on(type, function () {
+ test.ok(true, 'event was raised');
+ });
+ }
+
+ emitter.setMaxListeners(9001);
+ emitter.on(type, function () {
+ test.ok(true, 'event was raised');
+ });
+
+// require('eyes').inspect(emitter._events);
+
+ var listeners = emitter.listeners(type);
+ test.equal(listeners.length, 11, 'should have 11');
+ test.ok(!(emitter._events[type].warned), 'should not have been set');
+
+ test.expect(2);
+ test.done();
+ },
+
+ 'setMaxListener5. if we set maxListener to be 0 should add endlessly' : function (test) {
+ var emitter = this.emitter;
+ var type = 'foobar';
+
+ // set to 0
+ emitter.setMaxListeners(0);
+
+ for (var i = 0; i < 25 ; i++) {
+ emitter.on(type, function () {
+ test.ok(true, 'event was raised');
+ });
+ }
+
+ var listeners = emitter.listeners(type);
+ test.equal(listeners.length, 25, 'should have 25');
+ test.ok(!(emitter._events[type].warned), 'should not have been set');
+
+ test.expect(2);
+ test.done();
+ },
+
+});
126 node_modules/eventemitter2/test/simple/ttl.js
View
@@ -0,0 +1,126 @@
+var simpleEvents = require('nodeunit').testCase;
+
+var file = '../../lib/eventemitter2';
+
+module.exports = simpleEvents({
+
+ setUp: function (callback) {
+ var EventEmitter2;
+
+ if(typeof require !== 'undefined') {
+ EventEmitter2 = require(file).EventEmitter2;
+ }
+ else {
+ EventEmitter2 = window.EventEmitter2;
+ }
+
+ this.emitter = new EventEmitter2();
+ callback();
+ },
+
+ tearDown: function (callback) {
+ //clean up?
+ callback();
+ },
+
+ '1. A listener added with `once` should only listen once and then be removed.': function (test) {
+
+ var emitter = this.emitter;
+
+ emitter.once('test1', function () {
+ test.ok(true, 'The event was raised once');
+ });
+
+ emitter.emit('test1');
+ emitter.emit('test1');
+
+ test.expect(1);
+ test.done();
+
+ },
+ '2. A listener with a TTL of 4 should only listen 4 times.': function (test) {
+
+ var emitter = this.emitter;
+
+ emitter.many('test1', 4, function (value1) {
+ test.ok(true, 'The event was raised 4 times.');
+ });
+
+ emitter.emit('test1', 1);
+ emitter.emit('test1', 2);
+ emitter.emit('test1', 3);
+ emitter.emit('test1', 4);
+ emitter.emit('test1', 5);
+
+ test.expect(4);
+ test.done();
+
+ },
+ '3. A listener with a TTL of 4 should only listen 4 times and pass parameters.': function (test) {
+
+ var emitter = this.emitter;
+
+ emitter.many('test1', 4, function (value1, value2, value3) {
+ test.ok(typeof value1 !== 'undefined', 'got value 1');
+ test.ok(typeof value2 !== 'undefined', 'got value 2');
+ test.ok(typeof value3 !== 'undefined', 'got value 3');
+ });
+
+ emitter.emit('test1', 1, 'A', false);
+ emitter.emit('test1', 2, 'A', false);
+ emitter.emit('test1', 3, 'A', false);
+ emitter.emit('test1', 4, 'A', false);
+ emitter.emit('test1', 5, 'A', false);
+
+ test.done();
+
+ },
+ '4. Remove an event listener by signature.': function (test) {
+
+ var emitter = this.emitter;
+ var count = 0;
+
+ function f1(event) {
+ "event A";
+ test.ok(true, 'The event was raised less than 3 times.');
+ }
+
+ emitter.on('test1', f1);
+
+ function f2(event) {
+ "event B";
+ test.ok(true, 'The event was raised less than 3 times.');
+ }
+
+ emitter.on('test1', f2);
+
+ function f3(event) {
+ "event C";
+ test.ok(true, 'The event was raised less than 3 times.');
+ }
+
+ emitter.on('test1', f3);
+
+ emitter.removeListener('test1', f2);
+
+ emitter.emit('test1');
+
+ test.expect(2);
+ test.done();
+
+ },
+ '5. `removeListener` and `once`': function(test) {
+
+ var emitter = this.emitter;
+ var functionA = function() { test.ok(true, 'Event was fired'); };
+
+ emitter.once('testA', functionA);
+ emitter.removeListener('testA', functionA);
+
+ emitter.emit('testA');
+
+ test.expect(0);
+ test.done();
+ }
+
+});
248 node_modules/eventemitter2/test/wildcardEvents/addListener.js
View
@@ -0,0 +1,248 @@
+
+var simpleEvents = require('nodeunit').testCase;
+var file = '../../lib/eventemitter2';
+
+module.exports = simpleEvents({
+
+ setUp: function (callback) {
+ var EventEmitter2;
+
+ if(typeof require !== 'undefined') {
+ EventEmitter2 = require(file).EventEmitter2;
+ }
+ else {
+ EventEmitter2 = window.EventEmitter2;
+ }
+
+ this.emitter = new EventEmitter2({
+ wildcard: true
+ });
+ callback();
+ },
+
+ tearDown: function (callback) {
+ //clean up?
+ callback();
+ },
+
+ '1. Add a single listener on a single event.': 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();
+
+ },
+
+ '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) {
+
+ 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();
+
+ },
+
+ '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) {
+
+ 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');
+ });
+
+ emitter.on(type, function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ test.equal(emitter.listeners(type).length, 3, 'There are three emitters');
+
+ test.expect(1);
+ test.done();
+
+ },
+
+ '4. Add two listeners to two different events.': 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');
+ });
+
+ emitter.on('test2', function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ emitter.on('test2', function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ test.equal(emitter.listeners(type).length, 2, 'There are two emitters');
+ test.equal(emitter.listeners('test2').length, 2, 'There are two emitters');
+
+ test.expect(2);
+ test.done();
+ },
+
+ '5. Never adding any listeners should yield a listeners array with the length of 0.': 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('test2').length, 0, 'There are no emitters');
+
+ test.expect(1);
+ test.done();
+ },
+
+ '6. the listener added should be the right listener.': function (test) {
+ var emitter = this.emitter;
+ var type = 'some.listener.bar';
+ var f = function () {};
+
+ emitter.on(type, f);
+ test.equal(emitter.listeners(type).length, 1, 'There are is one emitters');
+ test.equal(emitter.listeners(type)[0], f, 'The function should be f');
+
+ test.expect(2);
+ test.done();
+
+ },
+
+ '7. Listeners on `*`, `*.*`, `*.test` with emissions from `foo.test` and `other.emit`': function (test) {
+ var emitter = this.emitter;
+ var f = function () {
+ test.ok(true, 'the event was fired')
+ };
+
+ emitter.on('*.test', f);
+ emitter.on('*.*', f);
+ emitter.on('*', f);
+
+ emitter.emit('other.emit');
+ emitter.emit('foo.test');
+
+ test.expect(3);
+ test.done();
+ },
+
+ '8. Listeners on `*`, `*.*`, foo.test with emissions from `*`, `*.*` and `foo.test`': function (test) {
+ var emitter = this.emitter;
+ var f = function () {
+ test.ok(true, 'the event was fired')
+ };
+
+ emitter.on('foo.test', f);
+ emitter.on('*.*', f);
+ emitter.on('*', f);
+
+ emitter.emit('*.*');
+ emitter.emit('foo.test');
+ emitter.emit('*')
+
+ test.expect(5);
+ 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();
+ },
+
+ '10. actual event name': function(test) {
+
+ var emitter = this.emitter;
+
+ emitter.on('foo', function() {
+ emitter.emit('bar'); // changes the current event, passes the old one in as a parameter.
+ });
+
+ emitter.on('*', function() {
+ console.log(this.event);
+ });
+
+
+
+ emitter.emit('foo');
+
+ test.done();
+ }
+
+});
804 node_modules/eventemitter2/test/wildcardEvents/all.js
View
@@ -0,0 +1,804 @@
+var basicEvents = require('nodeunit').testCase;
+
+/////helper///////
+function setHelper (emitter, test, testName){
+ var eventNames = [
+ testName,
+ testName + '.*',
+ testName + '.ns1',
+ testName + '.ns1.ns2',
+ testName + '.ns2.*'
+ ];
+
+ for (var i = 0; i < eventNames.length; i++) {
+ emitter.on(eventNames[i], function () {
+ test.ok(true, eventNames[i] + 'has fired');
+ });
+ }
+
+ return eventNames;
+};
+
+module.exports = basicEvents({
+
+ setUp: function (callback) {
+ var EventEmitter2;
+
+ if(typeof require !== 'undefined') {
+ EventEmitter2 = require('../../lib/eventemitter2').EventEmitter2;
+ }
+ else {
+ EventEmitter2 = window.EventEmitter2;
+ }
+
+ this.emitter = new EventEmitter2({
+ wildcard: true,
+ verbose: true
+ });
+
+ callback();
+ },
+
+ tearDown: function (callback) {
+ //clean up?
+ callback();
+ },
+
+ '1. An event can be namespaced.': function (test) {
+
+ var emitter = this.emitter;
+
+ emitter.on('test1.ns1', function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ emitter.emit('test1.ns1');
+
+ test.expect(1);
+ test.done();
+
+ },
+ '2. An event can be namespaced and accept values.': function (test) {
+
+ var emitter = this.emitter;
+
+ emitter.on('test2.ns1', function(value1) {
+ test.ok(true, 'The event was raised');
+ test.ok(typeof value1 !== 'undefined', 'The event was raised with the value `' + value1 + '`.');
+ });
+
+ emitter.emit('test2.ns1', 1);
+
+ test.expect(2);
+ test.done();
+
+ },
+ '3. A namespaced event can be raised multiple times and accept values.': function (test) {
+
+ var emitter = this.emitter;
+
+ emitter.on('test3.ns1', function (value1, value2, value3) {
+ test.ok(true, 'The event was raised');
+ test.ok(arguments.length === 3, 'The event was raised with the correct number of arguments');
+ test.ok(value1 === 1 || value1 === 4, 'The event was raised with the value `' + value1 + '`.');
+ test.ok(value2 === 2 || value2 === 5, 'The event was raised with the value `' + value2 + '`.');
+ test.ok(value3 === 3 || value3 === 6, 'The event was raised with the value `' + value3 + '`.');
+ });
+
+ emitter.emit('test3.ns1', 1, 2, 3);
+ emitter.emit('test3.ns1', 4, 5, 6);
+
+ test.expect(10);
+ test.done();
+ },
+ '4. A listener should support wild cards.': function (test) {
+
+ var emitter = this.emitter;
+
+ emitter.on('test4.*', function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ emitter.emit('test4.ns1');
+
+ test.expect(1);
+ test.done();
+
+ },
+ '5. Emitting an event should support wildcards.': function (test) {
+
+ var emitter = this.emitter;
+
+ emitter.on('test5A.test5B', function () {