allow handler to be removed and resubscribed
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/70657289 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/70657289 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/70657289 Branch: refs/heads/master Commit: 70657289235255b84dd4a428e28de1e945a3425b Parents: 63b20bb Author: Julien Bouquillon <jul...@bouquillon.com> Authored: Fri Jun 1 11:53:41 2012 +0200 Committer: Julien Bouquillon <jul...@bouquillon.com> Committed: Fri Jun 1 11:53:41 2012 +0200 ---------------------------------------------------------------------- lib/common/channel.js | 1 + test/test.channel.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/70657289/lib/common/channel.js ---------------------------------------------------------------------- diff --git a/lib/common/channel.js b/lib/common/channel.js index 3456e6a..176bc07 100755 --- a/lib/common/channel.js +++ b/lib/common/channel.js @@ -191,6 +191,7 @@ Channel.prototype.unsubscribe = function(g) { if (typeof g == 'function') { g = g.observer_guid; } var handler = this.handlers[g]; if (handler) { + if (handler.observer_guid) handler.observer_guid=null; this.handlers[g] = null; delete this.handlers[g]; this.numHandlers--; http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/70657289/test/test.channel.js ---------------------------------------------------------------------- diff --git a/test/test.channel.js b/test/test.channel.js index 34984e9..f7c158b 100644 --- a/test/test.channel.js +++ b/test/test.channel.js @@ -144,5 +144,19 @@ describe("channel", function () { expect(handler).toHaveBeenCalled(); expect(count).toEqual(1); }); + it("handler should be called when subscribed, removed, and subscribed again", function() { + var count = 0; + var handler = jasmine.createSpy().andCallFake(function() { count++; }); + + c.subscribe(handler); + c.unsubscribe(handler); + c.subscribe(handler); + + c.fire(); + + expect(handler).toHaveBeenCalled(); + expect(count).toEqual(1); + + }); }); });