Fork me on GitHub
#mount
<
2020-07-06
>
Matheus Moreira09:07:42

> I tend to keep a state with its logical module: i.e. “system-a” namespace will have a connection to “system a” plus some functions to work with “system a”. does it mean that you declare the state and the functions that depend on it in the same namespace (file)? and if this is the case, it wouldn’t be necessary to pass the state as fns arguments, since they can just use the state directly.

Ilari Tuominen11:07:09

I’m a clojure beginner but this is more of a question towards mount so better write it here. I’m having problems with ending up in a DerefableState {:status :pending, :val nil} when loading my state from a file using io/file. Am I trying to access the resource too soon or am I thinking of this wrong? Logging says that my defstate gets started but if I remove the places accessing the state, I can load the namespace in repl and it has the value I’m expecting. How can I get the state properly initialized?

tolitius15:07:04

> does it mean that you declare the state and the functions that depend on it in the same namespace (file)? and if this is the case, it wouldn’t be necessary to pass the state as fns arguments, since they can just use the state directly. the location of state should not really affect the function design. a function would usually take all the state / args it needs. it makes it "self contained" which allows for better testing, refactoring, reuse, .. all the good things.

tolitius15:07:47

@ilari.tuominen probably better solved with an example. usually a couple of quick things to look out for: • call mount/start in case state needs to be created before the function is called and / or • to make sure that compiler sees the namespace where the state lives: i.e. (require '[foo.bar]) where state component lives.