From 01273e9358ac5a2e82e5ebd6cfd3f24b09b5c0a3 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Thu, 29 Oct 2015 11:33:03 -0700 Subject: [PATCH] Ensure outer paths aren't forwarded to instance props. Fixes #2556. --- src/lib/template/templatizer.html | 5 ++++- src/standard/notify-path.html | 10 ++++----- test/unit/templatizer-elements.html | 32 +++++++++++++++++++++++++---- test/unit/templatizer.html | 14 +++++++++++++ 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/src/lib/template/templatizer.html b/src/lib/template/templatizer.html index 9466bca24b..bb0cc8bcc4 100644 --- a/src/lib/template/templatizer.html +++ b/src/lib/template/templatizer.html @@ -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); diff --git a/src/standard/notify-path.html b/src/standard/notify-path.html index 1da8324de0..069e3a3544 100644 --- a/src/standard/notify-path.html +++ b/src/standard/notify-path.html @@ -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); }, @@ -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); } } }, @@ -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); } } }, diff --git a/test/unit/templatizer-elements.html b/test/unit/templatizer-elements.html index e11d033f7d..395787a633 100644 --- a/test/unit/templatizer-elements.html +++ b/test/unit/templatizer-elements.html @@ -10,6 +10,7 @@ prop="{{prop}}" obj="{{obj}}" obj-prop="{{obj.prop}}" + conflict="{{outerInnerConflict.prop}}" > @@ -22,6 +23,7 @@ prop="{{prop}}" obj="{{obj}}" obj-prop="{{obj.prop}}" + conflict="{{outerInnerConflict.prop}}" > @@ -49,6 +51,9 @@ }, objProp: { notify: true + }, + outerInnerConflict: { + notify: true } }, observers: [ @@ -76,7 +81,8 @@ ], _instanceProps: { obj: true, - prop: true + prop: true, + outerInnerConflict: true }, propChanged: function(value) { this._forwardParentProp('prop', value); @@ -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); } @@ -137,7 +149,8 @@ ], _instanceProps: { obj: true, - prop: true + prop: true, + outerInnerConflict: true }, propChanged: function(value) { this._forwardParentProp('prop', value); @@ -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); } @@ -205,6 +224,11 @@ value: function() { return { prop: 'objB.prop' }; } + }, + outerInnerConflict: { + value: function() { + return { prop: 'conflict' }; + } } }, observers: [ diff --git a/test/unit/templatizer.html b/test/unit/templatizer.html index ca5b1dabb6..d578c32d07 100644 --- a/test/unit/templatizer.html +++ b/test/unit/templatizer.html @@ -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() { @@ -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'); + }); + });