emberjs/ember.js — Issue #541: Cannot observe changes to nested properties on array using @each 
Author: robharper
Created: 2012-02-27 15:14:35+00:00
State: open

Adding an observer on a nested property of objects within a collection does not reliably fire. I've created a test case that could be added to ```ember-runtime/tests/mixins/array_test.js``` that illustrates this. Observing a nested property on the EachProxy itself appears to work fine. However, observing the property using ```@each.nest.isDone``` does not.

In the following test, ```count1``` is incremented to 1, ```count2``` is not:

```javascript
test('modifying nested contents of an object in an array should call @each observers', function() {
var ary = new TestArray([
Em.Object.create({ nest: Em.Object.create({ isDone: false}) }),
Em.Object.create({ nest: Em.Object.create({ isDone: false}) }),
Em.Object.create({ nest: Em.Object.create({ isDone: false}) }),
Em.Object.create({ nest: Em.Object.create({ isDone: false}) })
]);

var get = Ember.get, set = Ember.set;
var count1 = 0, count2 = 0;

// Works
var each = get(ary, '@each');
Ember.addObserver(each, 'nest.isDone', function() { count1++; });

// Doesn't work
Ember.addObserver(ary, '@each.nest.isDone', function() { count2++; });

count1 = count2 = 0;
var item = ary.objectAt(2);
get(item, 'nest').set('isDone', true);

equal(count1, 1, '@each.nest.isDone should have notified - observing @each array');
equal(count2, 1, '@each.nest.isDone should have notified - observing chain containing @each');
});
```