mount

audaxion 2016-02-23T01:48:24.000081Z

i’m having a problem where i have defstate defined in a file to start up my db connection, but it only starts if i explicitly load-file in my REPL

tolitius 2016-02-23T01:49:48.000082Z

@audaxion: where do you call (mount/start)?

audaxion 2016-02-23T01:50:04.000083Z

it’s a luminus project

audaxion 2016-02-23T01:50:33.000084Z

i have my user ns call http/start

audaxion 2016-02-23T01:50:48.000085Z

which calls my init function

audaxion 2016-02-23T01:50:58.000086Z

which calls mount/start

tolitius 2016-02-23T01:53:06.000087Z

just to clarify: you have two namespaces A and B you have your defstate defined in A in the namespace B you call (mount/start) and the database connection state does not start is that accurate?

audaxion 2016-02-23T01:53:53.000088Z

that sounds right

tolitius 2016-02-23T01:54:19.000089Z

does your namespace B require a namespace A?

audaxion 2016-02-23T01:54:32.000090Z

nope

tolitius 2016-02-23T01:54:39.000091Z

that would be the reason

audaxion 2016-02-23T01:55:01.000092Z

ah

tolitius 2016-02-23T01:57:30.000093Z

when you load the program, at the entry point i.e. (mount/start), namespaces need to be required in order for mount to see them. that does not mean you have to require all the namespaces with defstates since most of them would be brought in transitively (similar to how dependencies are resolved with lein / boot / maven), but something needs to tell your entry point namespace what it is "you'd like to work with"

tolitius 2016-02-23T01:58:57.000095Z

let me know if adding a require made it work for you

audaxion 2016-02-23T02:01:24.000097Z

yeah that seems to have solved it

audaxion 2016-02-23T02:01:42.000098Z

looks like i need to create an issue for the luminus template

audaxion 2016-02-23T02:02:53.000099Z

thanks @tolitius

tolitius 2016-02-23T02:03:18.000100Z

sure, let me know if/when you have more questions

tolitius 2016-02-23T06:26:29.000104Z

@taylor.sando, see if this resolves the issues you had: https://github.com/tolitius/mount/blob/0.1.10-SNAPSHOT/README.md#composing-states

tolitius 2016-02-23T06:26:37.000106Z

(changes are in 0.1.10-SNAPSHOT)

arnout 2016-02-23T08:52:08.000108Z

@tolitius: I believe swap and swap-states are side effecting? Have you thought about naming them swap! and swap-states!?

2016-02-23T13:21:32.000109Z

@tolitius: The composing does work Does yurt also need to change, because I don't see a way of using blueprint

tolitius 2016-02-23T13:32:37.000110Z

@taylor.sando thx for checking. I'll update yurt a bit later. just wanted to first make sure mount works

tolitius 2016-02-23T13:38:43.000111Z

@arnout: I thought about it, but then I am not a "purist", and in this case thread side effects do not affect the application, and mostly affect mount internal state, which is later rolled back to its original state on (mount/stop). + most of the time these functions will be used together in composition right before the call to (mount/start).. e.g. which by itself is side effecting.. just not in the "business" context of an application + in yurt these will be detached after created, and will live locally .... :)

arnout 2016-02-23T13:44:31.000112Z

@tolitius: true, and they are also fine to use inside clojure.core/swap!, alter etc, as substitute! is idempotent. Still, users might be suprised if they have something like:

(def config-a
  (-> (only #'a #'b)
      (swap {#'a :some-substitute})))

(def config-b
  (-> (only #'b #'c)
      (swap-state {#'b #'d})))

(mount/start)

arnout 2016-02-23T13:46:09.000115Z

Maybe it is not your intention to have users use mount/your composable functions like that, but hey... users :simple_smile:

tolitius 2016-02-23T14:17:43.000116Z

yea, for these presets I would not recommend defing them. but rather use data, which I might add later. the whole concept is not immensely useful ( my opinion :simple_smile: ), but very good to have, so I don't want to make it more complex than it needs to be. yes, there is room for error, but if you are already in a position where you splitting state configs, you'd probably know what you are doing

tolitius 2016-02-23T14:18:23.000117Z

the only place where the data approach is really useful, might be lein profiles, since lein is declarative

tolitius 2016-02-23T14:18:31.000118Z

boot does not suffer this problem :simple_smile:

arnout 2016-02-23T18:50:36.000119Z

Nice, you really gave it some thought! I hope you don't mind me spewing my thoughts here :)

tolitius 2016-02-23T19:42:36.000120Z

@arnout: yea, I slept on it for some time.. thoughts are always welcome :simple_smile: