From 62cb9dd516eb1f194ccf2a3268908c7ba549fc78 Mon Sep 17 00:00:00 2001 From: anatoly Date: Mon, 28 Nov 2016 11:30:38 -0500 Subject: [PATCH] #69: stop accepts collections of states vs. an implicit all and varargs --- src/mount/core.cljc | 18 ++++++++++++------ test/core/mount/test/composable_fns.cljc | 12 +++++++++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/mount/core.cljc b/src/mount/core.cljc index c53701c..0545103 100644 --- a/src/mount/core.cljc +++ b/src/mount/core.cljc @@ -244,7 +244,7 @@ (defn start [& states] (let [fs (-> states first)] (if (coll? fs) - (if-not (empty? fs) ;; (mount/start) vs. (mount/start #{}) vs. (mount/start #{1 2 3}) + (if-not (empty? fs) ;; (mount/start) vs. (mount/start #{}) vs. (mount/start #{1 2 3}) (apply start fs) {:started #{}}) (let [states (or (seq states) @@ -252,11 +252,17 @@ {:started (bring states up <)})))) (defn stop [& states] - (let [states (or states (find-all-states)) - _ (dorun (map unsub states)) ;; unmark substitutions marked by "start-with" - stopped (bring states down >)] - (dorun (map rollback! states)) ;; restore to origin from "start-with" - {:stopped stopped})) + (let [fs (-> states first)] + (if (coll? fs) + (if-not (empty? fs) ;; (mount/start) vs. (mount/start #{}) vs. (mount/start #{1 2 3}) + (apply stop fs) + {:stopped #{}}) + (let [states (or (seq states) + (find-all-states)) + _ (dorun (map unsub states)) ;; unmark substitutions marked by "start-with" + stopped (bring states down >)] + (dorun (map rollback! states)) ;; restore to origin from "start-with" + {:stopped stopped})))) ;; composable set of states diff --git a/test/core/mount/test/composable_fns.cljc b/test/core/mount/test/composable_fns.cljc index a886413..b8b6ee2 100644 --- a/test/core/mount/test/composable_fns.cljc +++ b/test/core/mount/test/composable_fns.cljc @@ -167,4 +167,14 @@ (let [scope #{}] (is (= {:started #{}} (-> (only scope) mount/start))) - (mount/stop))))) + (mount/stop))) + + (testing "should not stop anything on empty seq of states" + (let [scope #{}] + (mount/start) + (is (instance? datomic.peer.LocalConnection (dval conn))) + (is (= {:stopped #{}} (-> (only scope) + mount/stop))) + (is (instance? datomic.peer.LocalConnection (dval conn))) + (mount/stop) + (is (instance? mount.core.NotStartedState (dval conn)))))))