mount

2016-09-21T19:32:47.000269Z

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?

tolitius 2016-09-21T20:40:32.000271Z

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

tolitius 2016-09-21T20:45:35.000273Z

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.

2016-09-21T21:21:32.000275Z

something like this https://github.com/stuartsierra/component#systems

2016-09-21T21:21:55.000277Z

@tolitius injecting dependencies

2016-09-21T21:23:08.000279Z

ok i think this reflects what i’m talking about https://github.com/tolitius/mount/blob/master/README.md#start-and-stop-order

2016-09-21T22:38:19.000286Z

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