Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Caldwell committed Oct 1, 2015
2 parents 8553de7 + 9db094d commit 34545d1
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 33 deletions.
12 changes: 7 additions & 5 deletions EventEmitter.js
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion EventEmitter.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions README.md
Expand Up @@ -44,18 +44,18 @@ 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

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

Expand All @@ -68,18 +68,18 @@ 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/
[bower]: http://bower.io/
[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/
9 changes: 2 additions & 7 deletions bower.json
@@ -1,20 +1,15 @@
{
"name": "eventEmitter",
"description": "Event based JavaScript for the browser",
"version": "4.2.11",
"version": "4.3.0",
"main": [
"./EventEmitter.js"
],
"author": {
"name": "Oliver Caldwell",
"web": "http://oli.me.uk/"
},
"licenses": [
{
"type": "Unlicense",
"url": "http://unlicense.org/"
}
],
"license": "Unlicense",
"keywords": [
"events",
"structure"
Expand Down
4 changes: 2 additions & 2 deletions 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"
Expand Down
2 changes: 1 addition & 1 deletion docs/api.dust
Expand Up @@ -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}
{#.}

Expand Down
2 changes: 1 addition & 1 deletion docs/api.md
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions 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

Expand Down Expand Up @@ -82,11 +82,11 @@ 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(){}
Player.inherit(EventEmitter);
heir.inherit(Player, EventEmitter);
```

That's all there is to it.
Expand Down Expand Up @@ -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`
Expand Down
6 changes: 3 additions & 3 deletions 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": {
Expand All @@ -9,7 +9,7 @@
},
"repository": {
"type": "git",
"url": "git://github.com/Wolfy87/EventEmitter.git"
"url": "git://github.com/Olical/EventEmitter.git"
},
"keywords": [
"eventemitter",
Expand All @@ -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": "*",
Expand Down
17 changes: 17 additions & 0 deletions tests/tests.js
Expand Up @@ -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 = [];

Expand Down

0 comments on commit 34545d1

Please sign in to comment.