Close success flash messages via delayed dispatch

This commit is contained in:
Teemu Patja 2017-02-21 23:00:53 +02:00
parent 4e627be1e0
commit 89475a9365
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
1 changed files with 12 additions and 3 deletions

View File

@ -13,6 +13,12 @@
:error-handler on-error
:finally finally
:params params})))
(reg-fx
:delayed-dispatch
(fn [{:keys [args timeout]}]
(js/setTimeout #(dispatch args)
timeout)))
(reg-event-db
:initialize-db
@ -24,10 +30,13 @@
(fn [db [_ path value]]
(assoc-in db path value)))
(reg-event-db
(reg-event-fx
:set-flash-message
(fn [db [_ type text]]
(assoc db :flash-message [type text])))
(fn [{:keys [db]} [_ type text]]
(merge {:db (assoc db :flash-message [type text])}
(when (= type :success)
{:delayed-dispatch {:args [:clear-flash-message]
:timeout 2000}}))))
(reg-event-db
:clear-flash-message