mount

Matheus Moreira 2020-07-03T09:56:40.031800Z

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? 🙂

tolitius 2020-07-03T13:32:20.033200Z

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.

❤️ 1
Matheus Moreira 2020-07-03T16:18:45.035500Z

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 Moreira 2020-07-03T16:22:13.038600Z

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?

tolitius 2020-07-03T16:36:43.043900Z

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..

tolitius 2020-07-03T16:40:27.047500Z

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

sudakatux 2020-07-03T21:48:47.049600Z

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

tolitius 2020-07-03T22:07:02.053400Z

> 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

sudakatux 2020-07-03T22:08:48.053600Z

thanks for that

🤘 1