forked from tastejs/todomvc
/
todo_collection.js
53 lines (40 loc) · 1.66 KB
/
todo_collection.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Generated by CoffeeScript 1.3.1
(function() {
var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
window.TodoCollection = (function(_super) {
__extends(TodoCollection, _super);
TodoCollection.name = 'TodoCollection';
function TodoCollection() {
return TodoCollection.__super__.constructor.apply(this, arguments);
}
TodoCollection.prototype.localStorage = new Store('todos-knockback');
TodoCollection.prototype.model = Todo;
TodoCollection.prototype.completedCount = function() {
return this.models.reduce((function(prev, cur) {
return prev + (cur.completed() ? 1 : 0);
}), 0);
};
TodoCollection.prototype.remainingCount = function() {
return this.models.length - this.completedCount();
};
TodoCollection.prototype.completeAll = function(completed) {
return this.each(function(todo) {
return todo.completed(completed);
});
};
TodoCollection.prototype.destroyCompleted = function() {
var completed_tasks, model, _i, _len, _results;
completed_tasks = this.filter(function(todo) {
return todo.completed();
});
_results = [];
for (_i = 0, _len = completed_tasks.length; _i < _len; _i++) {
model = completed_tasks[_i];
_results.push(model.destroy());
}
return _results;
};
return TodoCollection;
})(Backbone.Collection);
}).call(this);