Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #33 Need a way to know if an event handler attribute value was provi... #283

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions hsp/rt/cptwrapper.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
},

/**
Expand Down
17 changes: 16 additions & 1 deletion test/rt/cptwrapper.spec.hsp
Expand Up @@ -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);
Expand Down Expand Up @@ -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'};
Expand Down