I'm analyzing the basic todo application.
Why is it that when I delete the StatsView
(from the main todos.js and from todos.handlebars) the remaining
method (property) of the todoListController
stops updating itself?
Todos.todoListController = SC.ArrayController.create({
...
remaining: function() {
console.log('remaining');//doesn't apear in the console
return this.filterProperty('isDone', false).get('length');
}.property('@each.isDone').cacheable(),
...
});
I can imagine, that this is because with the StatsView
I deleted the binding. But shouldn't it be, that the @each
keeps an eye on the changes?
SproutCore optimizes to do as little work as possible. So, when you deleted the StatsView, you deleted the thing that cares about the .remaining
property. Since nothing is asking for it, SproutCore doesn't compute it. This is why you should always use the get()
and set()
methods when accessing properties so that they can decide whether to use the cached version or to actually compute the property.