4 ms·
ok so would it be correct to say this is sort of like handling an event that gets emitted? Sorry, I know no clojurescript, so I'm having a hard time parsing it
by dmn322 4y ago
ok so would it be correct to say this is sort of like handling an event that gets emitted?
Sorry, I know no clojurescript, so I'm having a hard time parsing it even googling the syntax
- LandR 4y agoYes, exactly. There is a piece of code which emits the event :stop-timer, that stops a js timer in the window. :on-click (fn [_](rf/dispatch-sync [:stop-timer])) In clojure a map has the syntax {:key :value} So this event handler is returning a map which describes the event. There is then a further function which does the actual event (rf/reg-fx :stop-ticker (fn [[handle]] (when (not (nil? handle)) (js/clearInterval handle)))) BUt as far as testing goes, you can test the event handler and test that it returns the expected map. The framework is responsible for actually executing the event that is described the event handler and it does it via the name :stop-ticker. Your event handler itself can remain a pure function.