 (defn complete-all [todos v] (swap! todos mod-map map #(assoc-in % [1 :done] v)))
 (defn clear-done [todos] (swap! todos mod-map remove #(get-in % [1 :done])))
 
-(defn todo-main [props]
+(defn todo-app [props]
   (let [todos (or (:todos props)
                   (let [t (atom (sorted-map))]
                     (dotimes [x 5]
                       (add-todo t (str "Some todo " x)))
                     t))
-        filt (atom :all)
-        editing (atom nil)]
+        filt (atom :all)]
     (fn []
       (let [items (vals @todos)
             done (->> items (filter :done) count)

                 (if-not (empty? v) (on-save v))
                 (stop)))]
    (fn [props]
      (let [p {:type "text" :value @val :on-blur save
               :on-change #(reset! val (-> % .-target .-value))
               :on-key-up #(case (.-which %)
                             13 (save)
                             27 (stop)
                             nil)}]
        [:input (cloact/merge-props props p)]))))

(def todo-input (with-meta todo-input-render
                  {:component-did-mount #(.focus (:dom-node %))}))

(defn todo-item [{:keys [todo editing is-editing
                         on-toggle on-save on-destroy]}]
  (dbg "rendering item")
  (let [{:keys [id done title]} todo]
    [:li {:class (str (if done "completed ") (if is-editing "editing"))}
     [:div.view
      [:input.toggle {:type "checkbox" :checked done :on-change on-toggle}]
      [:label {:on-double-click #(reset! editing id)} title]
      [:button.destroy {:on-click on-destroy}]]
     (when is-editing
       [todo-input {:class "edit" :title title :on-save on-save
                    :on-stop #(reset! editing nil)}])]))

(defn todo-stats [{:keys [filter clear]}]
  (let [props-for (fn [name]

         [:footer#info
          [:p "Double-click to edit a todo"]]]))))

(defn ^:export run []
  (cloact/render-component [todo-app] (.-body js/document)))
