From 8d6a907cfc5d57194ffecbbf17237433353f99a6 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Thu, 3 May 2012 09:35:48 -0400 Subject: [PATCH] Some *.completed refactoring --- src/app/index.coffee | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/app/index.coffee b/src/app/index.coffee index 25c4d2646f..231a3af6a4 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -74,22 +74,13 @@ ready (model) -> # or the item's id property list.pass(ignore: domId).move {id}, to - - list.on 'set', '*.completed', (i, completed, previous, isLocal) -> - # Move the item to the bottom if it was checked off - list.move i, -1 if completed && isLocal - exports.addHabit = -> newHabit = model.at "_newHabit" list = model.at "_habitList" # Don't add a blank todo return unless text = view.escapeHtml newHabit.get() newHabit.set '' - # Insert the new todo before the first completed item in the list - # or append to the end if none are completed - for todo, i in list.get() - break if todo.completed - list.insert i, {text} + list.push {text} exports.addDaily = -> newDaily = model.at "_newDaily" @@ -103,6 +94,10 @@ ready (model) -> break if todo.completed list.insert i, {text} + list.on 'set', '*.completed', (i, completed, previous, isLocal) -> + # Move the item to the bottom if it was checked off + list.move i, -1 if completed && isLocal + exports.addTodo = -> newTodo = model.at "_newTodo" list = model.at "_todoList" @@ -115,17 +110,17 @@ ready (model) -> break if todo.completed list.insert i, {text} + list.on 'set', '*.completed', (i, completed, previous, isLocal) -> + # Move the item to the bottom if it was checked off + list.move i, -1 if completed && isLocal + exports.addReward = -> newReward = model.at "_newReward" list = model.at "_rewardList" # Don't add a blank todo return unless text = view.escapeHtml newReward.get() newReward.set '' - # Insert the new todo before the first completed item in the list - # or append to the end if none are completed - for todo, i in list.get() - break if todo.completed - list.insert i, {text} + list.push {text} exports.del = (e) -> # Derby extends model.at to support creation from DOM nodes