Skip to content

Commit

Permalink
WIP: fixing ariatemplates#125
Browse files Browse the repository at this point in the history
  • Loading branch information
divdavem committed Apr 10, 2014
1 parent d692180 commit 4895742
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
21 changes: 10 additions & 11 deletions hsp/rt/$root.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ var CPT_TYPES={
var DOCUMENT_FRAGMENT_NODE = 11;

/**
* Root node - created at the root of each template
* Contains the listeners requested by the child nodes
* Root node - created at the root of each template
* Contains the listeners requested by the child nodes
* Is replaced by the $CptNode (child class) when the template is inserted in another template
*/
var $RootNode = klass({
Expand Down Expand Up @@ -384,8 +384,8 @@ var $CptNode = klass({
createNodeInstance : function (parent) {
var ni=null, vscope=parent.vscope, tp=this.tplPath;

// determine the type of this component:
// - either a template - e.g. <#mytemplate foo="bar"/>
// determine the type of this component:
// - either a template - e.g. <#mytemplate foo="bar"/>
// -> instance will extend $CptTemplate
// - a component with controller - e.g. <#mycpt foo="bar"/>
// -> instance will extend $CptComponent
Expand All @@ -408,7 +408,7 @@ var $CptNode = klass({
ni.initCpt({template:obj,ctlConstuctor:obj.controllerConstructor});
} else if (obj) {
if (obj.isCptAttElement) {
// insert attribute component
// insert attribute component
ni=this.createCptInstance("$CptAttInsert",parent);
ni.initCpt(obj);
}
Expand Down Expand Up @@ -455,7 +455,7 @@ var $CptNode = klass({
ni.node = ni.parent.node;
return ni;
},

/**
* Callback called when a controller attribute or a template attribute has changed
*/
Expand Down Expand Up @@ -504,7 +504,6 @@ var $CptNode = klass({
this.refreshAttributes();
}
}
this.adirty = false;
}
TNode.refresh.call(this);
},
Expand Down Expand Up @@ -559,7 +558,7 @@ var $CptNode = klass({
var sz=pos.length;

this._pathChgeCb = this.onPathChange.bind(this);

for (var i=0;sz>i;i++) {
json.observe(pos[i], this._pathChgeCb);
}
Expand Down Expand Up @@ -643,7 +642,7 @@ var $CptAttElement = klass({
isCptAttElement : true,

/**
* $CptAttElement generator
* $CptAttElement generator
*/
$constructor : function (name, exps, attcfg, ehcfg, children) {
this.name = name;
Expand All @@ -657,7 +656,7 @@ var $CptAttElement = klass({
},

/**
* Tell this node can be found in a component content
* Tell this node can be found in a component content
* other (if false) the component will generate the default component content element
*/
isValidCptAttElement:function () {
Expand All @@ -680,7 +679,7 @@ var $CptAttElement = klass({
if (p.ctlAttributes) {
attDef=p.ctlAttributes[this.name];
}

if (!eltDef && !attDef) {
// invalid elt
log.error(this+" Element not supported by its parent component");
Expand Down
15 changes: 13 additions & 2 deletions public/test/rt/exprbinding.spec.hsp
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,34 @@ function changeValue (data,val) {
$set(data.object,"value",val);
}

# template test1(data)
# template displayValue(value)
<input class="in3" type="text" value="{value}" />
# /template

# template test1(data)
<input class="in1" type="text" value="{data.object.value}" />
<input class="in2" type="text" value="{data.object.value}" />
<#displayValue value="{data.object.value}"/>
# /template

describe("Expression Bindings", function () {
var INPUT1=".in1", INPUT2=".in2";
var INPUT1=".in1", INPUT2=".in2", INPUT3=".in3";

it("validates bindings with value change", function() {
var h=ht.newTestContext(), dm={object:{value:"initial value"}};
test1(dm).render(h.container);

expect(h(INPUT1).value()).to.equal("initial value");
expect(h(INPUT2).value()).to.equal("initial value");
expect(h(INPUT3).value()).to.equal("initial value");


changeValue(dm,"v1");
h.refresh();

expect(h(INPUT1).value()).to.equal("v1");
expect(h(INPUT2).value()).to.equal("v1");
expect(h(INPUT3).value()).to.equal("v1");

h.$dispose();
});
Expand All @@ -57,18 +65,21 @@ describe("Expression Bindings", function () {

expect(h(INPUT1).value()).to.equal("v1");
expect(h(INPUT2).value()).to.equal("v1");
expect(h(INPUT3).value()).to.equal("v1");

changeValue(dm,"v2");
h.refresh();

expect(h(INPUT1).value()).to.equal("v2");
expect(h(INPUT2).value()).to.equal("v2");
expect(h(INPUT3).value()).to.equal("v2");

changeValueAndObject(dm,"v3");
h.refresh();

expect(h(INPUT1).value()).to.equal("v3");
expect(h(INPUT2).value()).to.equal("v3");
expect(h(INPUT3).value()).to.equal("v3");

h.$dispose();
});
Expand Down

0 comments on commit 4895742

Please sign in to comment.