<commit_before>(ns todomvc.item
  (:require [cljs.core.async :refer [>! put! timeout]]
            [todomvc.utils :refer [now hidden]]
            [clojure.string :as string]
            [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]))

(def ESCAPE_KEY 27)
(def ENTER_KEY 13)

;; =============================================================================
;; Todo Item

;; -----------------------------------------------------------------------------
;; Event Handlers

(defn submit [e todo owner comm]
  (when-let [edit-text (om/get-state owner :edit-text)]
    (if-not (string/blank? (.trim edit-text))
      (do
        (om/update! todo assoc :title edit-text)
        (put! comm [:save todo]))
      (put! comm [:destroy todo])))
  false)

(defn edit [e todo owner comm]
  (let [node (om/get-node owner "editField")]
    (put! comm [:edit todo])
    (doto owner
      (om/set-state! :needs-focus true)
      (om/set-state! :edit-text (:title todo)))))

(defn key-down [e todo owner comm]
  (condp == (.-keyCode e)
    ESCAPE_KEY (do
                 (om/set-state! owner :edit-text (:title todo))
                 (put! comm [:cancel todo]))
    ENTER_KEY  (submit e todo owner comm)
    nil))

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

;; -----------------------------------------------------------------------------
;; Todo Item

(defn todo-item [todo owner {:keys [comm]}]
  (reify
    om/IInitState
    (init-state [_]
      {:edit-text (:title todo)})
    om/IDidUpdate
    (did-update [_ _ _ _]
      (when (and (:editing todo)
                 (om/get-state owner :needs-focus))
        (let [node (om/get-node owner "editField")]
          (.focus node)
          (.setSelectionRange node (.. node -value -length) (.. node -value -length)))
        (om/set-state! owner :needs-focus nil)))
    om/IRender
    (render [_]
      (let [class (cond-> ""
                    (:completed todo) (str "completed")
                    (:editing todo)   (str "editing"))]
        (dom/li #js {:className class :style (hidden (:hidden todo))}
          (dom/div #js {:className "view"}
            (dom/input
              #js {:className "toggle" :type "checkbox"
                   :checked (and (:completed todo) "checked")<commit_msg>tweak<commit_after>(ns todomvc.item
  (:require [cljs.core.async :refer [>! put! timeout]]
            [todomvc.utils :refer [now hidden]]
            [clojure.string :as string]
            [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]))

(def ESCAPE_KEY 27)
(def ENTER_KEY 13)

;; =============================================================================
;; Todo Item

;; -----------------------------------------------------------------------------
;; Event Handlers

(defn submit [e todo owner comm]
  (when-let [edit-text (om/get-state owner :edit-text)]
    (if-not (string/blank? (.trim edit-text))
      (do
        (om/update! todo assoc :title edit-text)
        (put! comm [:save todo]))
      (put! comm [:destroy todo])))
  false)

(defn edit [e todo owner comm]
  (let [node (om/get-node owner "editField")]
    (put! comm [:edit todo])
    (doto owner
      (om/set-state! :needs-focus true)
      (om/set-state! :edit-text (:title todo)))))

(defn key-down [e todo owner comm]
  (condp == (.-keyCode e)
    ESCAPE_KEY (do
                 (om/set-state! owner :edit-text (:title todo))
                 (put! comm [:cancel todo]))
    ENTER_KEY  (submit e todo owner comm)
    nil))

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

;; -----------------------------------------------------------------------------
;; Todo Item

(defn todo-item [todo owner {:keys [comm]}]
  (reify
    om/IInitState
    (init-state [_]
      {:edit-text (:title todo)})
    om/IDidUpdate
    (did-update [_ _ _ _]
      (when (and (:editing todo)
                 (om/get-state owner :needs-focus))
        (let [node (om/get-node owner "editField")
              len  (.. node -value -length)]
          (.focus node)
          (.setSelectionRange node len len))
        (om/set-state! owner :needs-focus nil)))
    om/IRender
    (render [_]
      (let [class (cond-> ""
                    (:completed todo) (str "completed")
                    (:editing todo)   (str "editing"))]
        (dom/li #js {:className class :style (hidden (:hidden todo))}
          (dom/div #js {:className "view"}
            (dom/input
              #js {:className "toggle" :type "checkbox"
                   :checked (and (:completed todo) "checked")
{'fraction_non_alphanumeric': 0.24225473321858865, 'fraction_numerical': 0.0017211703958691911, 'mean_word_length': 1.822707953855495, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3865662', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1400, 'n_words': 407}