From ccb5abc9ccbcc300b7231f04a87cd048f598b374 Mon Sep 17 00:00:00 2001 From: Marc Laval Date: Tue, 2 Sep 2014 19:46:20 +0200 Subject: [PATCH] fix #33 Need a way to know if an event handler attribute value was provided --- hsp/rt/cptwrapper.js | 15 +++++++++++++-- test/rt/cptwrapper.spec.hsp | 17 ++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/hsp/rt/cptwrapper.js b/hsp/rt/cptwrapper.js index 3c49a22..7948dfb 100644 --- a/hsp/rt/cptwrapper.js +++ b/hsp/rt/cptwrapper.js @@ -211,8 +211,8 @@ var CptWrapper = klass({ } if (att.type === "callback") { // create an even callback function - this.createEventFunction(k.slice(2)); - cpt[k].isEmpty=(iAtt===undefined); + var isEmpty = !this.createEventFunction(k.slice(2)); + cpt[k].isEmpty = isEmpty; continue; } else if (att.type === "template") { v=null; @@ -268,6 +268,17 @@ var CptWrapper = klass({ self.nodeInstance.onEvent(evtData); } }; + if (this.nodeInstance) { + var evh = this.nodeInstance.evtHandlers; + if (evh) { + for (var i = 0; i < evh.length; i++) { + if (evh[i].evtType === evtType) { + return true; + } + } + } + } + return false; }, /** diff --git a/test/rt/cptwrapper.spec.hsp b/test/rt/cptwrapper.spec.hsp index 431ad9f..4853514 100644 --- a/test/rt/cptwrapper.spec.hsp +++ b/test/rt/cptwrapper.spec.hsp @@ -192,6 +192,9 @@ describe("Component Nodes", function () { expect(c.value).to.equal(0); expect(c.isValid).to.equal(false); + //Issue #33 + expect(c.onbeforereset.isEmpty).to.be.ok(); + cw.$dispose(); expect(cw.cpt).to.equal(null); expect(c["+json:observers"]).to.equal(undefined); @@ -334,12 +337,24 @@ it("tests a component inside another template", function() { expect(resetCount).to.equal(1); //validate that "onbeforereset" callback has been called expect(lastEvtType).to.equal("beforereset"); - expect(isBrCbEmpty).to.equal(true); + expect(isBrCbEmpty).to.equal(false); expect(lastResetArg).to.equal(123); expect(lastEvtType2).to.equal("afterreset"); expect(lastEvtOldValue2).to.equal(42); }); + it("tests if callback is not empty (issue #33)", function() { + isBrCbEmpty=false; + var d={value:'42'}; + var n=test(d); + var cptButton=n.node.childNodes[3]; + + fireEvent("click",cptButton); + hsp.refresh(); + + expect(isBrCbEmpty).to.equal(false); + }); + it("tests if callback is empty", function() { isBrCbEmpty=false; var d={value:'42'};