Skip to content

Instantly share code, notes, and snippets.

@alexeyraspopov

alexeyraspopov/1.js

Created May 14, 2014
Embed
What would you like to do?
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