   (:require-macros [cljs.core.async.macros :refer [go]])
   (:require [om.core :as om :include-macros true]
             [om.dom :as dom :include-macros true]
-            [cljs.core.async :refer [put! chan <!]]))
+            [cljs.core.async :refer [put! chan <!]]
+            [clojure.string :as string]))
 
 (enable-console-print!)
 

                                (vec (remove #(= contact %) xs))))
                (recur))))))
    om/IRenderState
    (render-state [this {:keys [delete]}]
      (dom/div nil
               (dom/h2 nil "Contact List")
               (apply dom/ul nil
                      (om/build-all contact-view (:contacts data)
                                    {:init-state {:delete delete}}))))))

(om/root contacts-view app-state
         {:target (. js/document (getElementById "contacts"))})

          {:first "Louis" :last "Reasoner" :email "prolog@mit.edu"}
          {:first "Cy" :middle-initial "D" :last "Effect" :email "bug@mit.edu"}
          {:first "Lem" :middle-initial "E" :last "Tweakit" :email "morebug@mit.edu"}]}))

(defn parse-contact [contact-str]
  (let [[first middle last :as parts] (string/split contact-str #"\s+")
        [first last middle] (if (nil? last) 
                              [first middle] 
                              [first last middle])
        middle (when middle (string/replace middle "." ""))
        c (if middle (count middle) 0)]
    (when (>= (count parts 2))
      (cond-> {:first first :last last}
              (= c 1) (assoc :middle-initial middle)
              (>= c 2) (assoc :middle middle)))))

(defn add-contact [data owner]
  (let [new-contact (-> (om/get-node owner "new-contact")
                        .-value
                        parse-contact)]
    (when new-contact
      (om/transact! data :contacts #(conj % new-contact)))))

(defn middle-name [{:keys [middle middle-initial]}]
  (cond
