I followed this example: https://github.com/Day8/re-frame/blob/master/docs/FAQs/PollADatabaseEvery60.md
And here is my interval handler
(defonce interval-handler
(fn [{:keys [action id frequency event]}]
(let [live-intervals (atom {})]
(condp = action
:start (swap! live-intervals assoc id (js/setInterval #(re-frame/dispatch event) frequency))
:end (do (js/clearInterval (get live-intervals id))
(swap! live-intervals dissoc id))))))
(re-frame/reg-fx
:interval
interval-handler)
I'm trying to dispatch this interval event from another event right here:
(re-frame/reg-event-db
:start-playing
(fn [db _]
(re-frame/dispatch [:interval {:action :start
:id :some-awesome-id
:frequency 1000
:event [:tick]}])
(assoc db :is-playing? true
:fake (random-active-color db)
:real (random-active-color db))))
but it says re-frame: no :event handler registered for: :interval
Is this not possible to do?
db
as the first arg toassoc
. It won't let me edit it cause the change is too small... – Diagnostician