component

2018-07-27T10:30:14.000194Z

Bit of an odd question

2018-07-27T10:30:21.000052Z

When you create a component using a defrecord

2018-07-27T10:30:34.000038Z

and you implement the lifecycle protocol

2018-07-27T10:30:46.000026Z

Does the key you assoc as the last line become a base field?

2018-07-27T10:31:54.000216Z

(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

2018-07-27T10:32:28.000037Z

So with an example component

2018-07-27T10:32:32.000315Z

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

2018-07-27T10:33:03.000149Z

If inside the stop you did (dissoc this :admin) would that convert the record to a map?

2018-07-27T10:33:09.000022Z

like (record? (dissoc ertu :name))

2018-07-27T11:03:50.000129Z

no, you can't add new base fields to a record

2018-07-27T11:04:03.000121Z

so you should be able to safely dissoc

2018-07-27T11:04:11.000024Z

easy to check that in a repl btw

2018-07-27T12:11:22.000105Z

ok thanks! :thumbsup: