Bit of an odd question
When you create a component using a defrecord
and you implement the lifecycle protocol
Does the key you assoc as the last line become a base field?
(defrecord Person [name age])
;;=> user.Person
(def ertu (->Person "Ertu" 24))
;;=> #'user/ertu
(record? ertu)
;;=> true
(record? (assoc ertu :address "Somewhere"))
;;=> true
;;removing base fields converts record to regular map
(record? (dissoc ertu :name))
;;=> false
So with an example component
(defrecord ExampleComponent [options cache database scheduler]
component/Lifecycle
(start [this]
(println ";; Starting ExampleComponent")
;; In the 'start' method, a component may assume that its
;; dependencies are available and have already been started.
(assoc this :admin (get-user database "admin")))
(stop [this]
(println ";; Stopping ExampleComponent")
;; Likewise, in the 'stop' method, a component may assume that its
;; dependencies will not be stopped until AFTER it is stopped.
this))
If inside the stop
you did (dissoc this :admin)
would that convert the record to a map?
like (record? (dissoc ertu :name))
no, you can't add new base fields to a record
so you should be able to safely dissoc
easy to check that in a repl btw
ok thanks! :thumbsup: