           (vec (for [y board-size]
             (apply dom/tr #js {:className (border-top y)}
               (vec (for [x board-size]
-                (om/build tile-view (:cells app)
+                (om/build tile-view all-units
                   {:state {:move move :x x :y y}})))))))
         (bench)))))
 


(defonce app-state (atom
                    {:cells
                      [{:type :opponent :x 0, :y 0}
                       {:type :opponent :x 2, :y 0}
                       {:type :opponent :x 4, :y 0}
                       {:type :opponent :x 6, :y 0}
                       {:type :opponent :x 8, :y 0}
                       {:type :my-team :x 0, :y 8}
                       {:type :my-team :x 2, :y 8}
                       {:type :my-team :x 4, :y 8}
                       {:type :my-team :x 6, :y 8}
                       {:type :my-team :x 8, :y 8}
                       {:type :loose-ball :x 0, :y 4}
                       {:type :loose-ball :x 2, :y 4}
                       {:type :loose-ball :x 4, :y 4}
                       {:type :loose-ball :x 6, :y 4}
                       {:type :loose-ball :x 8, :y 4}]
                    :selected-unit {}}))

(def board-size (range 0 9))
(def bench-size 4)

    (render [_]
      (dom/div #js {:className "blue-team"}))))

(defn ball-view [cursor owner]
  (reify
    om/IRender
    (render [_]
      (dom/div #js {:className "ball"}))))

(defn tile-view [cursor owner]
  (reify
    om/IRenderState
    (render-state [this {:keys [x y move] :as position}]
      (dom/td #js {:onClick #(put! move position)}
        (if-let [ball (ball? x y)]
          (om/build ball-view ball {:state {:move move}}))
        (if-let [red-player (red-unit? x y)]
          (om/build player-view red-player))
        (if-let [blue-player (blue-unit? x y)]
          (om/build opponent-view blue-player))))))

;; (defn update-unit-positions [units selected-position target-position]
;;   (vec
;;     (map
;;       (fn [unit]
;;         (if (= selected-position unit)
;;           (assoc unit apply target-position)
;;           unit))
;;       units)))

(defn board-view [app owner]
  (reify
    om/IInitState
      (init-state [_]
        {:move (chan)})

    om/IWillMount
    (will-mount [_]
      (let [move (om/get-state owner :move)]
        (go (loop []
          (let [selected-position (coords (<! move))]
            (let [target-position (coords (<! move))]
              (if (find-piece target-position)
                (println "CAN'T MOVE THERE")
                (om/transact! app [:cells :red-team]
                              (fn [xs]
                                (println xs)
                               (vec
                                 (map
                                    (fn [e]
                                      (if (= selected-position e)
                                        (assoc e :x target-position :y target-position)
                                        e))
                                  xs))))
                (recur))))))))

    om/IRenderState
    (render-state [this {:keys [move]}]
      (dom/div #js {:className "container"}
