Incorporate changes from #46

This commit is contained in:
mike-thompson-day8 2015-04-18 21:15:53 +10:00
parent 76ee67de10
commit f5ed759767
3 changed files with 6 additions and 6 deletions

View File

@ -7,9 +7,9 @@
(defn comp-middleware (defn comp-middleware
"Given a vector of middleware, filter out any nils, and use \"comp\" to compose the elements. "Given a vector of middleware, filter out any nils, and use \"comp\" to compose the elements.
v can have nested vectors, and will be flattended before \"comp\" is applied. v can have nested vectors, and will be flattened before \"comp\" is applied.
For convienience, if v is a function (assumed to be middleware already), just return it. For convienience, if v is a function (assumed to be middleware already), just return it.
Filtering out nils allows us to create Middlewhere conditionally like this: Filtering out nils allows us to create Middleware conditionally like this:
(comp-middleware [pure (when debug? debug)]) ;; that 'when' might leave a nil (comp-middleware [pure (when debug? debug)]) ;; that 'when' might leave a nil
" "
[v] [v]
@ -17,7 +17,7 @@
(fn? v) v ;; assumed to be existing middleware (fn? v) v ;; assumed to be existing middleware
(vector? v) (let [v (remove nil? (flatten v))] (vector? v) (let [v (remove nil? (flatten v))]
(cond (cond
(empty? v) identity ;; noop middleware (empty? v) identity ;; no-op middleware
(= 1 (count v)) (first v) ;; only one middleware, no composing needed (= 1 (count v)) (first v) ;; only one middleware, no composing needed
:else (apply comp v))) :else (apply comp v)))
:else (warn "re-frame: comp-middleware expects a vector, got: " v))) :else (warn "re-frame: comp-middleware expects a vector, got: " v)))

View File

@ -76,7 +76,7 @@
(defn trim-v (defn trim-v
"Middleware which removes the first element of v, allowing you to write "Middleware which removes the first element of v, allowing you to write
more asthetically pleasing handlers. No leading underscore on the event-v! more aesthetically pleasing handlers. No leading underscore on the event-v!
Your handlers will look like this: Your handlers will look like this:
(defn my-handler (defn my-handler
[db [x y z]] ;; <-- instead of [_ x y z] [db [x y z]] ;; <-- instead of [_ x y z]

View File

@ -16,12 +16,12 @@
;; -- router loop --------------------------------------------------------------------------------- ;; -- router loop ---------------------------------------------------------------------------------
;; ;;
;; In a perpretual loop, read events from "event-chan", and call the right handler. ;; In a perpetual loop, read events from "event-chan", and call the right handler.
;; ;;
;; Because handlers occupy the CPU, before each event is handled, hand ;; Because handlers occupy the CPU, before each event is handled, hand
;; back control to the browser, via a (<! (timeout 0)) call. ;; back control to the browser, via a (<! (timeout 0)) call.
;; ;;
;; In some cases, we need to pause for an entire annimationFrame, to ensure that ;; In some cases, we need to pause for an entire animationFrame, to ensure that
;; the DOM is fully flushed, before then calling a handler known to hog the CPU ;; the DOM is fully flushed, before then calling a handler known to hog the CPU
;; for an extended period. In such a case, the event should be laballed with metadata ;; for an extended period. In such a case, the event should be laballed with metadata
;; Example usage (notice the ":flush-dom" metadata): ;; Example usage (notice the ":flush-dom" metadata):