Clojurians
#reagent
<
2016-07-09
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

seantempesta10:07:28

Is there a way to specify reaction dependencies explicitly with reagent? Right now, I’m having to pass ratoms as arguments:

(defn groups-individual-group-info [groups-individual-group-id groups-info-ds]
  (let [result (first (filter #(= (:db/id %) @groups-individual-group-id) @groups-info-ds))]
    result))

(register-sub
  :groups-individual-group-info
  (let [groups-individual-group-id (subscribe [:groups-individual-group-id])
        groups-info-ds (subscribe [:groups-info-ds])]
    (fn [_ _] (r/track groups-individual-group-info groups-individual-group-id groups-info-ds))))
But I’d much rather pass values which can be checked with clojure.spec. Any advice on how this can be achieved?

mikethompson11:07:35

If you are using re-frame, and it looks like you are, don't use r/track , use reaction as pre the docs (your code won't work with v0.8.0 of re-frame if you use r/track) In effect, shouldn't it be:

(register-sub
  :groups-individual-group-info
  (let [groups-individual-group-id (subscribe [:groups-individual-group-id])
        groups-info-ds (subscribe [:groups-info-ds])]
    (reaction (groups-individual-group-info @groups-individual-group-id @groups-info-ds)))))