You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2012/08/24 23:57:38 UTC
[2/50] [abbrv] js commit: Fix channel not passing args when firing in
one case.
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/5732d87e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/5732d87e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/5732d87e
Branch: refs/heads/master
Commit: 5732d87e4779211e8ef6e1d6cde2b61c23b75d6e
Parents: 32ddfa6
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Aug 23 23:19:23 2012 -0400
Committer: Anis Kadri <an...@gmail.com>
Committed: Fri Aug 24 13:50:04 2012 -0700
----------------------------------------------------------------------
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/5732d87e/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/5732d87e/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() {