app.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. var Seed = require('seed')
  2. var todos = [
  3. { text: 'make nesting controllers work', done: true },
  4. { text: 'complete ArrayWatcher', done: true },
  5. { text: 'computed properties', done: true },
  6. { text: 'parse textnodes', done: false }
  7. ]
  8. Seed.controller('Todos', function (scope) {
  9. // regular properties -----------------------------------------------------
  10. scope.todos = todos
  11. scope.filter = window.location.hash.slice(2) || 'all'
  12. scope.remaining = todos.reduce(function (count, todo) {
  13. return count + (todo.done ? 0 : 1)
  14. }, 0)
  15. scope.allDone = scope.remaining === 0
  16. // computed properties ----------------------------------------------------
  17. scope.total = {get: function () {
  18. return scope.todos.length
  19. }}
  20. scope.completed = {get: function () {
  21. return scope.total - scope.remaining
  22. }}
  23. scope.itemLabel = {get: function () {
  24. return scope.remaining > 1 ? 'items' : 'item'
  25. }}
  26. // event handlers ---------------------------------------------------------
  27. scope.addTodo = function (e) {
  28. var val = e.el.value
  29. if (val) {
  30. e.el.value = ''
  31. scope.todos.unshift({ text: val, done: false })
  32. }
  33. scope.remaining++
  34. }
  35. scope.removeTodo = function (e) {
  36. scope.todos.remove(e.scope)
  37. scope.remaining -= e.scope.done ? 0 : 1
  38. }
  39. scope.updateCount = function (e) {
  40. scope.remaining += e.scope.done ? -1 : 1
  41. scope.allDone = scope.remaining === 0
  42. }
  43. scope.edit = function (e) {
  44. e.scope.editing = true
  45. }
  46. scope.stopEdit = function (e) {
  47. e.scope.editing = false
  48. }
  49. scope.setFilter = function (e) {
  50. scope.filter = e.el.dataset.filter
  51. }
  52. scope.toggleAll = function (e) {
  53. scope.todos.forEach(function (todo) {
  54. todo.done = e.el.checked
  55. })
  56. scope.remaining = e.el.checked ? 0 : scope.total
  57. }
  58. scope.removeCompleted = function () {
  59. scope.todos = scope.todos.filter(function (todo) {
  60. return !todo.done
  61. })
  62. }
  63. })
  64. var s = Date.now()
  65. Seed.bootstrap()
  66. console.log(Date.now() - s)