mount

mnewt 2016-12-05T17:48:34.000031Z

Love the addition of (find-all-states) and (running-states). I'm going to start using the latter inside use-fixtures so that I can return the app state back to what it was before tests were run.

mnewt 2016-12-05T17:51:45.000032Z

Is it possible to have binding style semantics in mount? If I have this:

(defstate db
  :start (start-db config)
  :stop  (stop-db db))

(defn insert-into-db
  [table row]
  (jdbc/insert! db table row))
Then I want to wrap my database calls in a transaction:
(jdbc/with-db-transaction [conn db]
  (binding [db conn]
    (insert-into-db :things {:id 1 :name "first thing"})
    (insert-into-db :things {:id 2 :name "second thing"})))
How do I do this sort of thing with mount? Or is there a better approach to this sort of problem?

yogthos 2016-12-05T20:29:39.000035Z

@mnewt you could use a dynamic var, e.g:

(defstate ^:dynamic *conn*
          :start (connect!)
          :stop (disconnect! *conn*))

yogthos 2016-12-05T20:30:45.000036Z

then you can do

(binding [*conn* t-conn]
 …)

yogthos 2016-12-05T20:31:15.000037Z

this is how I end up doing it in the conman lib for luminus https://github.com/luminus-framework/conman/blob/master/src/conman/core.clj#L88

mnewt 2016-12-05T20:32:23.000039Z

Ah, that’s simple! Didn’t realize defstate would work just like def. Thanks @yogthos!

yogthos 2016-12-05T20:32:41.000040Z

np