re-frame

Ryan 2024-12-13T00:00:25.509429Z

For a materialized view using the shorthand form, is it possible to pass a query variable to the input signal?

Ryan 2024-12-13T00:00:51.952629Z

something like

Ryan 2024-12-13T00:01:16.082319Z

(reg-sub 
  :id

  ;; input signals 
  :<- [:a entity-id]        ;; means (subscribe [:a] is an input)
  :<- [:b 2]      ;; means (subscribe [:b 2] is an input)

  ;; computation function
  (fn [[a b] entity-id other-query-v]
       (calculate-it a b)))

p-himik 2024-12-13T05:38:26.112209Z

No, you have to use the full form.

🙏 1
thogha 2024-12-13T23:52:49.061279Z

Given an event handler with two effects, where the second effect depends on the first completing, can the following pattern be relied upon?

(rf/reg-event-fx
 ::dispatch-events-sequentially
 (fn [_ _]
   {:fx [[:dispatch [::first-event]]
         [:dispatch [::depends-on-first-completing]]]}))
If dispatches occur in parallel, that would cause a problem. In that case, is the following recommended?
(rf/reg-event-fx
 ::depends-on-first-completing
 (fn [_ _]
   {}))

(rf/reg-event-fx
 ::first-event
 (fn [_ _]
   ; calculate something
   {:fx [[:dispatch [::depends-on-first-completing]]]}))

(rf/reg-event-fx
 ::dispatch-events-in-chain
 (fn [_ _]
   {:fx [[:dispatch [::first-event]]]}))

p-himik 2024-12-14T09:58:58.019899Z

The events will be handled in the right order. In fact, the :fx effect handler checks that its argument is sequential. But if ::first-event uses :dispatch or some other "happens later" effects, then of course ::depends-on-first-completing will not see the results of those effects. That's why I mentioned before that "util" events become harder to use the more you rely on them.

thogha 2024-12-14T17:59:56.361659Z

Got it. Thanks again!

👍 1