<commit_before>(ns schafkopfen.core
  (:require-macros [cljs.core.async.macros :refer [go-loop]])
  (:require [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]
            [cljs.core.async :refer [put! chan <!]]))

(enable-console-print!)

(defonce app-state (atom {:header "Schafkopfen at BarCamp"
                          :players [{:name "Player 1"}
                                    {:name "Player 2"}
                                    {:name "Player 3"}
                                    {:name "Player 4"}]}))

(defn player-view [player owner]
  (reify
    om/IRenderState
    (render-state [this {:keys [delete]}]
      (dom/li nil
              (:name player)
              (dom/button #js {:type "button"
                               :onClick (fn [e] (put! delete player))
                               :style #js {:marginLeft "10px"}
                               :className "btn btn-danger btn-xs"}
                          "delete")))))


(defn players-view [data owner]
  (reify
    om/IInitState
    (init-state [_]
      {:delete (chan)})
    om/IWillMount
    (will-mount [_]
      (let [delete (om/get-state owner :delete)]
        (go-loop []
          (let [player (<! delete)]
            (om/transact! data :players
                          (fn [xs] (vec (remove #(= player %) xs))))
            (recur)))))
    om/IRenderState
    (render-state [this {:keys [delete]}]
      (let [on-name-submit (fn [e]
                             (let [input (om/get-node owner "new-player-name")
                                   name (-> input .-value)]
                               (when name
                                 (om/transact! data :players #(conj % {:name name}))
                                 (set! (.-value input) "")))
                             false)]
        (dom/div nil
                 (dom/h2 nil "Players")
                 (apply dom/ul nil
                        (om/build-all player-view (:players data) {:init-state {:delete delete}}))
                 (dom/form #js {:onSubmit on-name-submit}
                           (dom/input #js {:type :text :placeholder "Name" :ref "new-player-name"})
                           (dom/button
                            #js {:onClick on-name-submit}<commit_msg>add name checking and warning field<commit_after>(ns schafkopfen.core
  (:require-macros [cljs.core.async.macros :refer [go-loop]])
  (:require [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]
            [cljs.core.async :refer [put! chan <!]]))

(enable-console-print!)

(defonce app-state (atom {:header "Schafkopfen at BarCamp"
                          :players [{:name "Player 1"}
                                    {:name "Player 2"}
                                    {:name "Player 3"}
                                    {:name "Player 4"}]}))

(defn player-view [player owner]
  (reify
    om/IRenderState
    (render-state [this {:keys [delete]}]
      (dom/li nil
              (:name player)
              (dom/button #js {:type "button"
                               :onClick (fn [e] (put! delete player))
                               :style #js {:marginLeft "10px"}
                               :className "btn btn-danger btn-xs"}
                          "delete")))))


(defn players-view [data owner]
  (reify
    om/IInitState
    (init-state [_]
      {:delete (chan)
       :warning nil})
    om/IWillMount
    (will-mount [_]
      (let [delete (om/get-state owner :delete)]
        (go-loop []
          (let [player (<! delete)]
            (om/transact! data :players
                          (fn [xs] (vec (remove #(= player %) xs))))
            (recur)))))
    om/IRenderState
    (render-state [this {:keys [delete warning]}]
      (let [on-name-submit
            (fn [e]
              (let [input (om/get-node owner "new-player-name")
                    name (-> input .-value)]
                (cond
                  (or (not name) (= "" name)) (om/set-state! owner :warning "Invalid name!")
                  (some #(= name (:name %)) (:players data)) (om/set-state! owner :warning "Duplicate user!")
                  :default (do
                             (om/transact! data :players #(conj % {:name name}))
                             (set! (.-value input) "")
                             (om/set-state! owner :warning nil))))
              false)]
        (dom/div nil
                 (dom/h2 nil "Players")
                 (apply dom/ul nil
                        (om/build-all player-view (:players data) {:init-state {:delete delete}}))
                 (when-not (nil? warning) (dom/div #js {:className "alert alert-danger" :role "alert"} warning))
                 (dom/form #js {:onSubmit on-name-submit}
                           (dom/input #js {:type :text :placeholder "Name" :ref "new-player-name"})
                           (dom/button
                            #js {:onClick on-name-submit}
{'fraction_non_alphanumeric': 0.14085914085914086, 'fraction_numerical': 0.002797202797202797, 'mean_word_length': 1.3047882136279927, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '946845', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1406, 'n_words': 372}