           (warn "re-frame: Looks like \"pure\" is in the middleware pipeline twice. Ignoring.")
           (warn "re-frame: \"pure\" middleware not given a Ratom.  Got: " app-db))
         handler)    ;; turn this into a noop handler
-      (let [orig-db @app-db
-            new-db  (handler orig-db event-vec)]
+      (let [db      @app-db
+            new-db  (handler db event-vec)]
         (if (nil? new-db)
           (warn "re-frame: your pure handler returned nil. It should return the new db state.")
-          (if-not (identical? orig-db new-db)
+          (if-not (identical? db new-db)
             (reset! app-db new-db)))))))
 
 


(defn path
  "A middleware factory which supplies a sub-tree of `db` to the handler.
  Supplies a narrowed view.
  Assumes \"pure\" is in the middleware pipeline prior.
  Grafts the result back into db.
  If a get-in of the path results in a nil, then \"default-fn\" will be called to supply a value.
  XXX very like update-in. Should the name be more indicative of that closeness? "
  ([p]
    (path p nil))
  ([p default-fn]
    (fn middleware
      [handler]
      (fn path-handler
        [db v]
        (if-not (vector? p)
          (warn  "re-frame: \"path\" expected a vector, got: " p))
        (let [val (get-in db p)
              val (if (and (nil? val) (fn? default-fn)) (default-fn) val)]
          (assoc-in db p (handler val v)))))))


(defn undoable
  "A Middleware factory which stores an undo checkpoint.
  \"explanation\" can be either a string or a function. If it is a
  function then it must be:  (db event-vec) -> string.
  \"explanation\" can be nil. in which case no
  "
  [explanation]
  (fn middleware

  the same text, then highlight their background, and report them in a warning
  down the bottom.
  Almost any action (edit text, add new todo, remove a todo) requires a
  complete reassesment of duplication errors and warnings. Eg: that edit
  update might have introduced a new duplicate or removed one. Same with a
  todo removal.
  And to perform this enrichment, a function has inspect all the todos,
