hyperfiddle

2025-04-06T11:14:33.831139Z

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?

2025-04-06T11:54:02.333599Z

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.

Dustin Getz (Hyperfiddle) 2025-04-06T12:59:08.959439Z

can i see the code? Injecting dependencies in the root is idiomatic, e/def is global scope

2025-04-06T13:13:55.629329Z

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.

Dustin Getz (Hyperfiddle) 2025-04-06T13:15:57.340549Z

can you just convert them all to e/defn?

Dustin Getz (Hyperfiddle) 2025-04-06T13:16:29.308999Z

(e/defn Nominal-timeline-chart-width [max-ti-end-parsed] ...)

2025-04-06T13:17:23.005629Z

I tried that, but I think I lose the memoising that e/def gives me.

2025-04-06T13:18:05.365649Z

So if there are multiple users of the e/def it only gets computed once, but converting to a function loses that I think

2025-04-06T13:19:30.340669Z

Oh, passing in all the dependencies as parameters. Hmmm

Dustin Getz (Hyperfiddle) 2025-04-06T13:19:58.591119Z

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

2025-04-06T13:21:20.360669Z

OK; cool — I will try that. Thanks (again!).