ember.js - Ember property doesn't update properly with multiple dependencies -
my property sum
depends on 3 different properties (inside model). have other property depends on sum
. iszero
, sum
have binding in template {{iszero}} {{sum}}
.
this 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 update data, sum
, iszero
not correctly updated. if call updatedata()
, these prints in console:
> update p1 > sum 5 > sum in iszero 5 > update p2 > update p3 > sum 0
as can see iszero
not updated anymore , sum
updates twice. template display iszero false , sum 0. know code looks crazy closest can show problem. tried reproduce in ember jsbin, unfortunately works correctly in there.
anyone have ideia why happening?
ps.: updatedata
call inside ember run loop. i'm using ember version 1.9.1.
Comments
Post a Comment