unpounding lifecycle fns
This commit is contained in:
parent
ead12a7e88
commit
0e4e507343
6 changed files with 12 additions and 12 deletions
|
|
@ -90,7 +90,7 @@ In case this state needs to be cleaned / destryed between reloads, there is also
|
|||
|
||||
```clojure
|
||||
(defstate conn :start create-conn
|
||||
:stop #(disconnect conn))
|
||||
:stop (disconnect conn))
|
||||
```
|
||||
|
||||
That is pretty much it. But wait, there is more.. this state is _a top level being_, which means it can be simply
|
||||
|
|
@ -146,7 +146,7 @@ There are of course direct dependecies that `mount` respects:
|
|||
(:require [mount.core :refer [defstate]]))
|
||||
|
||||
(defstate app-config
|
||||
:start #(load-config "test/resources/config.edn"))
|
||||
:start (load-config "test/resources/config.edn"))
|
||||
```
|
||||
|
||||
this `app-config`, being top level, can be used in other namespaces, including the ones that create states:
|
||||
|
|
@ -156,7 +156,7 @@ this `app-config`, being top level, can be used in other namespaces, including t
|
|||
(:require [mount.core :refer [defstate]]
|
||||
[app.config :refer [app-config]]))
|
||||
|
||||
(defstate conn :start #(create-connection app-config))
|
||||
(defstate conn :start (create-connection app-config))
|
||||
```
|
||||
|
||||
[here](https://github.com/tolitius/mount/blob/master/test/app/nyse.clj)
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ For the example sake the app reads arguments in two places:
|
|||
* [inside](https://github.com/tolitius/mount/blob/with-args/test/app/nyse.clj#L17) a `defstate`
|
||||
|
||||
```clojure
|
||||
(defstate conn :start #(new-connection (mount/args))
|
||||
:stop #(disconnect (mount/args) conn))
|
||||
(defstate conn :start (new-connection (mount/args))
|
||||
:stop (disconnect (mount/args) conn))
|
||||
```
|
||||
|
||||
* and from "any" [other place](https://github.com/tolitius/mount/blob/with-args/test/app/config.clj#L8) within a function:
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ and the reloadable state:
|
|||
(run-jetty {:join? false
|
||||
:port (:port www)})))
|
||||
|
||||
(defstate nyse-app :start #(start-nyse app-config)
|
||||
:stop #(.stop nyse-app)) ;; it's a "org.eclipse.jetty.server.Server" at this point
|
||||
(defstate nyse-app :start (start-nyse app-config)
|
||||
:stop (.stop nyse-app)) ;; it's a "org.eclipse.jetty.server.Server" at this point
|
||||
```
|
||||
|
||||
In order not to block, and being reloadable, the Jetty server is started in the "`:join? false`" mode which starts the server,
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@
|
|||
(start-server :bind host :port port))
|
||||
|
||||
;; nREPL is just another simple state
|
||||
(defstate nrepl :start #(start-nrepl (:nrepl app-config))
|
||||
:stop #(stop-server nrepl))
|
||||
(defstate nrepl :start (start-nrepl (:nrepl app-config))
|
||||
:stop (stop-server nrepl))
|
||||
|
||||
;; datomic schema
|
||||
(defn create-schema [conn]
|
||||
|
|
|
|||
|
|
@ -10,4 +10,4 @@
|
|||
edn/read-string))
|
||||
|
||||
(defstate app-config
|
||||
:start #(load-config "test/resources/config.edn"))
|
||||
:start (load-config "test/resources/config.edn"))
|
||||
|
|
|
|||
|
|
@ -17,5 +17,5 @@
|
|||
(.release conn) ;; usually it's not released, here just to illustrate the access to connection on (stop)
|
||||
(d/delete-database uri)))
|
||||
|
||||
(defstate conn :start #(new-connection app-config)
|
||||
:stop #(disconnect app-config conn))
|
||||
(defstate conn :start (new-connection app-config)
|
||||
:stop (disconnect app-config conn))
|
||||
|
|
|
|||
Loading…
Reference in a new issue