   ;; optionally touch your app-state to force rerendering depending on
   ;; your application
   ;; (swap! app-state update-in [:__figwheel_counter] inc)
-)
+  )

(ns om-tut.core
  (:require [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]))

(enable-console-print!)


  (str last ", " first (middle-name contact)))

(defn contact-view [contact owner]
  (reify om/IRenderState
    (render-state [this {:keys [delete]}]
      (dom/li nil 
              (dom/span nil (display-name contact))
              (dom/button #js {:onClick (fn [e] (put! delete @contact))} "Delete")))))

(defn contacts-view [data owner]
  (reify
    om/IInitState 
    (init-state [_] {:delete (chan)})
    om/IWillMount
    (will-mount [_]
      (let [delete (om/get-state owner :delete)]
        (go (loop []
              (let [contact (<! delete)]
                (om/transact! data :contacts
                              (fn [xs]
                                (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"))})
