-
-
Save alexeyraspopov/c85ba7d249d29140c03d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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