 
 (defn end-edit [ text state ]
   (let [ qws (js/parseInt text) ]
-    (swap! state assoc :query-window-secs qws)))
+    (watch [:update-qws qws])
+    (reset! query-window-secs qws)))
 
 (defn input-field [ on-enter ]
   (let [ state (atom { :text "" }) ]
     (fn []
       [:input {:value (:text @state)
                :onChange #(swap! state assoc :text (.. % -target -value))
-               :onKeyDown #(when (= (.-key %) "Enter")
-                             (on-enter (:text @state)))} ])))
+               :onKeyDown #(do
+                             (watch [:on-key-down (.-key %)])
+                             (when (= (.-key %) "Enter")
+                                 (on-enter (:text @state))))} ])))
 
 (defn header [ ]
   (watch :render-header)

            [cljs.core.async :refer [put! close! chan <!]]
            [metlog-client.tsplot :as tsplot]))

(def dashboard-state (atom {:series [] :query-window-secs (* 3600 24) :text ""}))

(defn <<< [f & args]
  (let [c (chan)]

              (watch [:response series-name])
              (cb data))))

(defn tsplot-fetch-and-draw [ canvas series-name ]
  (let [ ctx (.getContext canvas "2d")]
    (go
      (tsplot/draw ctx 1024 180 [])
      (tsplot/draw ctx 1024 180 (<! (<<< fetch-series-data
                                         series-name
                                         @query-window-secs))))))

(defn series-tsplot [ series ]
  (let [ series-state (atom { :series-name (:name series)} ) ]
    (reagent/create-class
     {:display-name (str "series-tsplot-" (:name series))
      :component-did-update
      (fn [ this ]
        (watch :component-did-update)
        (tsplot-fetch-and-draw (reagent/dom-node this) (:name series)))
      
      :component-did-mount
      (fn [ this ]
        (watch :component-did-mount)
        (tsplot-fetch-and-draw (reagent/dom-node this) (:name series)))

      :reagent-render
      (fn []
        @query-window-secs
        @series-state
        [:canvas { :width 1024 :height 180}])})))

