From cd362bb891486384bf64bf1796f273268fb184b8 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Thu, 19 Mar 2015 17:55:41 -0700 Subject: [PATCH] Avoid non-bubbling event gotchas with binding. --- src/lib/bind/bind.html | 13 +++++++---- test/unit/bind-elements.html | 44 ++++++++++++++++++++++++++++++++++++ test/unit/bind.html | 23 +++++++++++++++++++ 3 files changed, 75 insertions(+), 5 deletions(-) diff --git a/src/lib/bind/bind.html b/src/lib/bind/bind.html index 71522b31..3687af13 100644 --- a/src/lib/bind/bind.html +++ b/src/lib/bind/bind.html @@ -23,7 +23,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN _addAnnotatedListener: function(model, index, property, path) { // .on.-changed: = e.detail.value // - var changedFn = '\tthis.' + path + ' = e.detail.value;'; + var changedFn = '\t\tthis.' + path + ' = e.detail.value;'; if (path.indexOf('.') > 0) { // TODO(kschaaf): dirty check avoids null references when the object has gone away changedFn = @@ -32,12 +32,15 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN '\t\tthis.notifyPath(\'' + path + '\', e.detail.value)\n' + '\t}'; } - changedFn = 'if (e.detail.path) {\n' + - '\tvar path = this._fixPath(\'' + path + '\', \'' + + changedFn = + 'if (!e.path || e.path[0] == e.target) {\n' + + '\tif (e.detail.path) {\n' + + '\t\tvar path = this._fixPath(\'' + path + '\', \'' + property + '\', e.detail.path);\n' + - '\tthis.notifyPath(path, e.detail.value);\n' + - '} else {\n' + + '\t\tthis.notifyPath(path, e.detail.value);\n' + + '\t} else {\n' + changedFn + '\n' + + '\t}\n' + '}'; // model._bindListeners.push({ diff --git a/test/unit/bind-elements.html b/test/unit/bind-elements.html index fefa9bbe..00be5eab 100644 --- a/test/unit/bind-elements.html +++ b/test/unit/bind-elements.html @@ -143,3 +143,47 @@ } }); + + + + + + + + + + + + diff --git a/test/unit/bind.html b/test/unit/bind.html index a78018cb..9eb25ad3 100644 --- a/test/unit/bind.html +++ b/test/unit/bind.html @@ -593,6 +593,29 @@ suite('binding to attribute', function() { }); +suite('avoid non-bubbling event gotchas', function() { + + var el; + + beforeEach(function() { + el = document.createElement('x-notifies3'); + document.body.appendChild(el); + }); + + afterEach(function() { + document.body.removeChild(el); + }); + + test('avoid non-bubbling event gotchas', function() { + el.shouldNotChangeChanged = function(e) { + assert(false, 'parent notifies should not have changed'); + }; + el.$.notifies2.$.notifies1.notifies = 42; + }); + +}); + +