 (defn setpage [next]
   (updatedb [:start] next))
 
+(defn update_field [id value]
+  (println "Updating" id value)
+  (set! db (assoc-in db [:editing id] value)))
+
+(defn save []
+  (println "Saved!"))
+
+(defn clear []
+  (println "Cleared!"))
+
 ;
 ; View
 ;
 
-(defn text [value]
-  (m "input[type=text]" {:value value} nil))
+(defn text [id value]
+  (m "input[type=text]"
+     {:value value :onchange #(update_field id (-> % .-target .-value))}
+     nil))
 
 (defn editor [data]
   (let [title (get data "title" "")

    (m "div" nil ["Count: " count " " (page start - count) " " (page start + count)])))

(defn ctrl []
  (println "Calling major Tom")
  (fetch "/data.json"))

(defn viewer [c]
  (m "div" nil
     [(m "h1" {:style {:color "green"}} (:var db))
      (editor {})
      (m "div" {} [(m "ol" nil (notes (:data db) (:start db)))])
      (pages)]))



(def db
  {:var (str "tosi:" (rand-int 10))
   :start 10
   :editing {}})

(defn ^:export updatedb [fields value]
  (set! db (assoc-in db fields value))
