New middleware, mostly untested.
This commit is contained in:
parent
e548759fe6
commit
00ba238b74
|
@ -9,15 +9,17 @@
|
|||
|
||||
|
||||
(defn pure
|
||||
"Middleware which adapts a pure handler to the standard calling convension"
|
||||
"Middleware which adapts a pure handler to the non-pure standard calling convention"
|
||||
[handler]
|
||||
(fn new-handler
|
||||
[app-db event-vec]
|
||||
(assert (satisfies? IReactiveAtom app-db)
|
||||
(str "re-frame: pure not given a Ratom" (if (map? app-db) ". Perhaps \"pure\" is in twice.")))
|
||||
(str "re-frame: pure not given a Ratom" (if (map? app-db) ". Perhaps \"pure\" is used twice.")))
|
||||
(reset! app-db (handler @app-db event-vec))))
|
||||
|
||||
|
||||
|
||||
;; warning: untested
|
||||
(defn undoable
|
||||
"Middleware which stores an undo checkpoint, prior to handler being called."
|
||||
[handler]
|
||||
|
@ -28,22 +30,7 @@
|
|||
|
||||
|
||||
|
||||
|
||||
;; check the state of db AFTER the handler has run, using a prismatic Schema.
|
||||
#_(defn check-schema
|
||||
"Middleware for checking that a handlers mutations leave the state in a schema-matching way"
|
||||
[a-prismatic-schema]
|
||||
(fn middleware
|
||||
[next-handler]
|
||||
(fn handler
|
||||
[db v]
|
||||
(let [val (next-handler db v)
|
||||
valid? true] ;; XXXXX replace true by code which checks the schema using original parameter
|
||||
(if (not valid?)
|
||||
(warn "re-frame: schema not valid after:" v))
|
||||
val))))
|
||||
|
||||
|
||||
;; warning: untested
|
||||
(defn apply-event
|
||||
"Middleware which removes the first bit of v, and \"expands\" other parameters.
|
||||
Normally handlers get two paramters: db and v.
|
||||
|
@ -55,6 +42,7 @@
|
|||
(apply handler (cons db (rest v)))))
|
||||
|
||||
|
||||
;; warning: untested
|
||||
(defn path
|
||||
"Supplies a sub-tree of `app-db` to the handler.
|
||||
Assumes pure is
|
||||
|
@ -64,10 +52,14 @@
|
|||
[handler]
|
||||
(fn new-handler
|
||||
[db v]
|
||||
(warn (vector? p) "re-frame: ex")
|
||||
(assoc-in db p (handler db v)))))
|
||||
(if (satisfies? IReactiveAtom db)
|
||||
(str "re-frame: \"path\" used in middleware, without prior \"pure\"."))
|
||||
(if-not (vector? p)
|
||||
(warn "re-frame: \"path\" expected a vector, got: " v))
|
||||
(assoc-in db p (handler (get-in db p) v)))))
|
||||
|
||||
|
||||
;; warning: untested
|
||||
(defn validate
|
||||
"Middleware that applies a validation function to the db after the handler is finished.
|
||||
The validation function f, might assoc warnings and errors to the new state, created by the handler.
|
||||
|
@ -80,6 +72,7 @@ By validation, I mean validation of what the user has entered, or the state they
|
|||
(f (handler db v)))))
|
||||
|
||||
|
||||
;; warning: untested
|
||||
(defn log-events
|
||||
"Middleware that logs events (vec) using to the given logger fucntion"
|
||||
[logger]
|
||||
|
@ -91,3 +84,19 @@ By validation, I mean validation of what the user has entered, or the state they
|
|||
(handler db v))))
|
||||
|
||||
|
||||
|
||||
|
||||
;; warning: untested
|
||||
;; check the state of db AFTER the handler has run, using a prismatic Schema.
|
||||
#_(defn check-schema
|
||||
"Middleware for checking that a handlers mutations leave the state in a schema-matching way"
|
||||
[a-prismatic-schema]
|
||||
(fn middleware
|
||||
[next-handler]
|
||||
(fn handler
|
||||
[db v]
|
||||
(let [val (next-handler db v)
|
||||
valid? true] ;; XXXXX replace true by code which checks the schema using original parameter
|
||||
(if (not valid?)
|
||||
(warn "re-frame: schema not valid after:" v))
|
||||
val))))
|
Loading…
Reference in New Issue