 (defn- redo
   [undos cur redos]
   (let [u (conj @undos @cur)
+        r  @redos
+        path (undo-path-ks)]
+    (if path
+      (swap! cur assoc-in path (first r))
+      (reset! cur (first r)))
+    (reset! redos (rest r))
+    (reset! undos u)))
+
+(defn- redo-explain
+  [undos cur redos]
+  (let [u (conj @undos @cur)
         r  @redos]
-    (swap! cur assoc-in (undo-path-ks) (first r))
+    (reset! cur (first r))
     (reset! redos (rest r))
     (reset! undos u)))
 

(defn- undo
  [undos cur redos]
  (let [u @undos
        r (cons @cur @redos)]

    (.log js/console "in undo")
    (.log js/console cur)
    (.log js/console (undo-path-ks))
    (.log js/console (last u))
    (swap! cur assoc-in (undo-path-ks) (last u))
    (reset! redos r)
    (reset! undos (pop u))))


;;
;;
(def ^:private config (atom {:max-undos 50   ;; Maximum number of undo states maintained
                             :path  nil}))     ;; undo and redos will apply to only this path within app-db
(defn set-max-undos!
  [n]
  (swap! config assoc :max-undos n))
