Fork me on GitHub
#mount
<
2016-04-28
>
ido08:04:39

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?

arnout09:04:33

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

ido09:04:28

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

arnout09:04:58

@ido: good luck simple_smile

ido09:04:52

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

ido09:04:55

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

arnout09:04:14

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

ido09:04:54

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

arnout09:04:50

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})

arnout09:04:23

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.

arnout09:04:07

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)

arnout11:04:51

@ido, any luck yet?