-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathapp.js
71 lines (53 loc) · 1.42 KB
/
app.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
new Vue({
el: '#tasks',
data: {
tasks: [],
newTask: '',
filters: {
inProcess: function(task) {
return ! task.completed;
},
completed: function(task) {
return task.completed;
}
}
},
computed: {
completions: function() {
return this.tasks.filter(this.filters.completed);
},
remaining: function() {
return this.tasks.filter(this.filters.inProcess);
}
},
methods: {
addTask: function(e) {
e.preventDefault();
if ( ! this.newTask) return;
this.tasks.push({
body: this.newTask,
completed: false
});
this.newTask = '';
},
editTask: function(task) {
this.removeTask(task);
this.newTask = task.body;
this.$$.newTask.focus();
},
toggleTaskCompletion: function(task) {
task.completed = ! task.completed;
},
completeAll: function() {
this.tasks.forEach(function(task) {
task.completed = true;
});
},
clearCompleted: function() {
this.tasks = this.tasks.filter(this.filters.inProcess);
},
removeTask: function(task) {
this.tasks.$remove(task);
}
}
});