Fork me on GitHub
#mount
<
2020-07-03
>
Matheus Moreira09:07:40

hello! i am trying to understand the proper way of using mount. probably my difficulty arises from my object-oriented/spring-y experience that makes component more familiar, but mount’s argument that namespace and functions are the right abstraction kinda makes sense to me. basically what i am trying to wrap my mind around is this: i am working with datomic and understand that the db client is a (def)state. i would declare this state in a namespace that would be responsible for data access stuff, so the state would be internally accessed by functions in this namespace. now suppose that i want to replace the datomic implementation by an in-memory map implementation for tests… then the client as a state doesn’t seem to be the right “stateful” element, since each function uses the client to retrieve a connection an then uses more datomic api to perform its job. i am not sure if my explanation is understandable… can someone help me figure out the way to organize my states with mount? 🙂

tolitius13:07:20

good question. I think the confusion is from the scope of the state you are thinking about. usually db connection would be a state, and this connection then mocked with a connection to memory vs. disk / cloud. your other functions that work with datomic would accept a connection and use it for queries. it is similar how, in spring, you create a datasource. in spring though a datasource is not a stand alone state and is wrapped into the jdbctemplate, which is where the confusion (I think) comes from.

❤️ 3
Matheus Moreira16:07:45

i can better reason about the oo datasource because: a) i identify the datasource as a resource; b) that is injected into data access objects/classes; and c) these classes are usually behind an interface. in this case i would be able to change not only the datasource implementation, i would be able to change the entire data access layer implementation, e.g. instead of a postgres db it could be an in-memory hashmap.

Matheus Moreira16:07:13

maybe it is because i thought about datomic vs hashmap instead of disk vs. memory. e.g. i don’t want to think about datomic now, i just want to have an interface for some persistence mechanism during development and i mock it as a hashmap. does it make sense?

tolitius16:07:43

yea, there are two things here: • your functions working with the datasource consistently regardless whether it is in memory datasource or a file datasource or a network datasource, etc. • your datasource having a consistent interface (such as make-connection) that can be used by them functions the state here, however is just this datasource / connection. I tend to only use defstate (i.e. create a stateful component) for low level things: connections, thread pools, listeners, etc..

tolitius16:07:27

I went through an exact same transition from "but data access objects/classes is what we use for state, right?" to "no, we only use the lowest stateful things for state, and use functions for everything else" when I started with functional languages (then Erlang). it is a completely healthy and great stage to make your "design" mind to go through

sudakatux21:07:47

I have a similar confusion as @matheus.emm i come from a spring-background do you know of a blog or something explaining mount from a similar background. I would like to know if its possible to mount reitit routes

tolitius22:07:02

> I would like to know if its possible to mount reitit routes sure, it is not exactly mount specific to start a server with reitit routes. mount would be only used to start / stop a server vs. dealing with routes directly. here is a quick example: https://gist.github.com/tolitius/6a6dabfee5df0c6baa97d604560d460d > do you know of a blog or something explaining mount from a similar background I don't know whether there is one, but I've worked with spring for many years (before and after it was cool), so I can definitely answer some questions. maybe as a result also convert all the answers to a blog post so it is useful for others

sudakatux22:07:48

thanks for that

metal 3