Skip to content

Commit

Permalink
Add support for properties defined in a behavior.
Browse files Browse the repository at this point in the history
For correctness this is implemented using `getPropertyInfo()` though
this is not optimized at all. Note that `_propertyInfo` is not ready
when we parse the annotations (which is the earliest call to
`_parseMethod` right now). There are several options to make this right,
but these are not part of this feature PR.
  • Loading branch information
kaste committed Feb 12, 2016
1 parent f4486a2 commit b6abf26
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/standard/effectBuilder.html
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@
var m = expression.match(/([^\s]+?)\(([\s\S]*)\)/);
if (m) {
var sig = { method: m[1], static: true };
if (this.properties[sig.method]) {
// TODO(kaste): Optimize/memoize `getPropertyInfo`.
if (this.getPropertyInfo(sig.method) !== Polymer.nob) {
sig.static = false;
sig.dynamicFn = true;
}
Expand Down
49 changes: 28 additions & 21 deletions test/unit/bind-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -588,29 +588,36 @@
<div id="check">[[translate('Hello World.')]]</div>
</template>
<script>
Polymer({
is: 'x-bind-computed-property',
properties: {
translate: {
type: Function,
computed: '_computeTranslateFn(translator)'
},
translator: {
type: Function,
value: function() {
return function(message) {
return 'translated: ' + message;
}
(function(){
var TranslateBehavior = {
properties: {
translate: {
type: Function,
computed: '_computeTranslateFn(translator)'
}
}
};
Polymer({
is: 'x-bind-computed-property',
behaviors: [TranslateBehavior],
properties: {
translator: {
type: Function,
value: function() {
return function(message) {
return 'translated: ' + message;
}
}
},
},
},

_computeTranslateFn: function(translator) {
return function(message) {
return translator(message);
}
},
_computeTranslateFn: function(translator) {
return function(message) {
return translator(message);
}
},

});
});
})();
</script>
</dom-module>
</dom-module>

0 comments on commit b6abf26

Please sign in to comment.