Skip to content

Commit

Permalink
Support dynamic functions for computed annotations.
Browse files Browse the repository at this point in the history
Alternate take for #3299
  • Loading branch information
kaste committed Feb 12, 2016
1 parent de039f8 commit 3f1bc4e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/standard/annotations.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,17 @@
for (var k=0; k<b.parts.length; k++) {
var p = b.parts[k];
if (!p.literal) {
p.signature = this._parseMethod(p.value);
if (!p.signature) {
var signature = this._parseMethod(p.value);
if (signature) {
var method = signature.method;
if (this.properties[method]) {
var args = signature.args || [];
args.push(this._parseArg(method));
signature.args = args;
signature.static = false;
}
p.signature = signature;
} else {
p.model = this._modelForPath(p.value);
}
}
Expand Down
32 changes: 32 additions & 0 deletions test/unit/bind-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -582,3 +582,35 @@
})();
</script>
</dom-module>

<dom-module id="x-bind-computed-property">
<template>
<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;
}
}
},
},

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

});
</script>
</dom-module>
30 changes: 30 additions & 0 deletions test/unit/bind.html
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,36 @@

<script>

suite('computed properties', function() {

var el;

setup(function() {

});

teardown(function() {
document.body.removeChild(el);
});

test('x', function() {
el = document.createElement('x-bind-computed-property');
document.body.appendChild(el);

assert.equal(el.$.check.textContent, 'translated: Hello World.');

el.translator = function(message) {
return 'changed: ' + message;
}

assert.equal(el.$.check.textContent, 'changed: Hello World.');
});

});

</script>

<script>
suite('2-way binding effects between elements', function() {

var el;
Expand Down

0 comments on commit 3f1bc4e

Please sign in to comment.