 ;; Todo Item
 
 (defn handle-submit [e todo {:keys [owner comm]}]
-  (let [edit-text (om/get-state owner :edit-text)
+  (let [edit-text (dom/get-state owner :edit-text)
         val (.trim edit-text)]
     (if-not (string/blank? val)
       (go

      (>! comm [:edit todo])
      (.focus node)
      (.setSelectionRange node (.. node -value -length) (.. node -value -length))
      (om/set-state! owner :edit-text (:title todo)))))

(defn handle-key-down [e todo {:keys [owner] :as opts}]
  (let [kc (.-keyCode e)]
    (if (identical? kc ESCAPE_KEY)
      (om/set-state! owner :edit-text (:title todo))
      (if (identical? kc ENTER_KEY)
        (handle-submit e todo opts)))))

(defn handle-change [e todo owner]
  (om/set-state! owner :edit-text (.. e -target -value)))

(defn todo-item [{:keys [id title editing completed] :as todo} {:keys [comm]}]
  (reify

            (dom/button #js {:className "destroy"
                             :onClick (fn [_] (put! comm [:destroy todo]))}))
          (dom/input #js {:ref "editField" :className "edit"
                          :value (dom/get-state owner :edit-text)
                          :onBlur #(handle-submit % todo m)
                          :onChange #(handle-change % todo owner)
                          :onKeyDown #(handle-key-down % todo m)}))))))
