[Pkg-javascript-commits] [sockjs-client] 422/434: introducing EventEmitter.on

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:30 UTC 2014


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

tonnerre-guest pushed a commit to branch master
in repository sockjs-client.

commit 0b6ee5dd245e53d7f372610b6094b12bdedecbbd
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Tue May 22 17:22:27 2012 +0100

    introducing EventEmitter.on
---
 lib/eventemitter.js | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/lib/eventemitter.js b/lib/eventemitter.js
index 0ea96a9..f0c9206 100644
--- a/lib/eventemitter.js
+++ b/lib/eventemitter.js
@@ -9,6 +9,7 @@
 var EventEmitter = function(events) {
     var that = this;
     that._events = events || [];
+    that._listeners = {};
 };
 EventEmitter.prototype.emit = function(type) {
     var that = this;
@@ -19,7 +20,24 @@ EventEmitter.prototype.emit = function(type) {
     if (that['on'+type]) {
         that['on'+type].apply(that, args);
     }
+    if (type in that._listeners) {
+        for(var i = 0; i < that._listeners[type].length; i++) {
+            that._listeners[type][i].apply(that, args);
+        }
+    }
 };
+
+EventEmitter.prototype.on = function(type, callback) {
+    var that = this;
+    that._verifyType(type);
+    if (that._nuked) return;
+
+    if (!(type in that._listeners)) {
+        that._listeners[type] = [];
+    }
+    that._listeners[type].push(callback);
+};
+
 EventEmitter.prototype._verifyType = function(type) {
     var that = this;
     if (utils.arrIndexOf(that._events, type) === -1) {
@@ -35,4 +53,5 @@ EventEmitter.prototype.nuke = function() {
     for(var i=0; i<that._events.length; i++) {
         delete that[that._events[i]];
     }
+    that._listeners = {};
 };

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list