Fork me on GitHub
#mount
<
2016-09-21
>
dhruv119:09:47

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?

tolitius20:09:32

@dhruv1: do you mean that conn1 should be started before conn2, and "`conn1` and conn2" should be started before conn3?

tolitius20:09:35

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.

dhruv121:09:55

@tolitius injecting dependencies

dhruv122:09:19

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