Return-Path: X-Original-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 46A049CF7 for ; Fri, 1 Jun 2012 23:47:54 +0000 (UTC) Received: (qmail 41138 invoked by uid 500); 1 Jun 2012 23:47:54 -0000 Delivered-To: apmail-incubator-callback-commits-archive@incubator.apache.org Received: (qmail 41122 invoked by uid 500); 1 Jun 2012 23:47:54 -0000 Mailing-List: contact callback-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-commits@incubator.apache.org Received: (qmail 41106 invoked by uid 99); 1 Jun 2012 23:47:54 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Jun 2012 23:47:54 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id C90C5F64C; Fri, 1 Jun 2012 23:47:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: filmaj@apache.org To: callback-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [1/2] js commit: If a channel is already fired and a handler is attached to it, fire the handler. Message-Id: <20120601234753.C90C5F64C@tyr.zones.apache.org> Date: Fri, 1 Jun 2012 23:47:53 +0000 (UTC) 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 Authored: Fri Jun 1 16:47:46 2012 -0700 Committer: Fil Maj 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(); + }); }); });