UNPKG

todomvc

Version:

> Helping you select an MV\* framework

50 lines (41 loc) 934 B
/*global define */ define(['localstorage'], function(LocalStorage) { 'use strict'; // Basic Todo entry model var Todo = LocalStorage.extend({ storageName: 'todos-canjs' }, { init: function () { // Autosave when changing the text or completing the todo this.on('change', function (ev, prop) { if (prop === 'text' || prop === 'complete') { ev.target.save(); } }); } }); // List for Todos Todo.List = Todo.List.extend({ filter: function (check) { var list = []; this.each(function (todo) { if (check(todo)) { list.push(todo); } }); return list; }, completed: function () { return this.filter(function (todo) { return todo.attr('complete'); }); }, remaining: function () { return this.attr('length') - this.completed().length; }, allComplete: function () { return this.attr('length') === this.completed().length; } }); return Todo; });