Skip to content

Commit

Permalink
Ensure outer paths aren't forwarded to instance props. Fixes #2556.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Oct 29, 2015
1 parent 30da1b3 commit 01273e9
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/lib/template/templatizer.html
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@
if (this._forwardParentPath) {
if (path.indexOf(this._parentPropPrefix) === 0) {
var subPath = path.substring(this._parentPropPrefix.length);
this._forwardParentPath(subPath, value);
var model = this._modelForPath(subPath);
if (model in this._parentProps) {
this._forwardParentPath(subPath, value);
}
}
}
Polymer.Base._pathEffector.call(this._templatized, path, value, fromAbove);
Expand Down
10 changes: 5 additions & 5 deletions src/standard/notify-path.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
notifyPath: function(path, value, fromAbove) {
// Convert any array indices to keys before notifying path
var info = {};
path = this._get(path, this, info);
this._get(path, this, info);
// Notify change to key-based path
this._notifyPath(info.path, value, fromAbove);
},
Expand Down Expand Up @@ -294,9 +294,9 @@
} else if ((path.indexOf(effect.value + '.') === 0) && !effect.negate) {
// locate the bound node
var node = this._nodes[effect.index];
if (node && node.notifyPath) {
if (node && node._notifyPath) {
var p = this._fixPath(effect.name , effect.value, path);
node.notifyPath(p, value, true);
node._notifyPath(p, value, true);
}
}
},
Expand Down Expand Up @@ -364,9 +364,9 @@
for (var a in this._boundPaths) {
var b = this._boundPaths[a];
if (path.indexOf(a + '.') == 0) {
this.notifyPath(this._fixPath(b, a, path), value);
this._notifyPath(this._fixPath(b, a, path), value);
} else if (path.indexOf(b + '.') == 0) {
this.notifyPath(this._fixPath(a, b, path), value);
this._notifyPath(this._fixPath(a, b, path), value);
}
}
},
Expand Down
32 changes: 28 additions & 4 deletions test/unit/templatizer-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
prop="{{prop}}"
obj="{{obj}}"
obj-prop="{{obj.prop}}"
conflict="{{outerInnerConflict.prop}}"
></x-child>
</template>
</x-templatizer>
Expand All @@ -22,6 +23,7 @@
prop="{{prop}}"
obj="{{obj}}"
obj-prop="{{obj.prop}}"
conflict="{{outerInnerConflict.prop}}"
></x-child>
</template>

Expand Down Expand Up @@ -49,6 +51,9 @@
},
objProp: {
notify: true
},
outerInnerConflict: {
notify: true
}
},
observers: [
Expand Down Expand Up @@ -76,7 +81,8 @@
],
_instanceProps: {
obj: true,
prop: true
prop: true,
outerInnerConflict: true
},
propChanged: function(value) {
this._forwardParentProp('prop', value);
Expand Down Expand Up @@ -113,7 +119,13 @@
go: function() {
var template = Polymer.dom(this).querySelector('template');
this.templatize(template);
this.instance = this.stamp({obj: this.obj, prop: this.prop});
this.instance = this.stamp({
obj: this.obj,
prop: this.prop,
outerInnerConflict: {
prop: 'bar'
}
});
var parent = Polymer.dom(this).parentNode;
Polymer.dom(parent).appendChild(this.instance.root);
}
Expand All @@ -137,7 +149,8 @@
],
_instanceProps: {
obj: true,
prop: true
prop: true,
outerInnerConflict: true
},
propChanged: function(value) {
this._forwardParentProp('prop', value);
Expand Down Expand Up @@ -173,7 +186,13 @@
},
go: function() {
this.templatize(this);
this.instance = this.stamp({obj: this.obj, prop: this.prop});
this.instance = this.stamp({
obj: this.obj,
prop: this.prop,
outerInnerConflict: {
prop: 'bar'
}
});
var parent = Polymer.dom(this).parentNode;
Polymer.dom(parent).appendChild(this.instance.root);
}
Expand Down Expand Up @@ -205,6 +224,11 @@
value: function() {
return { prop: 'objB.prop' };
}
},
outerInnerConflict: {
value: function() {
return { prop: 'conflict' };
}
}
},
observers: [
Expand Down
14 changes: 14 additions & 0 deletions test/unit/templatizer.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@
assert.equal(host.objAChanged.getCall(0).args[0].value, 'objA.prop++');
});

test('outer & inner props conflict', function() {
host.$.templatizer.go();
assert.ok(childA);
host.set('outerInnerConflict.prop', 'foo');
assert.equal(childA.conflict, 'bar');
});

});

suite('templatizer client and template same element (template extension)', function() {
Expand Down Expand Up @@ -234,6 +241,13 @@
assert.equal(host.objBChanged.getCall(0).args[0].value, 'objB.prop++');
});

test('outer & inner props conflict', function() {
host.$.templatizer.go();
assert.ok(childA);
host.set('outerInnerConflict.prop', 'foo');
assert.equal(childA.conflict, 'bar');
});

});

</script>
Expand Down

0 comments on commit 01273e9

Please sign in to comment.