Fork me on GitHub
#re-frame
<
2017-06-23
>
danielneal10:06:45

is there a way to subscribe to the db and a subscription in the chained subscription

danielneal10:06:00

i.e. if I want access to the db as well as some derived data

sandbags10:06:27

@danieleneal my guess is that the "right way" is to create subscriptions for each of the bits of the db you also need access to. But a gross hack would just be to create a "top-level" @app-db based subscription and use that.

danielneal10:06:30

gross hack here we come

danielneal10:06:57

(reg-sub :db identity)

gklijs10:06:09

This will cause the component to reload on any change to the db right?

danielneal10:06:35

I think only if the output of the subscription is different

danielneal10:06:26

(reg-sub :some-other-thing :<- [:db] :<- [:derived-data] (fn [db derived-data] (some-other-function db derived-data)))

mikethompson14:06:52

Notes: 1. That subscription handler will rerun everytime anything in db changes. So you wouldn't want it to be an expensive computation. 2. It is kinda unusual to depend on all of db. Normally a subscription depends on some part/path within it.

danielneal14:06:50

@mikethompson 🙂 thanks! So it kind of makes sense to make extra subscriptions that just select the path first, like so (reg-sub :some-path (fn [db] (get db :some-path)) and (reg-sub :some-expensive-computation :<- [:some-path] (fn [data-at-some-path] (some-expensive-function data-at-some-path)) to avoid the expensive computation running unnecessarily