Here's an example that uses Backbone with React.
He defines a Model
: var _todos = new Backbone.Model();
And then adds two functions to it:
var TodoStore = _.extend(_todos, {
areAllComplete: function() {
return _.every(_todos.keys(), function(id){
return _todos.get(id).complete;
});
},
getAll: function() {
return _todos.toJSON();
}
});
What I don't understand is why areAllComplete
is being applied to a Model
instead of to a Collection
.
Shouldn't this be a function in a Collection
that will get all of its models and check that complete
attribute.
Similarly, I would expect getAll
to belong to a Collection
- get all of its models.
This example seems to replace Collection
with Model
.
Maybe I don't totally understand how models are used.