diff --git a/project.clj b/project.clj index db98c86..1d3d992 100644 --- a/project.clj +++ b/project.clj @@ -4,4 +4,4 @@ :license {:name "The MIT License" :url "http://opensource.org/licenses/MIT"} :dependencies [[com.stuartsierra/dependency "1.0.0"] - [org.clojure/clojure "1.7.0" :scope "provided"]]) + [org.clojure/clojure "1.11.0" :scope "provided"]]) diff --git a/src/com/stuartsierra/component.cljc b/src/com/stuartsierra/component.cljc index cbc21e0..69510dd 100644 --- a/src/com/stuartsierra/component.cljc +++ b/src/com/stuartsierra/component.cljc @@ -196,7 +196,7 @@ (-write writer "#")))) (defn system-map - "Returns a system constructed of key/value pairs. The system has + "Returns a system constructed of key/value pairs or a map. The system has default implementations of the Lifecycle 'start' and 'stop' methods which recursively start/stop all components in the system. @@ -205,12 +205,8 @@ 'read'. To disable this behavior and print system maps like normal records, call (remove-method clojure.core/print-method com.stuartsierra.component.SystemMap)" - [& keyvals] - ;; array-map doesn't check argument length (CLJ-1319) - (when-not (even? (count keyvals)) - (throw (platform/argument-error - "system-map requires an even number of arguments"))) - (map->SystemMap (apply array-map keyvals))) + [& {:as sys-map}] + (map->SystemMap sys-map)) (defn subsystem "Returns a system containing only components associated with the keys diff --git a/test/com/stuartsierra/component_test.clj b/test/com/stuartsierra/component_test.clj index eca77b2..f2c828a 100644 --- a/test/com/stuartsierra/component_test.clj +++ b/test/com/stuartsierra/component_test.clj @@ -228,6 +228,14 @@ (let [system (component/start (system-2))] (is (started? (get-in system [:beta :one :d :my-c]))))) + +(deftest map->system + (let [system (component/start (component/system-map {:a (component-a) + :b (component-b)}))] + (is (started? (get-in system [:a]))) + (is (started? (get-in system [:b]))))) + + (defn increment-all-components [system] (component/update-system system (keys system) update-in [:n] inc))