Merge branch 'master' into 0.1.11-SNAPSHOT
This commit is contained in:
commit
dc089c1aec
3 changed files with 32 additions and 34 deletions
|
|
@ -7,7 +7,7 @@ _**Alan J. Perlis** from [Structure and Interpretation of Computer Programs](htt
|
|||
module | branch | status
|
||||
----------|----------|----------
|
||||
mount | `master` | [](https://circleci.com/gh/tolitius/mount/tree/master)
|
||||
mount | `0.1.10-SNAPSHOT` | [](https://circleci.com/gh/tolitius/mount/tree/0.1.10-SNAPSHOT)
|
||||
mount | `0.1.11-SNAPSHOT` | [](https://circleci.com/gh/tolitius/mount/tree/0.1.11-SNAPSHOT)
|
||||
|
||||
[](http://clojars.org/mount)
|
||||
|
||||
|
|
@ -91,7 +91,7 @@ Pull request away, let's solve this thing!
|
|||
Creating state is easy:
|
||||
|
||||
```clojure
|
||||
(defstate conn :start create-conn)
|
||||
(defstate conn :start (create-conn))
|
||||
```
|
||||
|
||||
where the `create-conn` function is defined elsewhere, can be right above it.
|
||||
|
|
@ -99,7 +99,7 @@ where the `create-conn` function is defined elsewhere, can be right above it.
|
|||
In case this state needs to be cleaned / destroyed between reloads, there is also `:stop`
|
||||
|
||||
```clojure
|
||||
(defstate conn :start create-conn
|
||||
(defstate conn :start (create-conn)
|
||||
:stop (disconnect conn))
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -6,30 +6,26 @@
|
|||
|
||||
(alter-meta! *ns* assoc ::load false)
|
||||
|
||||
(defn- f-to-action [f]
|
||||
(defn- f-to-action [f {:keys [status]}]
|
||||
(let [fname (-> (str f)
|
||||
(split #"@")
|
||||
first)]
|
||||
(case fname
|
||||
"mount.core$up" :up
|
||||
"mount.core$down" :down
|
||||
"mount.core$sigstop" :suspend
|
||||
"mount.core$sigcont" :resume
|
||||
"mount.core$up" (when-not (:started status) :up)
|
||||
"mount.core$down" (when-not (:stopped status) :down)
|
||||
:noop)))
|
||||
|
||||
(defn whatcha-doing? [{:keys [status suspend]} action]
|
||||
(defn whatcha-doing? [action]
|
||||
(case action
|
||||
:up (if (status :suspended) ">> resuming"
|
||||
(if-not (status :started) ">> starting"))
|
||||
:down (if (or (status :started) (status :suspended)) "<< stopping")
|
||||
:suspend (if (and (status :started) suspend) "<< suspending")
|
||||
:resume (if (status :suspended) ">> resuming")))
|
||||
:up ">> starting"
|
||||
:down "<< stopping"
|
||||
false))
|
||||
|
||||
(defn log-status [f & args]
|
||||
(let [{:keys [var] :as state} (second args)
|
||||
action (f-to-action f)]
|
||||
(when-let [taking-over-the-world (whatcha-doing? state action)]
|
||||
(info (str taking-over-the-world ".. " var)))
|
||||
(let [[state-name state] args
|
||||
action (f-to-action f state)]
|
||||
(when-let [taking-over-the-world (whatcha-doing? action)]
|
||||
(info (str taking-over-the-world ".. " state-name)))
|
||||
(apply f args)))
|
||||
|
||||
(defonce lifecycle-fns
|
||||
|
|
@ -39,6 +35,9 @@
|
|||
(defn without-logging-status []
|
||||
(doall (map #(clear-hooks %) lifecycle-fns)))
|
||||
|
||||
|
||||
;; this is the one to use:
|
||||
|
||||
(defn with-logging-status []
|
||||
(without-logging-status)
|
||||
(doall (map #(add-hook % log-status) lifecycle-fns)))
|
||||
|
|
|
|||
|
|
@ -6,30 +6,26 @@
|
|||
|
||||
(alter-meta! *ns* assoc ::load false)
|
||||
|
||||
(defn- f-to-action [f]
|
||||
(defn- f-to-action [f {:keys [status]}]
|
||||
(let [fname (-> (str f)
|
||||
(split #"@")
|
||||
first)]
|
||||
(case fname
|
||||
"mount.core$up" :up
|
||||
"mount.core$down" :down
|
||||
"mount.core$sigstop" :suspend
|
||||
"mount.core$sigcont" :resume
|
||||
"mount.core$up" (when-not (:started status) :up)
|
||||
"mount.core$down" (when-not (:stopped status) :down)
|
||||
:noop)))
|
||||
|
||||
(defn whatcha-doing? [{:keys [status suspend]} action]
|
||||
(defn whatcha-doing? [action]
|
||||
(case action
|
||||
:up (if (status :suspended) ">> resuming"
|
||||
(if-not (status :started) ">> starting"))
|
||||
:down (if (or (status :started) (status :suspended)) "<< stopping")
|
||||
:suspend (if (and (status :started) suspend) "<< suspending")
|
||||
:resume (if (status :suspended) ">> resuming")))
|
||||
:up ">> starting"
|
||||
:down "<< stopping"
|
||||
false))
|
||||
|
||||
(defn log-status [f & args]
|
||||
(let [{:keys [var] :as state} (second args)
|
||||
action (f-to-action f)]
|
||||
(when-let [taking-over-the-world (whatcha-doing? state action)]
|
||||
(info (str taking-over-the-world ".. " var)))
|
||||
(let [[state-name state] args
|
||||
action (f-to-action f state)]
|
||||
(when-let [taking-over-the-world (whatcha-doing? action)]
|
||||
(info (str taking-over-the-world ".. " state-name)))
|
||||
(apply f args)))
|
||||
|
||||
(defonce lifecycle-fns
|
||||
|
|
@ -37,7 +33,10 @@
|
|||
#'mount.core/down})
|
||||
|
||||
(defn without-logging-status []
|
||||
(doall (map clear-hooks lifecycle-fns)))
|
||||
(doall (map #(clear-hooks %) lifecycle-fns)))
|
||||
|
||||
|
||||
;; this is the one to use:
|
||||
|
||||
(defn with-logging-status []
|
||||
(without-logging-status)
|
||||
|
|
|
|||
Loading…
Reference in a new issue