I have an Electric v2 app that uses e/def extensively. The definitions form a DAG, often via intermediate calls of Electric functions. How can I port this to Electric v3?
Looking back at old messages, maybe I have to create bindings for these things at the root of my app. But then my root namespace would need to know lots of things that I don’t really want it to know.
can i see the code? Injecting dependencies in the root is idiomatic, e/def is global scope
Here’s an example:
(ns nomis-timelines.timeline-items-1)
(e/def server-timeline-items
...)
(e/def max-ti-end-parsed
(e/client
(apply max (map :ti-end-parsed
server-timeline-items)))) ; <- depending on another `e/def`
(ns nomis-timelines.nominal-timeline-chart-width
(:require
[hyperfiddle.electric :as e]
[nomis-timelines.scale-and-axis :as scale-and-axis]
[nomis-timelines.timeline-items-1 :as timeline-items-1]))
(e/def nominal-timeline-chart-width ; <- depending on another `e/def` and using an Electric function:
(+ (scale-and-axis/TransformX. timeline-items-1/max-ti-end-parsed)
...))
If you’d like to see more I can give you access to my GitHub repo.can you just convert them all to e/defn?
(e/defn Nominal-timeline-chart-width [max-ti-end-parsed] ...)
I tried that, but I think I lose the memoising that e/def gives me.
So if there are multiple users of the e/def it only gets computed once, but converting to a function loses that I think
Oh, passing in all the dependencies as parameters. Hmmm
in the end, this DAG, lets call it SimonsHugeGlobalDAG, has clear inputs and outputs, represent them as e/fn params and return value, and call this e/fn SimonsHugeGlobalDAG once at the top of your app and pass in the actual inputs. Inside SimonsHugeGlobalDAG use let instead of e/def for all your "global" definitions
OK; cool — I will try that. Thanks (again!).