integrant

2021-09-30T13:58:19.068800Z

@dborges @kevin.van.rooijen: Just catching up on the above discussion… It sounds like there are some analogies between what you’re wanting to do and integrants suspend/resume mechanism. I wonder if you could hack something together using aspects of that mechanism. Also I noticed you mentioned “frontend”. Obviously one difference between clojurescript and clojure is that clojurescript doesn’t really have runtime eval, consequently all the cljs needs to be compiled first; which kinda implies you’re requiring everything, and bits of integrant like ig/load-namespaces don’t make sense. So wondering what you mean by “lazy loading”, how are you doing that?

2021-09-30T13:59:49.069700Z

Also what are modules in this context?? I’m guessing you don’t mean duct modules as IIRC they’re a pure clj thing.

2021-09-30T14:01:45.070700Z

I think lazy loading in this case means dispatching the events in the multimethods lazily

2021-09-30T14:02:40.071700Z

Since the event might trigger an HTTP request, for example (but Dax can probably elaborate 😄 )

2021-09-30T14:02:56.072Z

ok — so not something based around something like requiring-resolve (which presumably isn’t available in cljs)

2021-09-30T14:03:20.072500Z

I wouldn't think so no. I assume all multimethods are required before compilation is started

2021-09-30T14:03:32.073Z

But that's my assumption of the situation

2021-09-30T14:03:32.073100Z

yeah

2021-09-30T14:04:23.073500Z

having to use remove-method feels a bit icky though

2021-09-30T14:04:32.073700Z

It definitely is 😄

2021-09-30T14:04:40.074100Z

“nice” hack though 😁 (for some definition of nice)

2021-09-30T14:04:42.074200Z

But if you want to make integrant do something it's not meant to do

2021-09-30T14:04:54.074600Z

Then yeah 🤷

2021-09-30T14:05:32.075600Z

multimethods in clojurescript will never re-evaluate in production, so I don't see how this could break

2021-09-30T14:05:46.075900Z

Yeah I’ve definitely found integrant isn’t entirely suited for things like this. It’s good for static systems, but dynamic systems it’s always a bit of cludge.

2021-09-30T14:06:31.077400Z

I'm actually working on a more dynamic-ish implementation similar to integrant. But still a bit in hammock mode

2021-09-30T14:06:58.077700Z

Since I'm abusing integrant heavily at the moment (in production)

2021-09-30T14:07:17.078Z

I could really use a more tailored solution for my use case

2021-09-30T14:10:25.078700Z

Integrant's dependency resolver is also very slow. If you have a large configuration it can take seconds te resolve

2021-09-30T14:10:59.079Z

But again, these are things that Integrant wasn't really made for

2021-09-30T14:11:05.079200Z

Yeah definitely

2021-09-30T14:12:05.080200Z

I’ve got usecases where I want multiple phases for initialisation… e.g. I need a phase where some bits of the system are initialised first, e.g. a database is loaded with reference data, which is then validated, then after that the webserver is started.

2021-09-30T14:13:12.081100Z

I spoke to @dominicm about this topic a year or two ago, and I seem to remember him creating a more dynamic “integrant”; but I can’t for the life of me remember what it was called.

2021-09-30T14:15:27.082Z

This maybe?

2021-09-30T14:16:00.082400Z

No docs though and hasn't been updated in a while, so that unfortunate

2021-09-30T14:16:48.082700Z

I don’t think that’s it

2021-09-30T14:17:11.083Z

it had a pretty comprehensive readme

2021-09-30T14:17:25.083300Z

Hopefully he will enlighten us 😄

2021-09-30T14:20:01.083500Z

This is it: https://github.com/juxt/clip

2021-09-30T14:20:48.084500Z

Never used it though — though I seem to remember him creating it shortly after we spent a while discussing a more dynamic integrant. Unfortunately I never got around to having a play with it.

2021-09-30T14:20:59.084700Z

Thanks for the link

2021-09-30T14:21:08.085Z

I'll check this out when I have time

2021-09-30T14:29:34.089900Z

Returning to the original question, and phased systems… I wonder if we really need a new integrant at all… perhaps just a few new defmethods… e.g. in the same way ig/resume takes a config and an old system, we could have a new variant that took a config and a running subset of the system, and started the remaining bit… it would just call ig/init-key for anything not already running.

2021-09-30T14:33:00.091700Z

tempted to write this now — but got other stuff to do 😞

2021-09-30T14:49:44.093100Z

I guess you could do something like that, but you'd have to keep track of keys that have been initialized. Also if you initialize for a second time you will have 2 separate subsets. Sounds a bit like a pain to manage (in this use case)

2021-09-30T15:59:42.097100Z

A system only contains initialised keys, so the key diff between the remaining config and your previously initialised subsystem should give you that.

2021-09-30T14:49:58.093400Z

I might be misunderstanding your intent though

Dax Borges 2021-09-30T15:00:24.096600Z

Sorry I don't have a ton of time to discuss this right now but for clarity, when I say lazy-load I mean we are loading a javascript file into the browser based on when a user takes some action which requires additional functionality. This JS file contains components which have dependencies which have already been initialized from the main bundle on page load