My property sum
depends on 3 different properties (inside a model). I also have an other property that depends on sum
. isZero
and sum
have a binding in a template {{isZero}} {{sum}}
.
this is my simplified code:
sum: function () {
console.log('sum is', this.get('p1') + this.get('p2') + this.get('p3'));
return this.get('p1') + this.get('p2') + this.get('p3');
}.property('p1', 'p2', 'p3'),
p1: function () {
console.log('update p1');
return _data.p1;
}.property('data'),
p2: function () {
console.log('update p2');
return _data.p2;
}.property('data'),
p3: function () {
console.log('update p3');
return _data.p3;
}.property('data'),
data: {},
_data: {p1: 1, p2: 2, p3: 3},
isZero: function () {
console.log('sum in isZero is', this.get('sum'));
return this.get('sum') === 0;
}.property('sum'),
updateData: function () {
this._data: {p1: 0, p2: 0, p3: 0};
this.notifyPropertyChange('data');
}
Some times, when I update data, sum
and isZero
are not correctly updated. If I call updateData()
, these are the prints in console:
> update p1
> sum is 5
> sum in isZero is 5
> update p2
> update p3
> sum is 0
As you can see isZero
is not updated anymore and sum
updates twice. My template will display isZero false and sum 0. I know this code looks crazy but it is the closest I can show from my problem. I tried to reproduce in an ember jsbin, unfortunately it works correctly in there.
Anyone have any ideia why this is happening?
ps.: the updateData
call is inside an ember run loop. I'm using ember version 1.9.1.
Aucun commentaire:
Enregistrer un commentaire