diff --git a/src/mount/core.cljc b/src/mount/core.cljc index 95549dd..ab2598e 100644 --- a/src/mount/core.cljc +++ b/src/mount/core.cljc @@ -4,6 +4,7 @@ [clojure.set :refer [intersection]] [clojure.string :as s]) :cljs (:require [mount.tools.macro :as macro] + [clojure.set :refer [intersection]] [mount.tools.logger :refer [log]])) #?(:cljs (:require-macros [mount.core] [mount.tools.macro :refer [if-clj on-error throw-runtime]]))) @@ -239,8 +240,10 @@ (remove (comp :sub? @meta-state) (find-all-states))) (defn start [& states] - (let [states (or (seq states) (all-without-subs))] - {:started (bring states up <)})) + (if (-> states first coll?) + (apply start (first states)) + (let [states (or (seq states) (all-without-subs))] + {:started (bring states up <)}))) (defn stop [& states] (let [states (or states (find-all-states)) diff --git a/test/core/mount/test/composable_fns.cljc b/test/core/mount/test/composable_fns.cljc index 326bcab..ab7ff5b 100644 --- a/test/core/mount/test/composable_fns.cljc +++ b/test/core/mount/test/composable_fns.cljc @@ -114,3 +114,44 @@ (is (= 42 (dval test-conn))) ;; test-conn is explicitly started via "t-states" (mount/stop))))) +#?(:clj + (deftest composing + + (testing "states provided to the top level should narrow down the scope for the whole composition" + (let [scope [#'tapp.conf/config + #'tapp.example/nrepl + #'tapp.nyse/conn + #'mount.test.composable-fns/test-nrepl + #'mount.test.composable-fns/test-conn] + states (-> (only scope) + (with-args {:a 42}) + (except [#'mount.test.composable-fns/test-nrepl + #'mount.test.composable-fns/test-conn]) + (swap-states {#'tapp.example/nrepl #'mount.test.composable-fns/test-nrepl}) + (swap {#'tapp.conf/config {:datomic {:uri "datomic:mem://composable-mount"}}}))] + (is (= #{"#'tapp.nyse/conn" "#'tapp.conf/config" "#'tapp.example/nrepl"} (set states))) + (mount/start states) + (is (= {:a 42} (mount/args))) + (is (= {:datomic {:uri "datomic:mem://composable-mount"}} (dval config))) + (is (instance? datomic.peer.LocalConnection (dval conn))) + (is (vector? (dval nrepl))) + (mount/stop))) + + (testing "should compose and start in a single composition" + (let [scope [#'tapp.conf/config + #'tapp.example/nrepl + #'tapp.nyse/conn + #'mount.test.composable-fns/test-nrepl + #'mount.test.composable-fns/test-conn]] + (-> (only scope) + (with-args {:a 42}) + (except [#'mount.test.composable-fns/test-nrepl + #'mount.test.composable-fns/test-conn]) + (swap-states {#'tapp.example/nrepl #'mount.test.composable-fns/test-nrepl}) + (swap {#'tapp.conf/config {:datomic {:uri "datomic:mem://composable-mount"}}}) + mount/start) + (is (= {:a 42} (mount/args))) + (is (= {:datomic {:uri "datomic:mem://composable-mount"}} (dval config))) + (is (instance? datomic.peer.LocalConnection (dval conn))) + (is (vector? (dval nrepl))) + (mount/stop)))))