Skip to content

Instantly share code, notes, and snippets.

@jashkenas
Forked from steeleforge/gist:993924
Created May 26, 2011 20:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jashkenas/994057 to your computer and use it in GitHub Desktop.
Save jashkenas/994057 to your computer and use it in GitHub Desktop.
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
value
else
!!@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