Skip to content

Instantly share code, notes, and snippets.

@alexeyraspopov
Created May 14, 2014 07:58
Show Gist options
  • Save alexeyraspopov/c85ba7d249d29140c03d to your computer and use it in GitHub Desktop.
Save alexeyraspopov/c85ba7d249d29140c03d to your computer and use it in GitHub Desktop.
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