incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [1/2] js commit: If a channel is already fired and a handler is attached to it, fire the handler.
Date Fri, 01 Jun 2012 23:47:53 GMT
Updated Branches:
  refs/heads/master 63b20bb41 -> 95feb23c6


If a channel is already fired and a handler is attached to it, fire the handler.


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/95feb23c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/95feb23c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/95feb23c

Branch: refs/heads/master
Commit: 95feb23c6f2bcd8303ffb44cea41cc7a2e7adee7
Parents: 7065728
Author: Fil Maj <maj.fil@gmail.com>
Authored: Fri Jun 1 16:47:46 2012 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Fri Jun 1 16:47:46 2012 -0700

----------------------------------------------------------------------
 lib/common/channel.js |    1 +
 test/test.channel.js  |   12 ++++++++++++
 2 files changed, 13 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/95feb23c/lib/common/channel.js
----------------------------------------------------------------------
diff --git a/lib/common/channel.js b/lib/common/channel.js
index 176bc07..62662d5 100755
--- a/lib/common/channel.js
+++ b/lib/common/channel.js
@@ -155,6 +155,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);
     return g;
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/95feb23c/test/test.channel.js
----------------------------------------------------------------------
diff --git a/test/test.channel.js b/test/test.channel.js
index f7c158b..5a43802 100644
--- a/test/test.channel.js
+++ b/test/test.channel.js
@@ -158,5 +158,17 @@ describe("channel", function () {
             expect(count).toEqual(1);
 
         });
+        it("should instantly trigger the callback if the event has already been fired", function
() {
+            var chan = channel.create("foo"),
+                before = jasmine.createSpy('before'),
+                after = jasmine.createSpy('after');
+
+            chan.subscribe(before);
+            chan.fire();
+            chan.subscribe(after);
+
+            expect(before).toHaveBeenCalled();
+            expect(after).toHaveBeenCalled();
+        });
     });
 });


Mime
View raw message