With pure much more firmly embedded as mandatory middleware, remove a couple of checks

This commit is contained in:
mike-thompson-day8 2015-03-05 14:43:11 +11:00
parent 94afb7a7a1
commit a48f55ff79

View File

@ -18,17 +18,18 @@
[handler] [handler]
(fn pure-handler (fn pure-handler
[app-db event-vec] [app-db event-vec]
(assert (satisfies? IReactiveAtom app-db) (if (not (satisfies? IReactiveAtom app-db))
(str "re-frame: pure not given a Ratom." (do
(if (map? app-db) (if (map? app-db)
" Looks like \"pure\" is in the middleware pipeline twice." (warn "re-frame: Looks like \"pure\" is in the middleware pipeline twice. Ignoring.")
(str " Got: " app-db)))) (warn "re-frame: \"pure\" middleware not given a Ratom. Got: " app-db))
handler) ;; turn this into a noop handler
(let [orig-db @app-db (let [orig-db @app-db
new-db (handler orig-db event-vec)] new-db (handler orig-db event-vec)]
(if (nil? new-db) (if (nil? new-db)
(warn "re-frame: your pure handler returned nil. It should return the 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? orig-db new-db)
(reset! app-db new-db)))))) (reset! app-db new-db)))))))
(defn debug (defn debug
@ -38,13 +39,11 @@
[handler] [handler]
(fn debug-handler (fn debug-handler
[db v] [db v]
(if (satisfies? IReactiveAtom db)
(str "re-frame: \"debug\" middleware used without prior \"pure\"."))
(group "re-frame event: " v) (group "re-frame event: " v)
(let [new-db (handler db v) (let [new-db (handler db v)
diff (data/diff db new-db)] diff (data/diff db new-db)]
(log "only before: " (first diff)) (log "only before: " (first diff))
(log " only after: " (second diff)) (log "only after : " (second diff))
(groupEnd) (groupEnd)
new-db))) new-db)))
@ -79,14 +78,12 @@
If a get-in of the path results in a nil, then \"default-fn\" will be called to supply a value. 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? " XXX very like update-in. Should the name be more indicative of that closeness? "
([p] ([p]
(path p hash-map)) (path p #(nil)))
([p default-fn] ([p default-fn]
(fn middleware (fn middleware
[handler] [handler]
(fn path-handler (fn path-handler
[db v] [db v]
(if (satisfies? IReactiveAtom db)
(str "re-frame: \"path\" used in middleware, without prior \"pure\"."))
(if-not (vector? p) (if-not (vector? p)
(warn "re-frame: \"path\" expected a vector, got: " p)) (warn "re-frame: \"path\" expected a vector, got: " p))
(let [val (get-in db p) (let [val (get-in db p)
@ -126,7 +123,8 @@
position presumably for side effects. position presumably for side effects.
\"f\" is given the value of \"db\". It's return value is ignored. \"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. Examples: \"f\" can run schema validation. Or write current state to localstorage. etc.
In effect, \"f\" is meant to sideeffect. It gets no chance to change db. See \"derive\" (if you need that.)" In effect, \"f\" is meant to sideeffect. It gets no chance to change db. See \"enrich\"
(if you need that.)"
[f] [f]
(fn middleware (fn middleware
[handler] [handler]