Fork me on GitHub
#mount
<
2016-12-05
>
mnewt17:12:34

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.

mnewt17:12:45

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?

yogthos20:12:39

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

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

yogthos20:12:45

then you can do

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

mnewt20:12:23

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