re-frame

Ryan 2025-09-10T16:01:18.126559Z

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))

Kimo 2025-09-11T09:44:37.960539Z

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

p-himik 2025-09-11T10:35:39.636689Z

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

p-himik 2025-09-11T10:36:28.663249Z

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.

Kimo 2025-09-11T18:49:23.857219Z

oh right, haha

p-himik 2025-09-10T16:08:42.856529Z

I'd use reg-sub-raw.

p-himik 2025-09-10T16:09:28.397149Z

Oh, wait - no, your approach is proper.

🎉 1
p-himik 2025-09-10T16:09:53.292849Z

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

Ryan 2025-09-10T16:10:11.310939Z

Aha, that makes sense

p-himik 2025-09-10T16:10:37.556779Z

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

Ryan 2025-09-10T16:12:01.164999Z

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

p-himik 2025-09-10T16:13:36.104799Z

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
Ryan 2025-09-10T16:22:53.643819Z

nice

wevrem 2025-09-10T17:07:06.567279Z

@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?

p-himik 2025-09-10T17:32:57.838819Z

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