Do not dissoc a base field from a record – instead assoc a nil value into it.
If you dissoc a base field, the record changes into a hash map. Change: (dissoc this :data) to: (assoc this :data nil) Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN An Architect's View -- http://corfield.org/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood On 1/18/17, 6:28 AM, "Jochen" <clojure@googlegroups.com on behalf of joc...@riekhof.de> wrote: Hi… playing around with Stuart Sierras component library I found some behavior (code at end) that I find odd. M sample has just two components, data and compute, where data is injected into compute. On start data associates a data map and on stop dissociates it. compute uses a value from data's map to compute. What I found is that after system stop the started version of data is still associated to compute, while the data component in SystemMap is stopped. So, when do (def my-system (make-my-system {:factor 2})) (alter-var-root #'my-system component/start-system) (alter-var-root #'my-system component/stop-system) (my-compute (:mycomputecomp my-system) 16) my-compute should (as data map is nil'ed on stop) crash but doesn't. Calling (alter-var-root #'my-system component/stop-system) again fixes it and my-compute crashes as expected. Any ideas? Ciao …Jochen (ns foo.core (:require [com.stuartsierra.component :as component])) (defrecord MyDataComponent [data] component/Lifecycle (start [this] (println "Starting MyDataComponent") (assoc this :data {:foo 42})) (stop [this] (println "Stopping MyDataComponent") (dissoc this :data))) (defn my-data-component [] (->MyDataComponent nil)) (defn mydatacomp-foo [mydatacomp] (get-in mydatacomp [:data :foo])) (defrecord MyComputeComponent [factor mydatacomp] component/Lifecycle (start [this] (println "Starting MyComputeComponent") this) (stop [this] (println "Stopping MyComputeComponent") this)) (defn my-compute-component [factor] (map->MyComputeComponent {:factor factor})) (defn my-compute [mycomputecomp offset] (let [factor (:factor mycomputecomp) foo (mydatacomp-foo (:mydatacomp mycomputecomp))] (+ (* factor foo) offset))) (defn make-my-system [config-options] (let [{:keys [factor]} config-options] (component/system-map :mydatacomp (my-data-component) :mycomputecomp (component/using (my-compute-component factor) [:mydatacomp])))) ;;;;;; running ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (comment (def my-system (make-my-system {:factor 2})) (alter-var-root #'my-system component/start-system) (alter-var-root #'my-system component/stop-system) (my-compute (:mycomputecomp my-system) 16) ) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.