function TodoVM(model){ | |
this.title = observable(model.title); | |
this.completed = observable(model.observable) | |
} | |
filters = { | |
all: () => true, | |
active: (todo) => !todo.completed(), | |
completed: (todo) => todo.completed() | |
}; | |
function TodosVM(todos){ | |
todos = todos.map((model) => new TodoVM(model))); | |
this.todos = observableArray(todos); | |
this.todos.bind(JSON.stringify) | |
.subscribe(apply(localStorage, 'todos')); | |
this.status = computed(function(params){ | |
return maybe(params.status).orElse('all').value().toLowerCase(); | |
}, routeStream('/:status?')); | |
this.filtered = computed(function(todos, status){ | |
return todos.filter(filters[status]); | |
}, this.todos, this.status); | |
} |
function TodoVM(model){ | |
this.title = observable(model.title); | |
this.completed = observable(model.observable) | |
} | |
filters = { | |
all: () => true, | |
active: (todo) => !todo.completed(), | |
completed: (todo) => todo.completed() | |
}; | |
function TodosVM(todos){ | |
todos = todos.map((model) => new TodoVM(model))); | |
this.todos = observableArray(todos); | |
this.todos.bind(JSON.stringify) | |
.subscribe(apply(localStorage, 'todos')); | |
this.status = routeStream('/:status?') | |
.bind(pluck('status')) | |
.bind((status) => maybe(status).orElse('all').value().toLowerCase()); | |
this.filtered = merge(this.todos, this.status) | |
.bind(function(todos, status){ | |
return todos.filter(filters[status]); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment