Question

I have an Ember.Object that I'm updating with a property like below, but if I change primaryDemo twice in a row, it doesn't fire, yet if I change primaryDemo, then Rate, it does change. I'm puzzled as to why this is and how I can fix it.

dependantChanged: function() {
    console.log('Firing change');
    this.get('_update')(this);
}.observes('primaryDemo', 'Rate', 'Totals'),

UPDATE: So the first answer and fiddle got me thinking as to what the problem was, and it's due to changing a property on an object and not the object itself. I think ember does a hash check to see if there is a difference. In my case I'm already using underscorejs, so I just change the property, then use _.clone(demo) before doing the set. I'd rather not do that, so will wait to see if there is a more elegant solution before closing this.

Was it helpful?

Solution

You don't need to set primaryDemo again. In the example that does nothing. You need to force tell Ember to notify your observer. See this fiddle...

var demo = { Imps: 1, Demo: { Id: 2 } }

var obj = Ember.Object.create({
    dependantChanged: function() {
        console.log('Firing change');
    }.observes('primaryDemo', 'Rate', 'Totals'),
});

obj.set('primaryDemo', demo);
demo.Imps = 2;
obj.set('primaryDemo', demo);

// Notify observers on obj#primaryDemo
Ember.notifyObservers(obj, 'primaryDemo');

OTHER TIPS

Can you give more details? I created a simple JSFiddle http://jsfiddle.net/JjbXb/ from your description but changing the same property in a row, as you say, works.

Are you sure the value of primaryDemo is different in your 2 consecutive calls?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top