mount

ido 2016-04-28T08:51:39.000166Z

Hey @tolitius . I have a state in a library. now the state have dependencies which are not known at compile time, so I have tried to pass them as arguments using mount/start-with-args. I suspect that this is not supported, right? Every state I pass as an argument is passed as a mount.core.DerefableState and every non-state argument is passed fine. This is of course a circular dependency by definition, but is doable with component, since all the dependencies are defined explicitly there. Since mount relies on the compiler- is there a way to pull this off?

arnout 2016-04-28T09:12:33.000167Z

@ido: while I am of the opinion that mount states are not suitable for libraries, I think you can pull this off by passing the var as an argument. Then you can deref that var in the state that depends on it. This is possible with mount-lite, but I suspect it is the same for mount.

ido 2016-04-28T09:20:28.000168Z

@arnout: I am now starting to feel this in my fingers after I wrote a large mount-common library for use in house here. Maybe this was a mistake. But I'll try the var/deref approach first.

arnout 2016-04-28T09:21:58.000169Z

@ido: good luck :simple_smile:

ido 2016-04-28T09:32:52.000170Z

@arnout: deref is not enough. I now have a mount.core.NotStartedState in hand. Mount just won't start it. @tolitius is there anyway to convince mount that those are dependencies?

ido 2016-04-28T09:34:55.000171Z

@arnout: do you have any experience migrating from mount to mount-lite? I am having heresy thoughts :simple_smile:

arnout 2016-04-28T09:36:14.000172Z

@ido: Did you require the dependency state somewhere? That is required for mount to recognise and register the state.

ido 2016-04-28T09:37:54.000173Z

@arnout: yes I did. everything else is started but the stuff I pass to start-with-args

arnout 2016-04-28T09:39:50.000174Z

So, your code looks something like this?

(defstate foo
  :start 'started)

(defstate bar
  :start (do-something-with (-> (mount/args) :bar-dep deref)))

(mount/start-with-args {:bar-dep #'foo})

arnout 2016-04-28T09:45:23.000176Z

About migrating, I had not written a lot of mount before creating mount-lite. You can read the documentation here http://www.functionalbytes.nl/mount-lite/index.html, and decide for yourself. In the end, both libraries have the same goal, just with a tad different approach.

arnout 2016-04-28T09:47:07.000178Z

In mount-lite, the dependency injection code you need would look like this:

user> (defstate foo :start 'foo)
#'user/foo
user> (defstate bar [dep nil] :start (prn @dep))
#'user/bar
user> (start (bindings #'bar ['dep #'foo]))
foo
(#'user/foo #'user/bar)

arnout 2016-04-28T11:03:51.000179Z

@ido, any luck yet?