Skip to content

Commit 34b2c79

Browse files
committed
Make sure effect functions receive latest values
Fixes #3722
1 parent a54c1f2 commit 34b2c79

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎src/lib/bind/accessors.html‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@
7777

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

‎test/unit/bind-elements.html‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,3 +713,31 @@
713713
});
714714
</script>
715715
</dom-module>
716+
717+
<dom-module id="x-propagate">
718+
<script>
719+
Polymer({
720+
is: 'x-propagate',
721+
properties: {
722+
value: {
723+
type: Number,
724+
value: -1
725+
}
726+
},
727+
observers: [
728+
'_boundOne(value)',
729+
'_boundTwo(value)'
730+
],
731+
_boundOne: function(value) {
732+
if (value < 0) {
733+
this.value = 1;
734+
}
735+
},
736+
_boundTwo: function(value) {
737+
if (value < 0) {
738+
this.value = 2;
739+
}
740+
}
741+
});
742+
</script>
743+
</dom-module>

‎test/unit/bind.html‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,14 @@
10231023
});
10241024
});
10251025

1026+
suite('value propagation', function() {
1027+
test('effects forward propagate value', function() {
1028+
var el = document.createElement('x-propagate');
1029+
document.body.appendChild(el);
1030+
assert.equal(el.value, 1, 'observers did not receive latest value for property');
1031+
});
1032+
});
1033+
10261034
</script>
10271035

10281036
</body>

0 commit comments

Comments
 (0)