Fork me on GitHub
#component
<
2016-09-22
>
kurt-yagram07:09:12

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).

hiredman07:09:04

start and stop need to return the component

hiredman07:09:30

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

hiredman07:09:58

(just like the message in the exception says)

kurt-yagram07:09:06

🙂 makes sense.