Skip to content

Commit

Permalink
:dispatch-later now filters out nils. Fixes #455
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-thompson-day8 committed Mar 5, 2018
1 parent 228d80a commit d692cb2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#### Fixed

- After interceptor now runs against effect db if effect db is nil/false. [#447](https://github.com/Day8/re-frame/issues/447)
- The effect handler for `:dispatch-later` will now ignore `nils`. [#455](https://github.com/Day8/re-frame/issues/455)

## 0.10.5 (2018.02.13)

Expand Down
8 changes: 8 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ usage:

Which means: in 200ms do this: `(dispatch [:event-id "param"])` and in 100ms ...

Note: nil entries in the collection are ignored which means events can be added
conditionally:

```clj
{:dispatch-later [ (when (> 3 5) {:ms 200 :dispatch [:conditioned-out]})
{:ms 100 :dispatch [:another-one]}]}
```

***

#### :dispatch
Expand Down
7 changes: 6 additions & 1 deletion src/re_frame/fx.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@
;; {:dispatch-later [{:ms 200 :dispatch [:event-id "param"]} ;; in 200ms do this: (dispatch [:event-id "param"])
;; {:ms 100 :dispatch [:also :this :in :100ms]}]}
;;
;; Note: nil entries in the collection are ignored which means events can be added
;; conditionally:
;; {:dispatch-later [ (when (> 3 5) {:ms 200 :dispatch [:conditioned-out]})
;; {:ms 100 :dispatch [:another-one]}]}
;;
(reg-fx
:dispatch-later
(fn [value]
(doseq [{:keys [ms dispatch] :as effect} value]
(doseq [{:keys [ms dispatch] :as effect} (filter nil? value)]
(if (or (empty? dispatch) (not (number? ms)))
(console :error "re-frame: ignoring bad :dispatch-later value:" effect)
(set-timeout! #(router/dispatch dispatch) ms)))))
Expand Down

0 comments on commit d692cb2

Please sign in to comment.