re-frame

Joshua Shevach 2024-10-22T05:11:04.880359Z

What, if at all, is the right way to access the app-db in a level 3 sub?

p-himik 2024-10-22T07:11:01.313249Z

By using reg-sub-raw.

2024-10-28T03:44:00.331519Z

With the caveat that this is almost certainly a bad thing to do and a sign of a design problem ... you can do it in a variety of ways ... You could do this:

(reg-sub
  :query-id

  ;; signal function
  (fn [_ _] [re-frame/app-db])
  ;; computation function  

  (fn [[db] query-vec]
    ;; compute result
    ))
Or, probably better, you can create a level 2 sub which returns app-db
(reg-sub
  :app-db
  (fn [db _]  db ))
And then use it in a level 3
(reg-sub
  :query-id

  (fn [_ _] [subscribe([:app-db]])

  (fn [[db] query-vec]
    ;; compute result
    ))

p-himik 2024-10-28T05:21:26.300419Z

I'd still use reg-sub-raw. :) Apart from "marking" the sub, it also enables you to refer to other subs conditionally and provide parameters based on computation without having to split every operation into its own sub. Kinda similar in that regard to how one might want to use reg-event-fx to avoid creating "util" event handlers.

Joshua Shevach 2024-10-28T11:29:40.678539Z

Yeah I originally implemented a quick app-db signal sub like Mike suggested with a couple of validations but I definitely prefer reg-sub-raw