Fork me on GitHub
#re-frame
<
2019-02-05
>
oconn14:02:18

Not sure if itโ€™s idiomatic, but I find it helpful reference a function from my event / subscription. It also makes it easier to test.

(defn event-name
  "event-name's doc"
  [{:keys [db]} _]
  {:db db})

(re-frame/reg-event-fx :event-namespace/event-name event-name)

๐Ÿ‘ 5
hoopes14:02:35

https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/subs.cljs#L90 in a layer 3 subscription, should i add a signal function that returns the app db if i still need the db in my computation function, or should i just use re-frame.db/app-db directly?

hoopes15:02:21

i guess i need the app-db as a signal, so when it changes, the sub recomputes?

dtsiedel15:02:47

It looks to me like the computation function is passed the result of the signal function

dtsiedel15:02:08

So you grab any data you need out of db in the signal, and it comes to computation as a parameter

hoopes15:02:17

yeah, so i guess it doesn't make sense (from a performance perspective) to pass the db through ๐Ÿ™‚ ok, talked myself out of it

hoopes15:02:36

or else, just use the regular old layer 2, and unpack what you need from the db

dtsiedel15:02:53

Yea that seems about right. That page seems to indicate that the layer-3 is only really useful to prevent re-computing an expensive derivation function every time db is changed