polish todo example

This commit is contained in:
Evan You 2013-08-25 03:07:48 -04:00
parent 60bd928b56
commit f29754131c
2 changed files with 7 additions and 10 deletions

View File

@ -28,7 +28,7 @@
<li
class="todo"
sd-each="todo:todos"
sd-show="todoFilter(todo.completed)"
sd-show="todoFilter(todo)"
sd-class="completed:todo.completed, editing:todo.editing"
>
<div class="view">

View File

@ -1,18 +1,17 @@
seed.config({ debug: false })
var filters = {
all: function () { return true },
active: function (val) { return !val },
completed: function (val) { return val }
// need to access todo.completed in here so Seed.js can capture dependency.
all: function (todo) { return todo.completed || true },
active: function (todo) { return !todo.completed },
completed: function (todo) { return todo.completed }
}
var Todos = seed.ViewModel.extend({
init: function () {
this.todos = todoStorage.fetch()
this.remaining = this.todos.filter(function (todo) {
return filters.active(todo.completed)
}).length
this.remaining = this.todos.filter(filters.active).length
this.updateFilter()
},
@ -64,9 +63,7 @@ var Todos = seed.ViewModel.extend({
},
removeCompleted: function () {
this.todos.mutateFilter(function (todo) {
return filters.active(todo.completed)
})
this.todos.mutateFilter(filters.active)
todoStorage.save()
},