sproutcore/sproutcore — Issue #644: `replace` on Array calls notifyProperty('[]') *twice*
Author: tim-evans
Created: 2011-12-13 16:40:24+00:00
State: open

If you run the following code in your console you should see:

contentDidChange 1
contentDidChange 1
contentDidChange 2
contentDidChange 2

Here's the code to run:

var App = window.App = {};

App.array = SC.ArrayController.create({
content: []
});

App.obj = SC.ObjectController.create({
contentBinding: 'App.array.lastObject',
contentDidChange: function() {
console.log('contentDidChange', this.get('content'));
}.observes('content')
});

SC.run(function() {
App.array.pushObject(1); // Triggers contentDidChange + recomputes property.
});

SC.run(function() {
App.array.pushObject(2); // Does neither.
});

What's happening is that `replace` calls `arrayContentDidChange` which calls `notifyPropertyChange('[]')`, then it calls `enumerableContentDidChange` which calls `notifyPropertyChange('[]')` yet again. This should get addressed ASAP, because it negatively impacts performance in a big way.