Skip to content

Instantly share code, notes, and snippets.

@mauritslamers
Forked from dwt/gist:753040
Created December 23, 2010 15:32
Show Gist options
  • Save mauritslamers/753126 to your computer and use it in GitHub Desktop.
Save mauritslamers/753126 to your computer and use it in GitHub Desktop.
Arrayobservers = SC.Application.create({
NAMESPACE: 'Arrayobservers',
VERSION: '0.1.0',
store: SC.Store.create().from(SC.Record.fixtures)
});
Arrayobservers.objects = [SC.Object.create({foo: 1}), SC.Object.create({foo: 2})];
Arrayobservers.objectsController = SC.ArrayController.create();
Arrayobservers.contentNotifyingObjects = SC.Controller.create({
objectsBinding: SC.Binding.oneWay('Arrayobservers.objectsController.content*[]'),
// or perhaps this instead of the other one.
//objectsBinding: SC.Binding.oneWay('Arrayobservers*objectsController.[]'),
computedProperty: function() {
if(this.get('objects')){
return this.get('objects').getEach('foo').get('@sum');
};
}.property('objects')
});
Arrayobservers.valChecker = SC.Controller.create({
valBinding: 'Arrayobservers.contentNotifyingObjects.computedProperty',
valObs: function(){
console.log('val has changed: ' + this.get('val'));
}.observes('val')
});
console.log('should now see computed property output twice');
SC.RunLoop.begin();
Arrayobservers.objectsController.set('content', Arrayobservers.objects);
SC.RunLoop.end();
SC.RunLoop.begin();
Arrayobservers.objects.firstObject().set('foo', 5);
SC.RunLoop.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment