| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- var Seed = require('seed')
- var todos = [
- { text: 'make nesting controllers work', done: true },
- { text: 'complete ArrayWatcher', done: true },
- { text: 'computed properties', done: true },
- { text: 'parse textnodes', done: false }
- ]
- Seed.controller('Todos', function (scope) {
- // regular properties -----------------------------------------------------
- scope.todos = todos
- scope.filter = window.location.hash.slice(2) || 'all'
- scope.remaining = todos.reduce(function (count, todo) {
- return count + (todo.done ? 0 : 1)
- }, 0)
- scope.allDone = scope.remaining === 0
- // computed properties ----------------------------------------------------
- scope.total = {get: function () {
- return scope.todos.length
- }}
- scope.completed = {get: function () {
- return scope.total - scope.remaining
- }}
- scope.itemLabel = {get: function () {
- return scope.remaining > 1 ? 'items' : 'item'
- }}
- // event handlers ---------------------------------------------------------
- scope.addTodo = function (e) {
- var val = e.el.value
- if (val) {
- e.el.value = ''
- scope.todos.unshift({ text: val, done: false })
- }
- scope.remaining++
- }
- scope.removeTodo = function (e) {
- scope.todos.remove(e.scope)
- scope.remaining -= e.scope.done ? 0 : 1
- }
- scope.updateCount = function (e) {
- scope.remaining += e.scope.done ? -1 : 1
- scope.allDone = scope.remaining === 0
- }
- scope.edit = function (e) {
- e.scope.editing = true
- }
- scope.stopEdit = function (e) {
- e.scope.editing = false
- }
- scope.setFilter = function (e) {
- scope.filter = e.el.dataset.filter
- }
- scope.toggleAll = function (e) {
- scope.todos.forEach(function (todo) {
- todo.done = e.el.checked
- })
- scope.remaining = e.el.checked ? 0 : scope.total
- }
- scope.removeCompleted = function () {
- scope.todos = scope.todos.filter(function (todo) {
- return !todo.done
- })
- }
- })
- var s = Date.now()
- Seed.bootstrap()
- console.log(Date.now() - s)
|