From 968380616b201432676df3ce80488a4b9dcba5c8 Mon Sep 17 00:00:00 2001
From: Lloyd Hilaiel <lloyd@hilaiel.com>
Date: Wed, 2 May 2012 21:55:46 -0600
Subject: [PATCH] update hub.js with tested version from PR against
 stomlinson/message_hub.  tested and corrected.

---
 resources/static/lib/hub.js | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/resources/static/lib/hub.js b/resources/static/lib/hub.js
index b995018e7..8da4476cb 100644
--- a/resources/static/lib/hub.js
+++ b/resources/static/lib/hub.js
@@ -26,23 +26,28 @@ Hub = (function() {
 
   function all(callback, context) {
     globalListeners.push({
-      id: currID++,
+      id: currID,
       callback: context ? callback.bind(context) : callback
     });
 
-    return id;
+    return currID++;
   }
 
   function fire(message) {
     var messageListeners = listeners[message];
 
     if(messageListeners) {
+      // XXX: deviation from upstream!  upstream code doesn't pass
+      // 'message' as the first argument.  our code expects it.
+      // at some point we should modify all callers of hub.on() to
+      // not expect first arg to be message.
       for(var i = 0, listener; listener = messageListeners[i]; ++i) {
         listener.callback.apply(null, arguments);
       }
     }
-    
+
     for(var j = 0, glistener; glistener = globalListeners[j]; ++j) {
+      // global listeners get the message name as the first argument
       glistener.callback.apply(null, arguments);
     }
   }
@@ -60,7 +65,7 @@ Hub = (function() {
 
     for(var j = 0, glistener; glistener = globalListeners[j]; ++j) {
       if(glistener.id === id) {
-        globalListeners.splice(i, 1);
+        globalListeners.splice(j, 1);
         break;
       }
     }
-- 
GitLab