component

kurt-yagram 2016-09-22T07:25:12.000022Z

Having:

(defrecord Component []
  component/Lifecycle
  (start [component] (println "started"))
  (stop [component] (println "stopped")))

(defn start []
  (component/start
   (component/system-map
    :comp (map->Component {}))))
and running on the repl:
user> (def r (start))
started
#'user/r
user> r
#<SystemMap>
user> (component/stop-system r)
clojure.lang.ExceptionInfo: Component :comp was nil in system; maybe it returned nil from start or stop"*
(map->Component {}) is not nil, so why is :comp nil? I'm busy trying out component to manage state in a part of my application: I've got an application and I want to use component for a part of it. I know component is supposed to be used in all parts of the application, but refactoring it in one go may take too long. I want to do it step by step, and probably not even for all parts (I don't really like 'lib/framework buy-in', and it is supposed to be possible to use component only for a part of the application).

2016-09-22T07:34:04.000023Z

start and stop need to return the component

2016-09-22T07:34:30.000024Z

because println in your start returns nil, that is taken as the started state of your component

2016-09-22T07:34:58.000025Z

(just like the message in the exception says)

kurt-yagram 2016-09-22T07:38:06.000026Z

🙂 makes sense.