From c001c19eb589b3d259dea41474500359b5a892cf Mon Sep 17 00:00:00 2001 From: Anatoly Date: Sun, 28 Feb 2016 19:02:48 -0500 Subject: [PATCH 1/3] [docs]: circleci link onto 0.1.11-SNAPSHOT --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 81b1325..47f3ac1 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) From ef4dee6c8a3dd4bcfab72bec61835c8c867b2d24 Mon Sep 17 00:00:00 2001 From: Dan Kee Date: Mon, 29 Feb 2016 09:18:02 -0600 Subject: [PATCH 2/3] Make `:start` value a function call. In the existing example, `(defstate conn :start create-conn)` simply binds `conn` to the function `create-conn`, rather than the result of calling the function. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 47f3ac1..534e636 100644 --- a/README.md +++ b/README.md @@ -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)) ``` From 78b9a23c713778807e301204e7c1db44953d6609 Mon Sep 17 00:00:00 2001 From: anatoly Date: Fri, 4 Mar 2016 16:29:20 -0500 Subject: [PATCH 3/3] no start/stop sample logging for started/stopped states --- dev/clj/app/utils/logging.clj | 29 ++++++++++++++--------------- test/clj/tapp/utils/logging.clj | 31 +++++++++++++++---------------- 2 files changed, 29 insertions(+), 31 deletions(-) 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)