Skip to content

Commit

Permalink
Merge f884515 into d692180
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand Laporte committed Apr 13, 2014
2 parents d692180 + f884515 commit 2da1ba6
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
7 changes: 7 additions & 0 deletions hsp/rt/$root.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,13 @@ var $CptNode = klass({
} else {
if (this.refreshAttributes) {
this.refreshAttributes();
// for component and sub-templates the original vscope is substituted
// to the one of the component- or sub-template
// so we need to revert to the parent scope to observe the correct objects
var vs=this.vscope;
this.vscope=this.parent.vscope;
this.root.updateObjectObservers(this);
this.vscope=vs;
}
}
this.adirty = false;
Expand Down
40 changes: 40 additions & 0 deletions public/test/rt/cptattelements1.spec.hsp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ PanelController = klass({
</div>
# /template

var TestCtl=klass({
attributes:{
"value":{type:"string",binding:"1-way"}
}
})

# template item using c:TestCtl
Value: {c.value}
# /template

# template test7(m)
<div class="content">
<#item value="{m.prop.value}"/>
</div>
# /template

var HEAD=".panel .head";
var BODY=".panel .body";

Expand Down Expand Up @@ -218,6 +234,30 @@ describe("Component attribute elements (1)", function () {
h.$dispose();
});

it("validates change propagation with long expression paths", function() {
var h=ht.newTestContext();
var count=0, model={prop:{value:"hello"}};

test7(model).render(h.container);
expect(h(".content").text()).to.equal("Value: hello");

// change data
count++;
h.$set(model.prop,"value","hello"+count);
expect(h(".content").text()).to.equal("Value: hello1");

// change path
h.$set(model,"prop",{value:"foo"});
expect(h(".content").text()).to.equal("Value: foo");

// change data
count++;
h.$set(model.prop,"value","hello"+count);
expect(h(".content").text()).to.equal("Value: hello2");

h.$dispose();
});

// TODO
// properly dispose generated properties
// test errors when sub-template attribute are improperly mixed
Expand Down
33 changes: 33 additions & 0 deletions public/test/rt/subtemplates3.spec.hsp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ var removeItem = function (items, index) {
<a onclick="{addItem(items)}">Add item</a>
# /template

# template item(value)
Value: {value}
# /template

# template test1(m)
<div class="content">
<#item value="{m.prop.value}"/>
</div>
# /template

describe("Sub- and parent- template scope interactions", function () {
it("validates property bubbling from sub-template to parent", function() {
Expand All @@ -66,5 +75,29 @@ describe("Sub- and parent- template scope interactions", function () {

h.$dispose();
});

it("validates change propagation with long expression paths", function() {
var h=ht.newTestContext();
var count=0, model={prop:{value:"hello"}};

test1(model).render(h.container);
expect(h(".content").text()).to.equal("Value: hello");

// change data
count++;
h.$set(model.prop,"value","hello"+count);
expect(h(".content").text()).to.equal("Value: hello1");

// change path
h.$set(model,"prop",{value:"foo"});
expect(h(".content").text()).to.equal("Value: foo");

// change data
count++;
h.$set(model.prop,"value","hello"+count);
expect(h(".content").text()).to.equal("Value: hello2");

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

0 comments on commit 2da1ba6

Please sign in to comment.