When binding property of a parent to property of a child, parent's property value is used.
However, if parent's property does not have default value, or default value is explicitly set to undefined, child's property value is used instead.
Personally, I find this unintuitive and it breaks applications that deal with undefined values. For example, a value that is supposed to be undefined can suddenly become null, false, empty string or whatever is the default value of the element you bind it to.
This also applies to sibling elements. It appears that priority of values in binding corresponds to the order of elements in DOM, except if the value is undefined.
Below is a code that illustrated the problem:
<dom-module id="child-el">
<template>{{value}}</template>
</dom-module>
<script>
Polymer({
is: 'child-el',
properties: {
value: {
value: false,
notify: true,
observer: '_valueChanged'
}
},
_valueChanged: function() {
console.log('child-el value changed:', this.value);
}
});
</script>
<dom-module id="parent-el">
<template><child-el value="{{value}}"></child-el></template>
</dom-module>
<script>
Polymer({
is: 'parent-el',
properties: {
value: {
value: undefined,
notify: true,
observer: '_valueChanged'
}
},
_valueChanged: function() {
console.log('parent-el value changed:', this.value);
}
});
</script>
If you add parent-el to the DOM you will notice that its value is set to false while it should be undefined.
When binding property of a parent to property of a child, parent's property value is used.
However, if parent's property does not have default value, or default value is explicitly set to undefined, child's property value is used instead.
Personally, I find this unintuitive and it breaks applications that deal with undefined values. For example, a value that is supposed to be undefined can suddenly become null, false, empty string or whatever is the default value of the element you bind it to.
This also applies to sibling elements. It appears that priority of values in binding corresponds to the order of elements in DOM, except if the value is undefined.
Below is a code that illustrated the problem:
If you add parent-el to the DOM you will notice that its value is set to false while it should be undefined.