integrant

benny 2021-01-21T19:55:21.002800Z

hello everyone. I feel like I'm completely lost. Is there a more than minimal example project using integrant that one can inspect? I'm right now struggling with the ergonomics of having an open connection and using this open connection to do something with it. I have a database connection open and my functions take a connection as a first parameter but having the caller access the system-map every and getting out the currently opened connection feels weird.

benny 2021-01-21T20:04:42.004300Z

to give an additional insight into my current confusion: I see two options, having the caller grab the connection from the system-map and providing it to the callee or have the callee function receive the system-map as arg1 and getting the connection out of there itself

benny 2021-01-21T20:06:22.005700Z

the 2nd option would be fine if it weren't for the repeating of the same code (the get-in) and the bad ergonomics of normal repl development where I have to construct an unnecessarily large map with the right keys just to run my new functions

kwrooijen 2021-01-21T20:13:28.007200Z

Generally the idea is to define request handlers as ig/init-keys, then they reference the database connection in their opts. I'm not sure what kind of an application you're building though

kwrooijen 2021-01-21T20:13:38.007400Z

(This is how Duct does it)

➕ 1
benny 2021-01-21T20:17:48.009500Z

I'm trying to fit integrant into an already established work in progress system that has quite a bit of state, as it sources events from 5 places and so far I've used mount to keep those systems decoupled

benny 2021-01-21T20:18:40.010500Z

but the state is making repl testing cumbersome so I wanted to try integrant but I don't get how I go from the simple jetty single event handler model to my I have events in several subsystems

benny 2021-01-21T20:19:28.011400Z

maybe I have to redesign it and make a application wide queue and that way I can pipe everything through one place

kwrooijen 2021-01-21T20:20:08.012100Z

I think using Integrant in an existing application will be a bit difficult. When building a new Duct app, all your state runs through the integrant map

kwrooijen 2021-01-21T20:20:18.012400Z

You don't access it from the "outside" so to speak

kwrooijen 2021-01-21T20:21:20.013200Z

So if you're planning on using an existing codebase without making it fit into integrant, I'm not sure if that'll be a good choice (however, anyone can feel free to prove me wrong)

benny 2021-01-21T20:21:51.013900Z

I'm fine with retrofitting it because I would like to gain the ability to test while the dev system is running

kwrooijen 2021-01-21T20:22:11.014500Z

You could manipulate a dynamic var with integrant init-keys.. But then it's not much different from using component / mount (I think)

benny 2021-01-21T20:22:43.015100Z

yeah I saw a tutorial on integrant that just used a system atom which is referenced everywhere

benny 2021-01-21T20:23:00.015400Z

that didn't feel like the way to do things 😉

kwrooijen 2021-01-21T20:23:10.015800Z

Preferably not no

benny 2021-01-21T20:23:35.016400Z

maybe I should make a new duct application and just get a feel for how it's done there and try to build a minimal example outside of duct because my application has nothing to do with the web

kwrooijen 2021-01-21T20:24:20.016800Z

What kind of application is it?

kwrooijen 2021-01-21T20:24:26.017100Z

I've never used Integrant outside of webapps

kwrooijen 2021-01-21T20:24:48.017600Z

Well I guess that's technically not true, I've used it in Clojurescript

benny 2021-01-21T20:25:38.018600Z

a desktop program (at this point in time, web will come later) that grabs things from all kinds of places and shows them in a GUI while sourcing events from filesystem watcher and window titles, websites and excel files

benny 2021-01-21T20:26:06.019400Z

it's bespoke and there are 10 people in the world that may find it useful that all have the same job as me 😉

benny 2021-01-21T20:27:36.019900Z

so lots of state and trying to keep it from getting out of control using any means necessary

kwrooijen 2021-01-21T20:28:48.020300Z

Having a hard time imagining what this application might look like internally 😄

benny 2021-01-21T20:30:09.022500Z

the dependency graph is basically me putting everything into a database and having the GUI try to create its state from the choices in the GUI and the DB only

kwrooijen 2021-01-21T20:30:13.022700Z

But the basic gist of Duct is pretty straightforward: [`Database` / logging ] <-- ref --- handler <--- ref --- router <--- ref --- webserver

kwrooijen 2021-01-21T20:30:43.023300Z

Then your application starts Integrant with a root key (for example, the webserver), which starts all the dependent components

kwrooijen 2021-01-21T20:31:25.024400Z

Router takes all the handlers and puts them in the right place. And the handler references things that it needs. For example a database connection

benny 2021-01-21T20:32:39.025400Z

maybe by thinking in those terms I can solve my mapping issue, I'll try the duct template and try to create some basic CRUD stuff in the database

kwrooijen 2021-01-21T20:33:44.026200Z

Also, even though Duct markets itself as a "server-side application framework", I don't think there's anything stopping you from using it in a GUI application

kwrooijen 2021-01-21T20:34:01.026400Z

You just don't include the webserver stuff

benny 2021-01-21T20:35:06.026800Z

thanks @kevin.van.rooijen, time to get my hands dirty 😉

kwrooijen 2021-01-21T20:35:24.027100Z

Best of luck to you 👍 Duct documentation can be a bit lacking