Skip to content

Comment on Relic: Functional relational programming for Clojure(Script)parent

Comments

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

Yes, 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.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.