From 6efdae438f393f8121a2d6dfbf76db00e6dafbf5 Mon Sep 17 00:00:00 2001 From: Mike Thompson Date: Thu, 20 Jul 2017 08:51:44 +1000 Subject: [PATCH] Enshrine and document existing practice around dispatch-n and nils --- src/re_frame/fx.cljc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/re_frame/fx.cljc b/src/re_frame/fx.cljc index aff4d45..aab731c 100644 --- a/src/re_frame/fx.cljc +++ b/src/re_frame/fx.cljc @@ -81,12 +81,17 @@ ;; usage: ;; {:dispatch-n (list [:do :all] [:three :of] [:these])} ;; +;; Note: nil events are ignored which means events can be added +;; conditionally: +;; {:dispatch-n (list (when (> 3 5) [:conditioned-out]) +;; [:another-one])} +;; (register :dispatch-n (fn [value] (if-not (sequential? value) (console :error "re-frame: ignoring bad :dispatch-n value. Expected a collection, got got:" value) - (doseq [event value] (router/dispatch event))))) + (doseq [event (remove nil? value)] (router/dispatch event))))) ;; :deregister-event-handler