 
 
 (defn validate
-  "Middleware factory which applies a given validation function \"f\" to db
-  after the handler is finished.
-  This validation function f, might further change db, by perhaps
-   assoc-ing warnings and errors into db. "
+  "Middleware factory which runs a given function \"f\" in the after position.
+  \"f\" is given the new db value and is expected to perform certain kinds of
+  \"overall\" checks on this new state, adding to it (or removing) necessary
+  errors and warnings.
+  This need is such a common pattern!! There are invariably a category of
+  checks that require \"overall knowledge\".
+  For example, imagine that todomvc had to do duplicate detection - if any
+  two todos had the same text, highlight them, and put a warning down the
+  bottom.
+  That requires access to all todos, plus the ability to assoc in one or
+  more duplicate reports. Perhaps make the background of these todos pink
+  as a sign of the problem.
+  And that's just one kind of check, there may be a few that need to run
+  on every change.
+  \"f\" would need to be both adding and removing the duplicate warnings.
+  We don't want to pollute each handler with calls to \"f\", so we
+  simply add it to the middleware for each handler, and presto the checks are
+  always run.
+  This is a genuine part of the Derived Data, flowing thing."
   [f]
   (fn middleware
     [handler]
     (fn new-handler
       [db v]
       (f (handler db v)))))
+
+
+
+(defn after
+  "Middleware factory which runs a function \"f\" in the \"after handler\"
+  position presumably for side effects.
+  \"f\" is given the value of \"db\". It's return value is ignored.
+  Examples: \"f\" can run schema validation. Or write current state to localstorage. etc."
+  [f]
+  (fn middleware
+    [handler]
+    (fn new-handler
+      [db v]
+      (let [new-db (handler db v)]
+        (f new-db)   ;; call f for side effects
+        new-db))))
 
 
 ;; warning: untested

  "Supplies a sub-tree of `db` to the handler. 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."
  ([p]
    (path p hash-map))
  ([p default-fn]


(defn debug
  "Middleware which logs debug information to js/console for each event.
  Includes a clojure.data/diff of the db, before vs after, showing the changes
  caused by the event."
  [handler]
  (fn new-handler
    [db v]
