diff --git a/hsp/rt/$root.js b/hsp/rt/$root.js
index 88e4bd5..53191ce 100644
--- a/hsp/rt/$root.js
+++ b/hsp/rt/$root.js
@@ -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;
diff --git a/public/test/rt/cptattelements1.spec.hsp b/public/test/rt/cptattelements1.spec.hsp
index abce00b..a711840 100644
--- a/public/test/rt/cptattelements1.spec.hsp
+++ b/public/test/rt/cptattelements1.spec.hsp
@@ -85,6 +85,22 @@ PanelController = klass({
# /template
+var TestCtl=klass({
+ attributes:{
+ "value":{type:"string",binding:"1-way"}
+ }
+})
+
+# template item using c:TestCtl
+ Value: {c.value}
+# /template
+
+# template test7(m)
+
+ <#item value="{m.prop.value}"/>
+
+# /template
+
var HEAD=".panel .head";
var BODY=".panel .body";
@@ -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
diff --git a/public/test/rt/subtemplates3.spec.hsp b/public/test/rt/subtemplates3.spec.hsp
index 862c6c0..17f9860 100644
--- a/public/test/rt/subtemplates3.spec.hsp
+++ b/public/test/rt/subtemplates3.spec.hsp
@@ -41,6 +41,15 @@ var removeItem = function (items, index) {
Add item
# /template
+# template item(value)
+ Value: {value}
+# /template
+
+# template test1(m)
+
+ <#item value="{m.prop.value}"/>
+
+# /template
describe("Sub- and parent- template scope interactions", function () {
it("validates property bubbling from sub-template to parent", function() {
@@ -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();
+ });
});