Fork me on GitHub
#integrant2021-01-21
>
benny19:01:21

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.

benny20:01:42

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

benny20:01:22

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

Kevin20:01:28

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

Kevin20:01:38

(This is how Duct does it)

3
benny20:01:48

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

benny20:01:40

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

benny20:01:28

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

Kevin20:01:08

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

Kevin20:01:18

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

Kevin20:01:20

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)

benny20:01:51

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

Kevin20:01:11

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

benny20:01:43

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

benny20:01:00

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

Kevin20:01:10

Preferably not no

benny20:01:35

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

Kevin20:01:20

What kind of application is it?

Kevin20:01:26

I've never used Integrant outside of webapps

Kevin20:01:48

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

benny20:01:38

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

benny20:01:06

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

benny20:01:36

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

Kevin20:01:48

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

benny20:01:09

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

Kevin20:01:13

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

Kevin20:01:43

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

Kevin20:01:25

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

benny20:01:39

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

Kevin20:01:44

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

Kevin20:01:01

You just don't include the webserver stuff

benny20:01:06

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

Kevin20:01:24

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