re-frame

https://github.com/Day8/re-frame/blob/master/docs/README.md https://github.com/Day8/re-frame/blob/master/docs/External-Resources.md
achikin 2021-03-25T12:01:50.029300Z

(def db {:form {:entity-id 1}
         ...})

(reg-sub
  ::get-some-entity
  :<- [:a lot]
  :<- [:of]
  :<- [:signals]
  (fn [[yada yada yada] [_ entity-id]]
    (some (really (complicated code))))

(reg-sub
  ::get-entity-from-form
  (fn [db [_ form-path]]
     ???????)

(defn my-form []
  (let [form-path :form
        entity @(re-frame/subscrible [::get-entity-from-form form-path])]
    [render-entity entity]))
I have some really complicated subscription with a lot of input signals, which extracts some entity from the db which I can’t replicate as a function of db. Also I have a form stored in the db, which has that entity id inside it. I want a subscription which given a form path gives me back entity (marked with ??????? in the code above). So, essentially what I want to do : 1. given path to form extract :entity-id 2. use that :entity-id as an input to ::get-some-entity and I want to do all of that inside subscriptions, without passing data through the form rendering. Is that possible in re-frame?

p-himik 2021-03-25T13:00:05.029500Z

I'm pretty sure you can safely use @(subscribe ...) within the reg-sub handler. Alternatively, use reg-sub-raw.

Adriaan Callaerts 2021-03-25T15:47:08.030700Z

Is there a way to check if a subscription is already registered given a query-id?

Adriaan Callaerts 2021-03-25T15:49:52.030800Z

I figure I could use the re-frame.registrar namespace functionality, but that feels like relying on internal api too much

p-himik 2021-03-25T15:54:33.031Z

It is internal. But I don't think there's any other way.