Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
SC 2.0a To-Do's coffee-script
Todos = SC.Application.create()
Todos.Todo = SC.Object.extend
title: null
isDone: false
Todos.todosController = SC.ArrayProxy.create
content: []
createTodo: (title) ->
@pushObject Todos.Todo.create title: title
clearCompletedTodos: ->
@filterProperty('isDone', true).forEach @removeObject, this
remaining: (->
@filterProperty('isDone', false).get 'length'
).property '@each.isDone'
allAreDone: ((key, value) ->
if value?
@setEach 'isDone', value
!!@get('length') and @everyProperty 'isDone', true
).property '@each.isDone'
Todos.StatsView = SC.View.extend
remainingBinding: 'Todos.todosController.remaining'
remainingString: (->
"#{remaining} item" + if @get('remaining') is 1 then '' else 's'
).property 'remaining'
Todos.CreateTodoView = SC.TextField.extend
insertNewline: ->
value = @get 'value'
if value?
Todos.todosController.createTodo value
@set 'value', ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment