mount

onetom 2017-02-14T09:22:00.000741Z

@arnout i've just noticed your mount-lite 2.0. do you have a public example app showcasing or i can only look at the test suite?

arnout 2017-02-14T12:07:31.000744Z

Hi @onetom, I don't have an example app, but the tests should indeed suffice

arnout 2017-02-14T12:07:49.000745Z

And otherwise, just ask 🙂

onetom 2017-02-14T13:42:33.000748Z

thanks, i will give it a try. im just a bit worried how will it cooperate with boot-jetty, boot-refresh and the boot repl and running tests from cursive... 😕

arnout 2017-02-14T13:43:23.000749Z

What kind of problems do you expect?

onetom 2017-02-14T13:50:38.000751Z

for example when clojure.tools.namespace.repl/refresh unloads changed namespaces, the states defined in them wont be stopped

onetom 2017-02-14T13:52:03.000752Z

i saw in the 0.2.0 docs that > States are not automatically stopped anymore on redefinition. however as i understand refresh is not doing redefinition

arnout 2017-02-14T13:53:14.000753Z

True, stopping states is your own responsibility, especially with tools.namespace. With tests, it's quite easy to add a fixture that ensures all states are stopped after your tests have run (regardless of their results).

arnout 2017-02-14T13:54:01.000754Z

With tools.namespace it is possible to add metadata to the namespaces in order to have different refresh behaviour.

onetom 2017-02-14T13:54:21.000755Z

for tests i would just use separate sessions anyway probably since with cursive they are supposed to be run in the same repl as the dev process

arnout 2017-02-14T13:54:26.000756Z

But this is more suitable if you'd use mount-lite 0.9.x or the original mount.

onetom 2017-02-14T13:57:49.000757Z

im gonna try it soon, but i suspect this boot task won't cut it: https://github.com/samestep/boot-refresh/blob/master/src/samestep/boot_refresh.clj

onetom 2017-02-14T13:58:25.000759Z

according to https://github.com/clojure/tools.namespace i should do something like this:

(defn start []
  (alter-var-root #'my-app (constantly (start-my-app))))

(defn restart []
  (stop-my-app my-app)
  (refresh :after 'dev/start))

onetom 2017-02-14T14:00:17.000762Z

so i guess it should replace the middle of the boot refresh task with (mount/stop) (refresh :after 'mount.lite/start)

onetom 2017-02-14T14:01:01.000763Z

hmm... but that would reboot the whole app 😕 that's not good

arnout 2017-02-14T14:03:54.000764Z

From the former 0.9.x version docs: > This cascading is great to work with, and in combination with the tools.namespace library it can really shine. Whenever you make sure your namespaces with defstate definitions have {:clojure.tools.namespace.repl/unload false} as metadata, calling (clojure.tools.namespace.repl/refresh :after 'mount.lite/start) will only stop the required states (in correct order) and restart them.

onetom 2017-02-14T14:06:03.000765Z

so this still applies to 0.2.0? i haven't seen this in those docs.

arnout 2017-02-14T14:06:24.000766Z

No, it does not, because in 0.2.0 states do not stop themselves when being reloaded.

onetom 2017-02-14T14:09:32.000767Z

ok, thanks, i will play with it and report back with actual examples if something doesn't work

onetom 2017-02-14T14:09:53.000768Z

but it sounds like it make sense to mark all defstates with unload false, no?

arnout 2017-02-14T14:10:44.000769Z

All namespaces (with defstates) you mean?

onetom 2017-02-14T14:11:21.000771Z

oh, i misread it... so the namespaces should be marked with unload, not the defstates...

onetom 2017-02-14T14:11:51.000772Z

nevermind, i will come back with more specific questions soon. thanks in advance!

arnout 2017-02-14T14:12:07.000773Z

Correct, if you use 0.9.x. Otherwise, you are responsible for stoping the states beforehand.

arnout 2017-02-14T14:12:13.000774Z

That would be great, see ya.

onetom 2017-02-14T14:16:00.000775Z

but ctnr/refresh doesn't seem to have a hook for that... =:-/ i dont want to use 0.9.x; im strictly talking about 0.2.0 because i want independent states for tests within the same repl. i don't see any other way how to make a convenient workflow in cursive otherwise.

onetom 2017-02-14T19:34:18.000782Z

@arnout do i see well that by default i can't define explicit dependencies between states, only by using mount.extensions.explicit-deps/start? i was wondering how can i put multiple defstates into one namespace.

onetom 2017-02-14T19:35:43.000783Z

for example if i do

(ns app.datomic
  (:require
    [app.conf :refer [opts]]
...
(defstate uri
  :start (:uri @opts))

(defstate conn
  :start (do (println "Connecting to Datomic...")
             (connect @uri))
...
i get this error:
clojure.lang.ExceptionInfo: state uri not started
    name: "uri"
clojure.lang.ExceptionInfo: error while starting state #'app.datomic/conn
    var: #'app.datomic/conn

onetom 2017-02-14T19:37:39.000784Z

which practically suggests that i should have 1 defstate per namespace, unless they are not dependent on each other.

onetom 2017-02-14T19:43:16.000785Z

on https://github.com/aroemers/mount-lite you said > The order in which the states are started is determined by their load order by the Clojure compiler. which i understand it refers to the order of namespaces, but it would make sense to start the states in definition order? or it's actually not a realistic use-case, hence better not add more code to support it?

onetom 2017-02-14T20:14:23.000788Z

i thought the problem is solved by adding :dependencies [#'uri] to the conn state as i saw it in the mount.lite test suite, but after removing it, the problem is gone 😕

arnout 2017-02-14T21:29:57.000790Z

@onetom, indeed, by default the dependencies between the defstates are inferred by the Clojure compiler. So yes, the defstate are started in definition order. Also, you are free to put as many defstates in one namespaces as you want, whether you use the explicit-deps extension or not.

arnout 2017-02-14T21:31:43.000791Z

How are you starting your system, that yields you the error you mention?

arnout 2017-02-14T21:33:48.000792Z

Hi @jorisbontje, long time no see 🙂