Skip to content

Instantly share code, notes, and snippets.

@kwrooijen
Created February 3, 2020 10:06
Show Gist options
  • Save kwrooijen/3c4c4c2dace071107ea4ae2c584a8572 to your computer and use it in GitHub Desktop.
Save kwrooijen/3c4c4c2dace071107ea4ae2c584a8572 to your computer and use it in GitHub Desktop.
(defrecord RefWith [key opts]
ig/RefLike
(ref-key [_] key)
(ref-resolve [_ config resolvef]
(let [[k _] (first (ig/find-derived config key))
config (update config k #(merge % opts))
v (get (ig/init config [k]) k)]
(resolvef k v))))
(defn ref-with [key opts]
(->RefWith key opts))
(defmethod ig/init-key :test/ref-with [_ opts]
opts)
(defmethod ig/init-key :component/basic [_ opts]
(update opts :counter inc))
(defmethod ig/init-key :another/value [_ opts]
opts)
(def s
(ig/init {:test/ref-with {:age (ref-with :my/component {:counter 9999})}
[:component/basic :my/component]
{:counter 123
:year 1992
:value (ig/ref :another/value)}
:another/value 1}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment