i am working a project where a state is dependent on other states. ie: conn1 (conn2 conn1 config) (conn3 conn1 conn2) how do i express this in mount?
@dhruv1: do you mean that conn1
should be started before conn2
, and "`conn1` and conn2
" should be started before conn3
?
if you have states defined as:
(defstat config :start ...)
(defstate conn1 :start (new-conn config)
(defstate conn2 :start (new-conn conn1 config))
(defstate conn3 :start (new-conn conn1 conn2))
internally mount will assign an :order
to each state as they were compiled. and since conn2
can't be compiled without compiling conn1
and config
, it will be "ordered"/started after them.something like this https://github.com/stuartsierra/component#systems
@tolitius injecting dependencies
ok i think this reflects what i’m talking about https://github.com/tolitius/mount/blob/master/README.md#start-and-stop-order
this is interesting.
I defined a var with a defstate
but made a mistake the first time around.
;; not the same mistake but it will help elaborate what I’m trying to explain
(def conn1-atom (atom nil))
(defstate conn
:start (reset! conn1-atom :started)
:stop (reset! :started conn1-atom)) ;; there is a mistake in :stop.
(mount/start) ;; this works fine.
(mount/stop) ;; produces the error.
ClassCastException clojure.lang.Keyword cannot be cast to clojure.lang.IAtom clojure.core/reset! (core.clj:2273)
;; trying to re-define conn
but keep running into the same error.
(defstate conn
:start (reset! conn1-atom :started)
:stop (reset! :started conn1-atom))