diff --git a/README.md b/README.md index 81b1325..534e636 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ _**Alan J. Perlis** from [Structure and Interpretation of Computer Programs](htt module | branch | status ----------|----------|---------- mount | `master` | [![Circle CI](https://circleci.com/gh/tolitius/mount/tree/master.png?style=svg)](https://circleci.com/gh/tolitius/mount/tree/master) - mount | `0.1.10-SNAPSHOT` | [![Circle CI](https://circleci.com/gh/tolitius/mount/tree/0.1.10-SNAPSHOT.png?style=svg)](https://circleci.com/gh/tolitius/mount/tree/0.1.10-SNAPSHOT) + mount | `0.1.11-SNAPSHOT` | [![Circle CI](https://circleci.com/gh/tolitius/mount/tree/0.1.11-SNAPSHOT.png?style=svg)](https://circleci.com/gh/tolitius/mount/tree/0.1.11-SNAPSHOT) [![Clojars Project](http://clojars.org/mount/latest-version.svg)](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)) ``` diff --git a/dev/clj/app/utils/logging.clj b/dev/clj/app/utils/logging.clj index df58144..e2a7bab 100644 --- a/dev/clj/app/utils/logging.clj +++ b/dev/clj/app/utils/logging.clj @@ -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))) diff --git a/test/clj/tapp/utils/logging.clj b/test/clj/tapp/utils/logging.clj index 516101a..6764aed 100644 --- a/test/clj/tapp/utils/logging.clj +++ b/test/clj/tapp/utils/logging.clj @@ -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)