                       :sync-chan sub-chan
                       :on-error
                       (fn [err tx-data]
+                        (prn "Error:")
                         (reset! app-state (:old-state tx-data))
                         (om/set-state! owner :err-msg
                           "Ooops! Sorry something went wrong try again later."))}})


;; snapshot the state when it is changed:

; (def app-history (atom [@app-state]))

; (defn pluralize [n w]
;   (if (> n 1) 
;       (str w "s")
;       (str w)))

; (add-watch app-state :history
;   (fn [_ _ _ n]
;     (when-not (= (last @app-history) n)
;       (swap! app-history conj n))
;     (let [c (count @app-history)]
;         (prn (str c " Saved " (pluralize c "State"))))))

; (defn undo [e]
;   (when (> (count @app-history) 1)
;     (swap! app-history pop)
;     (reset! app-state (last @app-history))))

; (om/root
;   (fn [app owner]
;     (om/component (dom/button #js {:onClick undo} "Undo!")))
;   app-state 
;   {:target (. js/document (getElementById "inspector"))})

(defn send-update [state]
  (.send @socket (pr-str (select-keys (state :tx-data) [:new-value :path])))
  
  ; (edn-xhr 
  ;   {:method :put
  ;   :url "/data"
  ;   :on-error (fn [res tx-data] (prn tx-data))
  ;   :on-complete (fn [res] (prn "updated"))
  ;   :data (select-keys (state :tx-data) [:new-value :path])})
)

(let [sub-chan (chan)]
(defn app-view [app owner opts]

  (edn-xhr
    {:method :get
     :url "/data"
     :on-error (fn [res tx-data] (prn "Error: ")(println res))
     :on-complete
     (fn [res]
       (let [host (aget js/window "location" "hostname")
