   (fn [num]
     (let [local-max (if (<= num maximum) num maximum)]
       (if (<= minimum local-max) local-max minimum))))
+
+(defn circle-dragged
+  "Event handler for circle drags"
+  [[newX newY]]
+  (swap! app-db assoc :x newX :y newY))
 
 (def draggable-circle-component
   (with-meta circle-component

             canvas (-> node .-parentNode)
             x-constraint (->> canvas .-clientWidth (make-constraint 0))
             y-constraint (->> canvas .-clientHeight (make-constraint 0))]
         
         (goog.events/listen
          node
          goog.events.EventType/MOUSEDOWN
          (fn [e]
            (let [drag (fx/Dragger. node)]
              
              ;; Drag event handler
              (.addEventListener
               drag
               goog.fx.Dragger.EventType/DRAG
               (fn [b]
                 (let [dx (-> b .-dragger .-deltaX)
                       dy (-> b .-dragger .-deltaY)
                       x (x-constraint
                          (+ dx (:x @app-db)))
                       y (y-constraint
                          (+ dy (:y @app-db)))]
                   (swap! app-db assoc :x x :y y))))

              ;; Drag end
              (.addEventListener drag goog.fx.Dragger.EventType/END #(.dispose drag))

              ;; Initialize
              (.startDrag drag e))))))}))


(defn range-component [v min max title]
  [:div {:class "form-group"}

  [clicks]
  [:h2 "Clicks: " [:small @clicks]])

(defn circle-component
  [cx cy r fill score]
  (let [local-state {:x cx :y cy}]
    (r/set-state (r/current-component) local-state)
    (fn [cx cy r fill score]
      [:circle {:cx @cx :cy @cy
                :r @r :style {:fill @fill}
                :onClick (fn [e] (swap! score inc))}])))

(defn make-constraint
  "Creates a function that keeps a supplied number within the set bounds"
