From a2b818a90630f901c53ae0c6d9d1531aef08df67 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 23 Jan 2015 22:28:57 -0800 Subject: [PATCH 1/6] Documentation Update Thanks for getting back to my original pull request. Pointing this one with the same change to the development branch like you mentioned. Hope this helps! Playing around with implementations of EventEmitter and having an awesome time of it. Cool stuff! --- docs/guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide.md b/docs/guide.md index a63a627..29bb964 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -86,7 +86,7 @@ If you do not want to use a huge framework like that then you might want to use ```javascript function Player(){} -Player.inherit(EventEmitter); +heir.inherit(Player, EventEmitter); ``` That's all there is to it. From 7c69b6b450c037b66c5fbb4ab43c1845b473f4db Mon Sep 17 00:00:00 2001 From: Eric Eldredge Date: Thu, 12 Feb 2015 14:23:49 -0500 Subject: [PATCH 2/6] Add test for removing a listener from within a listener --- tests/tests.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/tests.js b/tests/tests.js index 6cff17a..c7d9a19 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -466,6 +466,23 @@ assert.strictEqual(flattenCheck(check), '1,2,3,4'); }); + test('can remove another listener from within a listener', function() { + var check = []; + var toRemove = function() { check.push('1'); }; + + ee.addListener('baz', toRemove); + ee.addListener('baz', function() { + check.push(2); + ee.removeListener('baz', toRemove); + }); + ee.addListener('baz', function() { check.push(3); }); + + ee.emitEvent('baz'); + ee.emitEvent('baz'); + + assert.strictEqual(flattenCheck(check), '1,2,2,3,3'); + }); + test('executes multiple listeners and removes those that return true', function() { var check = []; From 52f7c17f9ef16e141634d0ed27bef55e6c530034 Mon Sep 17 00:00:00 2001 From: Eric Eldredge Date: Thu, 12 Feb 2015 14:24:49 -0500 Subject: [PATCH 3/6] Clone list of listeners to guarantee it won't change during emit All tests passing! --- EventEmitter.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/EventEmitter.js b/EventEmitter.js index 818df02..5211bae 100644 --- a/EventEmitter.js +++ b/EventEmitter.js @@ -358,20 +358,22 @@ * @return {Object} Current instance of EventEmitter for chaining. */ proto.emitEvent = function emitEvent(evt, args) { - var listeners = this.getListenersAsObject(evt); + var listenersMap = this.getListenersAsObject(evt); + var listeners; var listener; var i; var key; var response; - for (key in listeners) { - if (listeners.hasOwnProperty(key)) { - i = listeners[key].length; + for (key in listenersMap) { + if (listenersMap.hasOwnProperty(key)) { + listeners = listenersMap[key].slice(0); + i = listeners.length; while (i--) { // If the listener returns true then it shall be removed from the event // The function is executed either with a basic call or an apply if there is an args array - listener = listeners[key][i]; + listener = listeners[i]; if (listener.once === true) { this.removeListener(evt, listener.listener); From 763185b232bda69f4041e58eba97b261c890cd05 Mon Sep 17 00:00:00 2001 From: Asa Zernik Date: Thu, 6 Aug 2015 15:27:52 -0700 Subject: [PATCH 4/6] bower.json nitpick: Use standard 'license' attribute From the bower/bower.json-spec readme: *Recommended* Type: `String` or `Array` of `String` [SPDX license identifier](https://spdx.org/licenses/) or path/url to a license. --- bower.json | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/bower.json b/bower.json index a8513e6..a4c5ad2 100644 --- a/bower.json +++ b/bower.json @@ -9,12 +9,7 @@ "name": "Oliver Caldwell", "web": "http://oli.me.uk/" }, - "licenses": [ - { - "type": "Unlicense", - "url": "http://unlicense.org/" - } - ], + "license": "Unlicense", "keywords": [ "events", "structure" From 67080dd842f1b65996b3077087d583aa14f58d04 Mon Sep 17 00:00:00 2001 From: Oliver Caldwell Date: Thu, 1 Oct 2015 12:46:37 +0100 Subject: [PATCH 5/6] Bump version and replace Wolfy87 -> Olical --- README.md | 14 +++++++------- bower.json | 2 +- component.json | 4 ++-- docs/api.dust | 2 +- docs/api.md | 2 +- docs/guide.md | 10 +++++----- package.json | 6 +++--- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index e3785c2..5f80112 100644 --- a/README.md +++ b/README.md @@ -44,10 +44,10 @@ You can clone the repository with your generic clone commands as a standalone re ```bash # Full repository -git clone git://github.com/Wolfy87/EventEmitter.git +git clone git://github.com/Olical/EventEmitter.git # Or submodule -git submodule add git://github.com/Wolfy87/EventEmitter.git assets/js/EventEmitter +git submodule add git://github.com/Olical/EventEmitter.git assets/js/EventEmitter ``` ### Package managers @@ -55,7 +55,7 @@ git submodule add git://github.com/Wolfy87/EventEmitter.git assets/js/EventEmitt You can also get a copy of EventEmitter through the following package managers: * [NPM][] (wolfy87-eventemitter) * [Bower][] (eventEmitter) - * [Component][] (Wolfy87/EventEmitter) + * [Component][] (Olical/EventEmitter) ## Unlicense @@ -68,7 +68,7 @@ This project used to be released under MIT, but I release everything under the [ I gave people the chance to object in issue #84, which also explains my reasoning. [guide]: https://github.com/Wolfy87/EventEmitter/blob/master/docs/guide.md -[api]: https://github.com/Wolfy87/EventEmitter/blob/master/docs/api.md +[api]: https://github.com/Olical/EventEmitter/blob/master/docs/api.md [simple]: http://jsfiddle.net/Wolfy87/qXQu9/ [regexp dom caster]: http://jsfiddle.net/Wolfy87/JqRvS/ [npm]: https://npmjs.org/ @@ -76,10 +76,10 @@ I gave people the chance to object in issue #84, which also explains my reasonin [component]: http://github.com/component/component [mocha]: http://visionmedia.github.io/mocha/ [chai]: http://chaijs.com/ -[issues]: https://github.com/Wolfy87/EventEmitter/issues -[example]: https://github.com/Wolfy87/EventEmitter/pull/46 +[issues]: https://github.com/Olical/EventEmitter/issues +[example]: https://github.com/Olical/EventEmitter/pull/46 [nathggns]: https://github.com/nathggns [http-server]: https://www.npmjs.org/package/http-server [node.js]: http://nodejs.org/ -[gitter]: https://gitter.im/Wolfy87/EventEmitter?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge +[gitter]: https://gitter.im/Olical/EventEmitter?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge [unlicense]: http://unlicense.org/ diff --git a/bower.json b/bower.json index a4c5ad2..39b9803 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "eventEmitter", "description": "Event based JavaScript for the browser", - "version": "4.2.11", + "version": "4.3.0", "main": [ "./EventEmitter.js" ], diff --git a/component.json b/component.json index bcf9297..34e0670 100644 --- a/component.json +++ b/component.json @@ -1,8 +1,8 @@ { "name": "eventEmitter", - "repo": "Wolfy87/EventEmitter", + "repo": "Olical/EventEmitter", "description": "Event based JavaScript for the browser.", - "version": "4.2.11", + "version": "4.3.0", "scripts": ["EventEmitter.js"], "main": "EventEmitter.js", "license": "Unlicense" diff --git a/docs/api.dust b/docs/api.dust index 8203c42..6a06812 100644 --- a/docs/api.dust +++ b/docs/api.dust @@ -2,7 +2,7 @@ {~n} Each of the methods listed in the API are accessed through an instance of EventEmitter. You can create an instance with `var ee = new EventEmitter();`. Then you can call API methods from `ee`, for example `ee.emitEvent('foo');`.{~n} {~n} -You may also be interested in [the guide](https://github.com/Wolfy87/EventEmitter/blob/master/docs/guide.md) which highlights some key features of EventEmitter and how to use them. It is a broad overview of the script whereas this is concise information about each method in the API.{~n} +You may also be interested in [the guide](https://github.com/Olical/EventEmitter/blob/master/docs/guide.md) which highlights some key features of EventEmitter and how to use them. It is a broad overview of the script whereas this is concise information about each method in the API.{~n} {~n} {#.} diff --git a/docs/api.md b/docs/api.md index 6d10c93..4ce0083 100644 --- a/docs/api.md +++ b/docs/api.md @@ -2,7 +2,7 @@ Each of the methods listed in the API are accessed through an instance of EventEmitter. You can create an instance with `var ee = new EventEmitter();`. Then you can call API methods from `ee`, for example `ee.emitEvent('foo');`. -You may also be interested in [the guide](https://github.com/Wolfy87/EventEmitter/blob/master/docs/guide.md) which highlights some key features of EventEmitter and how to use them. It is a broad overview of the script whereas this is concise information about each method in the API. +You may also be interested in [the guide](https://github.com/Olical/EventEmitter/blob/master/docs/guide.md) which highlights some key features of EventEmitter and how to use them. It is a broad overview of the script whereas this is concise information about each method in the API. ## EventEmitter diff --git a/docs/guide.md b/docs/guide.md index 29bb964..fc18104 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -1,20 +1,20 @@ # Guide -This guide should get you going with EventEmitter. Once finished you may wish to learn more about the script and use methods that are not shown here. At that point you should either browse [the API documentation](https://github.com/Wolfy87/EventEmitter/blob/master/docs/api.md) or have a look around [the source](https://github.com/Wolfy87/EventEmitter/blob/master/EventEmitter.js). +This guide should get you going with EventEmitter. Once finished you may wish to learn more about the script and use methods that are not shown here. At that point you should either browse [the API documentation](https://github.com/Olical/EventEmitter/blob/master/docs/api.md) or have a look around [the source](https://github.com/Olical/EventEmitter/blob/master/EventEmitter.js). ## Getting a copy of the script ### Cloning the full source as a submodule ```bash -git submodule add git://github.com/Wolfy87/EventEmitter.git assets/js/EventEmitter +git submodule add git://github.com/Olical/EventEmitter.git assets/js/EventEmitter ``` This will copy the whole repository, including all documentation and build scripts. Obviously you must replace the destination directory with your desired location. ### Downloading a minified version -You can get pre-built versions of EventEmitter from [the downloads page](https://github.com/Wolfy87/EventEmitter/downloads). I would recommend using the latest version. It's the latest for a reason. +You can get pre-built versions of EventEmitter from [the downloads page](https://github.com/Olical/EventEmitter/downloads). I would recommend using the latest version. It's the latest for a reason. ### Installing the component with Bower @@ -82,7 +82,7 @@ function Player(){} Player.prototype = Object.clone(EventEmitter.prototype); ``` -If you do not want to use a huge framework like that then you might want to use this script I wrote, [Heir](https://github.com/Wolfy87/Heir). It just makes prototypical inheritance nice and easy. So here is how you would inherit EventEmitter's methods with Heir. +If you do not want to use a huge framework like that then you might want to use this script I wrote, [Heir](https://github.com/Olical/Heir). It just makes prototypical inheritance nice and easy. So here is how you would inherit EventEmitter's methods with Heir. ```javascript function Player(){} @@ -274,7 +274,7 @@ ee.emitEvent('addStuff', [10, 20]); ### Method aliases -[Hebo](https://github.com/Hebo), from GitHub, [contributed three aliases](https://github.com/Wolfy87/EventEmitter/pull/35#issuecomment-9920932) to add, remove and emit. The aliases can be found in the [API documentation](https://github.com/Wolfy87/EventEmitter/blob/master/docs/api.md) but here is the mapping. +[Hebo](https://github.com/Hebo), from GitHub, [contributed three aliases](https://github.com/Olical/EventEmitter/pull/35#issuecomment-9920932) to add, remove and emit. The aliases can be found in the [API documentation](https://github.com/Olical/EventEmitter/blob/master/docs/api.md) but here is the mapping. * `on` - `addListener` * `off` - `removeListener` diff --git a/package.json b/package.json index f96ab59..0af272d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wolfy87-eventemitter", - "version": "4.2.11", + "version": "4.3.0", "description": "Event based JavaScript for the browser", "main": "EventEmitter.js", "directories": { @@ -9,7 +9,7 @@ }, "repository": { "type": "git", - "url": "git://github.com/Wolfy87/EventEmitter.git" + "url": "git://github.com/Olical/EventEmitter.git" }, "keywords": [ "eventemitter", @@ -25,7 +25,7 @@ "license": "Unlicense", "readmeFilename": "README.md", "bugs": { - "url": "https://github.com/Wolfy87/EventEmitter/issues" + "url": "https://github.com/Olical/EventEmitter/issues" }, "devDependencies": { "uglify-js": "*", From 9db094d02b1343a0a273d62d77741268b3517dfb Mon Sep 17 00:00:00 2001 From: Oliver Caldwell Date: Thu, 1 Oct 2015 12:48:49 +0100 Subject: [PATCH 6/6] Minify new version --- EventEmitter.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EventEmitter.min.js b/EventEmitter.min.js index 0779d85..f85b5e3 100644 --- a/EventEmitter.min.js +++ b/EventEmitter.min.js @@ -4,4 +4,4 @@ * Oliver Caldwell - http://oli.me.uk/ * @preserve */ -(function(){"use strict";function t(){}function i(t,n){for(var e=t.length;e--;)if(t[e].listener===n)return e;return-1}function n(e){return function(){return this[e].apply(this,arguments)}}var e=t.prototype,r=this,s=r.EventEmitter;e.getListeners=function(n){var r,e,t=this._getEvents();if(n instanceof RegExp){r={};for(e in t)t.hasOwnProperty(e)&&n.test(e)&&(r[e]=t[e])}else r=t[n]||(t[n]=[]);return r},e.flattenListeners=function(t){var e,n=[];for(e=0;e