From 0bb137d53fe99943e5a8cf80fbcf04fe9ee8578f Mon Sep 17 00:00:00 2001 From: Anatoly Date: Sun, 3 Jan 2016 16:49:47 -0500 Subject: [PATCH 1/2] #35 [docs]: lifecycle funs take vars (not ns) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ba4ae1c..595f486 100644 --- a/README.md +++ b/README.md @@ -258,7 +258,7 @@ You can see examples of start and stop flows in the [example app](README.md#moun In REPL or during testing it is often very useful to work with / start / stop _only a part_ of an application, i.e. "only these two states". -`mount` start/stop functions _optionally_ take namespaces to start/stop: +`mount`'s lifecycle functions, i.e. start/stop/suspend/resume, can _optionally_ take states as vars (i.e. prefixed with their namespaces): ```clojure (mount/start #'app.config/app-config #'app.nyse/conn) @@ -266,7 +266,7 @@ In REPL or during testing it is often very useful to work with / start / stop _o (mount/stop #'app.config/app-config #'app.nyse/conn) ``` -which will only start/stop `app-config` and `conn` (won't start any other states). +which will _only_ start/stop `app-config` and `conn` (won't start/stop any other states). Here is an [example](test/core/mount/test/parts.cljc) test that uses only two namespaces checking that the third one is not started. From d2b14d0cb51e4f5098c65329ecd09d4c52fa84fb Mon Sep 17 00:00:00 2001 From: anatoly Date: Mon, 4 Jan 2016 12:22:52 -0500 Subject: [PATCH 2/2] boot-check to 0.1.1 + fixing what it caught --- build.boot | 3 ++- src/mount/core.cljc | 20 ++++++++++---------- src/mount/tools/graph.cljc | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/build.boot b/build.boot index ecd0a4c..8f8aabc 100644 --- a/build.boot +++ b/build.boot @@ -25,7 +25,7 @@ [adzerk/bootlaces "0.1.13" :scope "test"] [adzerk/boot-logservice "1.0.1" :scope "test"] [adzerk/boot-test "1.0.6" :scope "test"] - [tolitius/boot-check "0.1.0-SNAPSHOT" :scope "test"] + [tolitius/boot-check "0.1.1" :scope "test"] ;; boot cljs [adzerk/boot-cljs "1.7.170-3" :scope "test"] @@ -96,6 +96,7 @@ (set-env! :source-paths #(conj % "dev/clj" "dev/cljs" "test/core" "test/clj" "test/cljs")) ;; (load-data-readers!) (comp + (check/with-bikeshed) (check/with-eastwood) ;; (check/with-yagni) ;; yagni does not yet support (throws on) "cljc" (check/with-kibit))) diff --git a/src/mount/core.cljc b/src/mount/core.cljc index d872eb3..4882ab3 100644 --- a/src/mount/core.cljc +++ b/src/mount/core.cljc @@ -19,16 +19,16 @@ (or (:order (@meta-state state)) (swap! state-seq inc))) -(deftype NotStartedState [state] - Object - (toString [this] +(deftype NotStartedState [state] + Object + (toString [this] (str "'" state "' is not started (to start all the states call mount/start)"))) ;;TODO validate the whole lifecycle (defn- validate [{:keys [start stop suspend resume] :as lifecycle}] - (cond + (cond (not start) (throw-runtime "can't start a stateful thing without a start function. (i.e. missing :start fn)") - (and suspend + (and suspend (not resume)) (throw-runtime "suspendable state should have a resume function (i.e. missing :resume fn)"))) (defn- with-ns [ns name] @@ -98,7 +98,7 @@ (defn- down [state {:keys [stop status] :as current} done] (when (some status #{:started :suspended}) - (when stop + (when stop (on-error (str "could not stop [" state "] due to") (record! state stop done))) (alter-state! current (NotStartedState. state)) ;; (!) if a state does not have :stop when _should_ this might leak @@ -113,7 +113,7 @@ (alter-state! current s))) (update-meta! [state :status] #{:suspended}))) -(defn- sigcont [state {:keys [resume status] :as current} done] +(defn- sigcont [state {:keys [resume status] :as current} done] (when (:suspended status) (let [s (on-error (str "could not resume [" state "] due to") (record! state resume done))] @@ -198,7 +198,7 @@ (defn- bring [states fun order] (let [done (atom [])] - (as-> states $ + (as-> states $ (map var-to-str $) (select-keys @meta-state $) (sort-by (comp :order val) order $) @@ -206,13 +206,13 @@ @done)) (defn- merge-lifecycles - "merges with overriding _certain_ non existing keys. + "merges with overriding _certain_ non existing keys. i.e. :suspend is in a 'state', but not in a 'substitute': it should be overriden with nil however other keys of 'state' (such as :ns,:name,:order) should not be overriden" ([state sub] (merge-lifecycles state nil sub)) ([state origin {:keys [start stop suspend resume status]}] - (assoc state :origin origin + (assoc state :origin origin :status status :start start :stop stop :suspend suspend :resume resume))) diff --git a/src/mount/tools/graph.cljc b/src/mount/tools/graph.cljc index 9113c4e..d84031a 100644 --- a/src/mount/tools/graph.cljc +++ b/src/mount/tools/graph.cljc @@ -8,7 +8,7 @@ deps (->> (filter (comp any val) refers) (map (comp str second)) set)] - (assoc (dissoc state :ns) + (assoc (dissoc state :ns) :deps deps)))) #?(:clj