[Pkg-javascript-commits] [node-component-emitter] 01/03: Imported Upstream version 1.2.0

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Fri Apr 3 22:16:58 UTC 2015


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository node-component-emitter.

commit 1ce82a36dfb149acbe2117b2da12278425888597
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Sat Apr 4 00:05:51 2015 +0200

    Imported Upstream version 1.2.0
---
 .npmignore => .gitignore |  1 -
 .travis.yml              |  4 +++-
 History.md               | 11 +++++++++++
 LICENSE                  | 24 ++++++++++++++++++++++++
 bower.json               |  2 +-
 component.json           |  2 +-
 index.js                 | 15 ++++++---------
 package.json             |  6 ++++--
 test/emitter.js          | 18 ++++++++++++++++++
 9 files changed, 68 insertions(+), 15 deletions(-)

diff --git a/.npmignore b/.gitignore
similarity index 72%
rename from .npmignore
rename to .gitignore
index f05b1f2..3c3629e 100644
--- a/.npmignore
+++ b/.gitignore
@@ -1,2 +1 @@
 node_modules
-test
diff --git a/.travis.yml b/.travis.yml
index 8750e3b..a4596ab 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,4 +1,6 @@
 node_js:
 - "0.8"
 - "0.10"
-language: node_js
\ No newline at end of file
+- "0.12"
+- "iojs"
+language: node_js
diff --git a/History.md b/History.md
index b898ca6..2ab0779 100644
--- a/History.md
+++ b/History.md
@@ -1,4 +1,15 @@
 
+1.2.0 / 2014-02-12
+==================
+
+ * prefix events with `$` to support object prototype method names
+ 
+1.1.3 / 2014-06-20
+==================
+
+ * republish for npm
+ * add LICENSE file
+
 1.1.2 / 2014-02-10
 ==================
 
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..de51692
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,24 @@
+(The MIT License)
+
+Copyright (c) 2014 Component contributors <dev at component.io>
+
+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.
diff --git a/bower.json b/bower.json
index c618d41..c1a5c01 100644
--- a/bower.json
+++ b/bower.json
@@ -5,7 +5,7 @@
     "emitter",
     "events"
   ],
-  "version": "1.1.2",
+  "version": "1.2.0",
   "license": "MIT",
   "main": "index.js",
   "homepage": "https://github.com/component/emitter",
diff --git a/component.json b/component.json
index 68ba0b1..009d846 100644
--- a/component.json
+++ b/component.json
@@ -6,7 +6,7 @@
     "emitter",
     "events"
   ],
-  "version": "1.1.2",
+  "version": "1.2.0",
   "scripts": [
     "index.js"
   ],
diff --git a/index.js b/index.js
index ad71163..1c78176 100644
--- a/index.js
+++ b/index.js
@@ -42,7 +42,7 @@ function mixin(obj) {
 Emitter.prototype.on =
 Emitter.prototype.addEventListener = function(event, fn){
   this._callbacks = this._callbacks || {};
-  (this._callbacks[event] = this._callbacks[event] || [])
+  (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
     .push(fn);
   return this;
 };
@@ -58,11 +58,8 @@ Emitter.prototype.addEventListener = function(event, fn){
  */
 
 Emitter.prototype.once = function(event, fn){
-  var self = this;
-  this._callbacks = this._callbacks || {};
-
   function on() {
-    self.off(event, on);
+    this.off(event, on);
     fn.apply(this, arguments);
   }
 
@@ -94,12 +91,12 @@ Emitter.prototype.removeEventListener = function(event, fn){
   }
 
   // specific event
-  var callbacks = this._callbacks[event];
+  var callbacks = this._callbacks['$' + event];
   if (!callbacks) return this;
 
   // remove all handlers
   if (1 == arguments.length) {
-    delete this._callbacks[event];
+    delete this._callbacks['$' + event];
     return this;
   }
 
@@ -126,7 +123,7 @@ Emitter.prototype.removeEventListener = function(event, fn){
 Emitter.prototype.emit = function(event){
   this._callbacks = this._callbacks || {};
   var args = [].slice.call(arguments, 1)
-    , callbacks = this._callbacks[event];
+    , callbacks = this._callbacks['$' + event];
 
   if (callbacks) {
     callbacks = callbacks.slice(0);
@@ -148,7 +145,7 @@ Emitter.prototype.emit = function(event){
 
 Emitter.prototype.listeners = function(event){
   this._callbacks = this._callbacks || {};
-  return this._callbacks[event] || [];
+  return this._callbacks['$' + event] || [];
 };
 
 /**
diff --git a/package.json b/package.json
index 4f096ab..b523901 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,8 @@
 {
   "name": "component-emitter",
   "description": "Event emitter",
-  "version": "1.1.2",
+  "version": "1.2.0",
+  "license": "MIT",
   "devDependencies": {
     "mocha": "*",
     "should": "*"
@@ -18,5 +19,6 @@
   },
   "scripts": {
     "test": "make test"
-  }
+  },
+  "files": ["index.js", "LICENSE"]
 }
diff --git a/test/emitter.js b/test/emitter.js
index 91ea483..02c3a0b 100644
--- a/test/emitter.js
+++ b/test/emitter.js
@@ -37,6 +37,24 @@ describe('Emitter', function(){
 
       calls.should.eql([ 'one', 1, 'two', 1, 'one', 2, 'two', 2 ]);
     })
+
+    it('should add listeners for events which are same names with methods of Object.prototype', function(){
+      var emitter = new Emitter;
+      var calls = [];
+
+      emitter.on('constructor', function(val){
+        calls.push('one', val);
+      });
+
+      emitter.on('__proto__', function(val){
+        calls.push('two', val);
+      });
+
+      emitter.emit('constructor', 1);
+      emitter.emit('__proto__', 2);
+
+      calls.should.eql([ 'one', 1, 'two', 2 ]);
+    })
   })
 
   describe('.once(event, fn)', function(){

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-component-emitter.git



More information about the Pkg-javascript-commits mailing list