PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/backbone/js/collections/todos.js

https://gitlab.com/x33n/todomvc
JavaScript | 41 lines | 19 code | 9 blank | 13 comment | 1 complexity | 69e185f6f511a7ec13a980c1f671fbdf MD5 | raw file
  1. /*global Backbone */
  2. var app = app || {};
  3. (function () {
  4. 'use strict';
  5. // Todo Collection
  6. // ---------------
  7. // The collection of todos is backed by *localStorage* instead of a remote
  8. // server.
  9. var Todos = Backbone.Collection.extend({
  10. // Reference to this collection's model.
  11. model: app.Todo,
  12. // Save all of the todo items under the `"todos"` namespace.
  13. localStorage: new Backbone.LocalStorage('todos-backbone'),
  14. // Filter down the list of all todo items that are finished.
  15. completed: function () {
  16. return this.where({completed: true});
  17. },
  18. // Filter down the list to only todo items that are still not finished.
  19. remaining: function () {
  20. return this.where({completed: false});
  21. },
  22. // We keep the Todos in sequential order, despite being saved by unordered
  23. // GUID in the database. This generates the next order number for new items.
  24. nextOrder: function () {
  25. return this.length ? this.last().get('order') + 1 : 1;
  26. },
  27. // Todos are sorted by their original insertion order.
  28. comparator: 'order'
  29. });
  30. // Create our global collection of **Todos**.
  31. app.todos = new Todos();
  32. })();