(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?I'm pretty sure you can safely use @(subscribe ...)
within the reg-sub
handler.
Alternatively, use reg-sub-raw
.
Is there a way to check if a subscription is already registered given a query-id?
I figure I could use the re-frame.registrar
namespace functionality, but that feels like relying on internal api too much
It is internal. But I don't think there's any other way.