re-frame 2025-09-10

What’s the best way to write a materialized view that has a parameterized input? Thusly?

(reg-sub ::parameterized-materialized-view
  (fn [query-v] 
    [(subscribe [:a]) (subscribe [:b query-v])])
  (fn [[a b] query-v] (do-stuff a b))

I think event and query-v are synonymous, right?

event is for event handlers, query is for subscription handlers.

But synonymous in the sense that they have the same structure with the same overall meaning - ID of a thing followed by arguments for the handler of the thing.

I'd use reg-sub-raw.

Oh, wait - no, your approach is proper.

🎉 1

reg-sub-raw is more suitable when you either need to have conditional subscriptions or you need to also access app-db.

Aha, that makes sense

Your approach is pretty much literally what happens in the second code block here in the docs: https://day8.github.io/re-frame/subscriptions/#reg-sub

Yeah that’s where I started, just wasn’t sure if there were any caveats to that or if there was a more sugar-y way to express that like the :<- syntax

I have added my own sugar. :) I've wrapped pretty much every re-frame function that I use. In this case, I'd write it as

(my-reg-sub ::parameterized-materialized-view
  (fn [query-v]
    {:a [:a]
     :b [:b query-v]}
  (fn [{:keys [a b]} _]
    (do-stuff a b)))

😯 1

@p-himik I've seen you mention reg-sub-raw often. I've looked at it a little bit but never used it. What is the event argument passed to the handler fn? I'm referring to the description/example on https://day8.github.io/re-frame/flow-mechanics/#reg-sub-raw, where the signature of the handler function is (defn some-fn [app-db event] ...) . What is event there? Is it query-v?

Yeah, seems like a typo in the docs. It is indeed query-v.