mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
Avoid non-bubbling event gotchas with binding.
This commit is contained in:
@@ -23,7 +23,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
_addAnnotatedListener: function(model, index, property, path) {
|
||||
// <node>.on.<property>-changed: <path> = 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({
|
||||
|
||||
@@ -143,3 +143,47 @@
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
Polymer({
|
||||
is: 'x-notifies1',
|
||||
properties: {
|
||||
notifies: {
|
||||
notify: true
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<dom-module id="x-notifies2">
|
||||
<template>
|
||||
<x-notifies1 id="notifies1"></x-notifies1>
|
||||
</template>
|
||||
</dom-module>
|
||||
<script>
|
||||
Polymer({
|
||||
is: 'x-notifies2',
|
||||
properties: {
|
||||
notifies: {
|
||||
notify: true
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<dom-module id="x-notifies3">
|
||||
<template>
|
||||
<x-notifies2 id="notifies2" notifies="{{shouldNotChange}}"></x-notifies2>
|
||||
</template>
|
||||
</dom-module>
|
||||
<script>
|
||||
Polymer({
|
||||
is: 'x-notifies3',
|
||||
properties: {
|
||||
shouldNotChange: {
|
||||
observer: 'shouldNotChangeChanged'
|
||||
}
|
||||
},
|
||||
shouldNotChangeChanged: function() { }
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user