incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [3/5] js commit: Fix channel not passing args when firing in one case.
Date Fri, 24 Aug 2012 03:36:22 GMT
Fix channel not passing args when firing in one case.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/470ac670
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/470ac670
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/470ac670

Branch: refs/heads/master
Commit: 470ac6708778afb39cf1bedacddaa24abb91ae9c
Parents: 3b3e2de
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Aug 23 23:19:23 2012 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Thu Aug 23 23:35:56 2012 -0400

----------------------------------------------------------------------
 lib/common/channel.js |    4 ++--
 test/test.channel.js  |    9 +++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/470ac670/lib/common/channel.js
----------------------------------------------------------------------
diff --git a/lib/common/channel.js b/lib/common/channel.js
index c1cd702..7281f1b 100755
--- a/lib/common/channel.js
+++ b/lib/common/channel.js
@@ -154,7 +154,7 @@ Channel.prototype.subscribe = function(f, c, g) {
         this.handlers[g] = func;
         this.numHandlers++;
         if (this.events.onSubscribe) this.events.onSubscribe.call(this);
-        if (this.fired) func.call(this);
+        if (this.fired) func.apply(this, this.fireArgs);
     }
     return g;
 };
@@ -206,6 +206,7 @@ Channel.prototype.fire = function(e) {
     if (this.enabled) {
         var fail = false;
         this.fired = true;
+        this.fireArgs = arguments;
         for (var item in this.handlers) {
             var handler = this.handlers[item];
             if (typeof handler == 'function') {
@@ -213,7 +214,6 @@ Channel.prototype.fire = function(e) {
                 fail = fail || rv;
             }
         }
-        this.fireArgs = arguments;
         return !fail;
     }
     return true;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/470ac670/test/test.channel.js
----------------------------------------------------------------------
diff --git a/test/test.channel.js b/test/test.channel.js
index 9968901..b485f6f 100644
--- a/test/test.channel.js
+++ b/test/test.channel.js
@@ -206,6 +206,15 @@ describe("channel", function () {
             expect(before).toHaveBeenCalled();
             expect(after).toHaveBeenCalled();
         });
+        it("should instantly trigger the callback if the event is currently being fired.",
function () {
+            var handler1 = jasmine.createSpy().andCallFake(function() { c.subscribe(handler2);
}),
+                handler2 = jasmine.createSpy().andCallFake(function(arg1) { expect(arg1).toEqual('foo');});
+
+            c.subscribe(handler1);
+            c.fire('foo');
+
+            expect(handler2).toHaveBeenCalled();
+        });
     });
     describe("subscribeOnce method", function() {
         it("should be unregistered after being fired.", function() {


Mime
View raw message