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