Skip to content

Commit

Permalink
Make sure effect functions receive latest values
Browse files Browse the repository at this point in the history
Fixes #3722
  • Loading branch information
dfreedm committed Jun 17, 2016
1 parent a54c1f2 commit 34b2c79
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/bind/accessors.html
Expand Up @@ -77,7 +77,9 @@

_effectEffects: function(property, value, effects, old, fromAbove) {
for (var i=0, l=effects.length, fx; (i<l) && (fx=effects[i]); i++) {
fx.fn.call(this, property, value, fx.effect, old, fromAbove);
// always send latest value for property
// if any previous effect has modified the value, given `value` will be stale
fx.fn.call(this, property, this[property], fx.effect, old, fromAbove);
}
},

Expand Down
28 changes: 28 additions & 0 deletions test/unit/bind-elements.html
Expand Up @@ -713,3 +713,31 @@
});
</script>
</dom-module>

<dom-module id="x-propagate">
<script>
Polymer({
is: 'x-propagate',
properties: {
value: {
type: Number,
value: -1
}
},
observers: [
'_boundOne(value)',
'_boundTwo(value)'
],
_boundOne: function(value) {
if (value < 0) {
this.value = 1;
}
},
_boundTwo: function(value) {
if (value < 0) {
this.value = 2;
}
}
});
</script>
</dom-module>
8 changes: 8 additions & 0 deletions test/unit/bind.html
Expand Up @@ -1023,6 +1023,14 @@
});
});

suite('value propagation', function() {
test('effects forward propagate value', function() {
var el = document.createElement('x-propagate');
document.body.appendChild(el);
assert.equal(el.value, 1, 'observers did not receive latest value for property');
});
});

</script>

</body>
Expand Down

0 comments on commit 34b2c79

Please sign in to comment.