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?
@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
.
@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.
@ido: good luck :simple_smile:
@arnout: do you have any experience migrating from mount
to mount-lite
? I am having heresy thoughts :simple_smile:
@ido: Did you require the dependency state somewhere? That is required for mount
to recognise and register the state.
@arnout: yes I did. everything else is started but the stuff I pass to start-with-args
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})
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.
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)
@ido, any luck yet?